Skip to content

Commit

Permalink
Implemented option to disable auto-completion for command line
Browse files Browse the repository at this point in the history
  • Loading branch information
mrusme committed Apr 5, 2021
1 parent b2c5d05 commit 23fa5ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cli/tuiCmd.go
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/mrusme/gomphotherium/tui"
)

var flagAutocompletion bool

var tuiCmd = &cobra.Command{
Use: "tui",
Short: "Launch TUI",
Expand All @@ -14,6 +16,7 @@ var tuiCmd = &cobra.Command{
Client: MastodonClient,
Options: tui.TUIOptions{
ShowImages: flagShowImages,
AutoCompletion: flagAutocompletion,
},
Help: help,
}
Expand All @@ -23,4 +26,11 @@ var tuiCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(tuiCmd)
tuiCmd.Flags().BoolVarP(
&flagAutocompletion,
"auto-completion",
"a",
true,
"Auto-completion on command input",
)
}
10 changes: 7 additions & 3 deletions tui/tui.go
Expand Up @@ -21,6 +21,7 @@ const (

type TUIOptions struct {
ShowImages bool
AutoCompletion bool
}

type TUICore struct {
Expand Down Expand Up @@ -67,9 +68,6 @@ func TUI(tuiCore TUICore) {
tuiCore.CmdLine = tview.NewInputField().
SetLabelColor(tcell.ColorDefault).
SetFieldBackgroundColor(tcell.ColorDefault).
SetAutocompleteFunc(func(input string) ([]string) {
return mast.CmdAutocompleter(input, tuiCore.Timeline.KnownUsers)
}).
SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEnter {
cmd := tuiCore.CmdLine.GetText()
Expand Down Expand Up @@ -100,6 +98,12 @@ func TUI(tuiCore TUICore) {
}
})

if tuiCore.Options.AutoCompletion == true {
tuiCore.CmdLine.SetAutocompleteFunc(func(input string) ([]string) {
return mast.CmdAutocompleter(input, tuiCore.Timeline.KnownUsers)
})
}

tuiCore.Profile = tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
Expand Down

0 comments on commit 23fa5ff

Please sign in to comment.