src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/cli/examples/nav/main.go (about)

     1  // Command nav runs the navigation mode of the line editor.
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"src.elv.sh/pkg/cli"
     8  	"src.elv.sh/pkg/cli/modes"
     9  	"src.elv.sh/pkg/cli/term"
    10  	"src.elv.sh/pkg/cli/tk"
    11  )
    12  
    13  func main() {
    14  	app := cli.NewApp(cli.AppSpec{})
    15  	w, _ := modes.NewNavigation(app, modes.NavigationSpec{
    16  		Bindings: tk.MapBindings{
    17  			term.K('x'): func(tk.Widget) { app.CommitCode() },
    18  		},
    19  	})
    20  	app.PushAddon(w)
    21  
    22  	code, err := app.ReadCode()
    23  	fmt.Println("code:", code)
    24  	if err != nil {
    25  		fmt.Println("err", err)
    26  	}
    27  }