diff --git a/cursor/cursor.go b/cursor/cursor.go new file mode 100644 index 0000000..aa49c05 --- /dev/null +++ b/cursor/cursor.go @@ -0,0 +1,12 @@ +package cursor + +import ( + "github.com/charmbracelet/bubbles/cursor" +) + +// Modes maps strings to cursor modes. +var Modes = map[string]cursor.Mode{ + "blink": cursor.CursorBlink, + "hide": cursor.CursorHide, + "static": cursor.CursorStatic, +} diff --git a/input/command.go b/input/command.go index c15e180..4d3edb2 100644 --- a/input/command.go +++ b/input/command.go @@ -8,6 +8,7 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/gum/cursor" "github.com/charmbracelet/gum/internal/exit" "github.com/charmbracelet/gum/internal/stdin" "github.com/charmbracelet/gum/style" @@ -29,6 +30,7 @@ func (o Options) Run() error { i.Width = o.Width i.PromptStyle = o.PromptStyle.ToLipgloss() i.Cursor.Style = o.CursorStyle.ToLipgloss() + i.Cursor.SetMode(cursor.Modes[o.CursorMode]) i.CharLimit = o.CharLimit if o.Password { diff --git a/input/options.go b/input/options.go index 86eef6a..77cc683 100644 --- a/input/options.go +++ b/input/options.go @@ -8,6 +8,7 @@ type Options struct { Prompt string `help:"Prompt to display" default:"> " env:"GUM_INPUT_PROMPT"` PromptStyle style.Styles `embed:"" prefix:"prompt." envprefix:"GUM_INPUT_PROMPT_"` CursorStyle style.Styles `embed:"" prefix:"cursor." set:"defaultForeground=212" envprefix:"GUM_INPUT_CURSOR_"` + CursorMode string `prefix:"cursor." name:"mode" help:"Cursor mode" default:"blink" enum:"blink,hide,static" env:"GUM_INPUT_CURSOR_MODE"` Value string `help:"Initial value (can also be passed via stdin)" default:""` CharLimit int `help:"Maximum value length (0 for no limit)" default:"400"` Width int `help:"Input width (0 for terminal width)" default:"40" env:"GUM_INPUT_WIDTH"` diff --git a/write/command.go b/write/command.go index 84fcd76..76e46b2 100644 --- a/write/command.go +++ b/write/command.go @@ -9,6 +9,7 @@ import ( "github.com/charmbracelet/bubbles/textarea" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/gum/cursor" "github.com/charmbracelet/gum/internal/exit" "github.com/charmbracelet/gum/internal/stdin" "github.com/charmbracelet/gum/style" @@ -43,6 +44,7 @@ func (o Options) Run() error { a.BlurredStyle = style a.FocusedStyle = style a.Cursor.Style = o.CursorStyle.ToLipgloss() + a.Cursor.SetMode(cursor.Modes[o.CursorMode]) a.SetWidth(o.Width) a.SetHeight(o.Height) diff --git a/write/options.go b/write/options.go index cfae3c9..af5b422 100644 --- a/write/options.go +++ b/write/options.go @@ -13,6 +13,7 @@ type Options struct { ShowLineNumbers bool `help:"Show line numbers" default:"false" env:"GUM_WRITE_SHOW_LINE_NUMBERS"` Value string `help:"Initial value (can be passed via stdin)" default:"" env:"GUM_WRITE_VALUE"` CharLimit int `help:"Maximum value length (0 for no limit)" default:"400"` + CursorMode string `prefix:"cursor." name:"mode" help:"Cursor mode" default:"blink" enum:"blink,hide,static" env:"GUM_WRITE_CURSOR_MODE"` BaseStyle style.Styles `embed:"" prefix:"base." envprefix:"GUM_WRITE_BASE_"` CursorLineNumberStyle style.Styles `embed:"" prefix:"cursor-line-number." set:"defaultForeground=7" envprefix:"GUM_WRITE_CURSOR_LINE_NUMBER_"`