()
| 84 | } |
| 85 | |
| 86 | func (a *App) RunInteractive() error { |
| 87 | commands := []Command{ |
| 88 | {"status", "show paths with changes", a.statusCmd}, |
| 89 | {"update", "add working tree state to the staged set of changes", a.updateCmd}, |
| 90 | {"revert", "revert staged set of changes back to the HEAD version", a.revertCmd}, |
| 91 | {"add untracked", "add contents of untracked files to the staged set of changes", a.addUntrackedCmd}, |
| 92 | {"patch", "pick hunks and update selectively", a.patchCmd}, |
| 93 | {"diff", "view diff between HEAD and index", a.diffCmd}, |
| 94 | {"quit", "quit", a.quitCmd}, |
| 95 | {"help", "show help", a.helpCmd}, |
| 96 | } |
| 97 | |
| 98 | for { |
| 99 | // Show status first like Perl version |
| 100 | a.showInteractiveStatus() |
| 101 | |
| 102 | // Show commands in compact format like Perl version |
| 103 | fmt.Print(a.colored(a.colors.HeaderColor, "\n*** Commands ***\n")) |
| 104 | |
| 105 | // Display commands in compact horizontal format like Perl version |
| 106 | cmdLine1 := fmt.Sprintf(" 1: %s 2: %s 3: %s 4: %s", |
| 107 | a.colored(a.colors.PromptColor, "s")+"tatus", |
| 108 | a.colored(a.colors.PromptColor, "u")+"pdate", |
| 109 | a.colored(a.colors.PromptColor, "r")+"evert", |
| 110 | a.colored(a.colors.PromptColor, "a")+"dd untracked") |
| 111 | cmdLine2 := fmt.Sprintf(" 5: %s 6: %s 7: %s 8: %s", |
| 112 | a.colored(a.colors.PromptColor, "p")+"atch", |
| 113 | a.colored(a.colors.PromptColor, "d")+"iff", |
| 114 | a.colored(a.colors.PromptColor, "q")+"uit", |
| 115 | a.colored(a.colors.PromptColor, "h")+"elp") |
| 116 | |
| 117 | fmt.Println(cmdLine1) |
| 118 | fmt.Println(cmdLine2) |
| 119 | |
| 120 | // Interactive prompt |
| 121 | fmt.Print(a.colored(a.colors.PromptColor, "What now> ")) |
| 122 | input, err := a.promptSingleChar() |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | |
| 127 | if input == "" { |
| 128 | break |
| 129 | } |
| 130 | |
| 131 | // Handle single letter commands |
| 132 | var selectedCmd *Command |
| 133 | for _, cmd := range commands { |
| 134 | if strings.ToLower(input) == strings.ToLower(cmd.Name[:1]) { |
| 135 | selectedCmd = &cmd |
| 136 | break |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // Handle numeric commands |
| 141 | if selectedCmd == nil { |
| 142 | if num, err := strconv.Atoi(input); err == nil { |
| 143 | if num >= 1 && num <= len(commands) { |
no test coverage detected