Skip to content
Myr

Blink cursor

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent 923390d · Browse files · 2 files+27 added−23 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+27 added−23 removed

  • other:+27 added−23 removed

2 files+27 added−23 removed

modified:examples/input/main.go+21 added-14 removed
23 unmodified lines
24 input: input.DefaultModel(),25 },26 update,27 view,28 nil,29 //[]tea.Sub{input.Blink},28 []tea.Sub{29 // Just hand off the subscription to the input component30 func(m tea.Model) tea.Msg {31 if m, ok := m.(model); ok {32 return input.Blink(m.input)33 }34 // TODO: return error35 return nil36 },37 },38 )3940 if err := p.Start(); err != nil {41 log.Fatal(err)
1 unmodified line
43}4445func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {46 var cmd tea.Cmd3947 m, _ := mdl.(model)4849 switch msg := msg.(type) {50 case tea.KeyMsg:
2 unmodified lines
53 fallthrough54 case "esc":55 return m, tea.Quit56 }5051 case input.CursorBlinkMsg:52 return input.Update(msg, m.input)57 }5859 m.input, cmd = input.Update(msg, m.input)60 return m, cmd61}6259func view(mdl tea.Model) string {60 m, _ := mdl.(model)61 help := "(esc to exit)"63func view(m tea.Model) string {64 if m, ok := m.(model); ok {65 help := "(esc to exit)"6663 return fmt.Sprintf(64 "What’s your favorite Pokémon?\n\n%s\n\n%s",65 input.View(m.input),66 help,67 )67 return fmt.Sprintf(68 "What’s your favorite Pokémon?\n\n%s\n\n%s",69 input.View(m.input),70 help,71 )72 }73 // TODO: return error74 return ""75}
modified:input/input.go+6 added-9 removed
25 unmodified lines
26 BlinkSpeed: time.Second,27 }28}2930func Update(msg tea.Msg, model tea.Model) (Model, tea.Cmd) {31 m, _ := model.(Model)3230func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {31 switch msg := msg.(type) {3233 case tea.KeyMsg:34 switch msg.Type {
14 unmodified lines
4950func View(model tea.Model) string {51 m, _ := model.(Model)52 cursor := m.Cursor55 //if m.Blink {56 //cursor = m.HiddenCursor57 //}53 if m.Blink {54 cursor = m.HiddenCursor55 }56 return m.Prompt + m.Value + cursor57}5859func Blink(model tea.Model) tea.Msg {62 //m, _ := model.(Model)63 //time.Sleep(m.BlinkSpeed)64 time.Sleep(time.Second)60 m, _ := model.(Model)61 time.Sleep(m.BlinkSpeed)62 return CursorBlinkMsg{}63}