Skip to content

Commit

Permalink
Adds command exit, and make execution of consiquent command as a prio…
Browse files Browse the repository at this point in the history
…rity
  • Loading branch information
ksysoev committed Nov 6, 2023
1 parent a4493c0 commit 99a6676
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
20 changes: 8 additions & 12 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,20 @@ func (c *CLI) Run(opts RunOptions) error {

for {
select {
case cmd, ok := <-c.commands:
if !ok {
return nil
}
case cmd := <-c.commands:
nextCmd := cmd

nextCmd, err := cmd.Execute(exCtx)
for nextCmd != nil {
nextCmd, err = cmd.Execute(exCtx)

if err != nil {
return err
}

if nextCmd != nil {
c.commands <- nextCmd
if err != nil {
return err
}
}
case event := <-keysEvents:
switch event.Key {
case keyboard.KeyEsc, keyboard.KeyCtrlC, keyboard.KeyCtrlD:
return nil
c.commands <- NewCommandExit()
case keyboard.KeyEnter:
c.commands <- NewCommandEdit("")
default:
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ func (c *CommandPrintMsg) Execute(exCtx *ExecutionContext) (Executer, error) {

return nil, nil
}

type CommandExit struct{}

func NewCommandExit() *CommandExit {
return &CommandExit{}
}

func (c *CommandExit) Execute(_ *ExecutionContext) (Executer, error) {
return nil, fmt.Errorf("interrupted")
}

0 comments on commit 99a6676

Please sign in to comment.