Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.wiki
.gemini
6 changes: 3 additions & 3 deletions example/main-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func mainMenuCommands(app *console.Console) console.Commands {
message, _ := cmd.Flags().GetString("message")
count, _ := cmd.Flags().GetInt("count")

for i := 0; i < count; i++ {
for range count {
fmt.Println(message)
}
},
Expand Down Expand Up @@ -403,7 +403,7 @@ func mainMenuCommands(app *console.Console) console.Commands {

rootCmd.AddCommand(searchCmd)

var mySlice = []string{"a", "b", "c"}
mySlice := []string{"a", "b", "c"}

backupCmd := &cobra.Command{
Use: "backup [flags] SOURCE DESTINATION",
Expand Down Expand Up @@ -590,7 +590,7 @@ func mainMenuCommands(app *console.Console) console.Commands {
if cmd.Name() == "ssh" {
// Generate a list of random hosts to use as positional arguments
hosts := make([]string, 0)
for i := 0; i < 10; i++ {
for i := range 10 {
hosts = append(hosts, fmt.Sprintf("host%d", i))
}

Expand Down
19 changes: 10 additions & 9 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (c *Console) StartContext(ctx context.Context) error {
lastLine := "" // used to check if last read line is empty.

for {
// Print a newline after the last output if NewlineAfter is true
// and the last line was not empty.
c.displayPostRun(lastLine)

// Always ensure we work with the active menu, with freshly
Expand All @@ -47,15 +49,10 @@ func (c *Console) StartContext(ctx context.Context) error {
}

// Block and read user input.
input , err := c.shell.Readline()

c.displayPostRun(input)

input, err := c.shell.Readline()
if err != nil {
menu.handleInterrupt(err)

lastLine = input

lastLine = input
continue
}

Expand All @@ -72,7 +69,7 @@ func (c *Console) StartContext(ctx context.Context) error {
}

if len(args) == 0 {
lastLine = input
lastLine = input
continue
}

Expand All @@ -84,6 +81,10 @@ func (c *Console) StartContext(ctx context.Context) error {
continue
}

// Print a newline before executing the command if NewlineBefore is true
// and the last line was not empty.
c.displayPreRun(input)

// Run all pre-run hooks and the command itself
// Don't check the error: if its a cobra error,
// the library user is responsible for setting
Expand All @@ -93,7 +94,7 @@ func (c *Console) StartContext(ctx context.Context) error {
menu.ErrorHandler(ExecutionError{newError(err, "")})
}

lastLine = input
lastLine = input
}
}

Expand Down