diff --git a/internal/model/cmd_buff.go b/internal/model/cmd_buff.go index ef79ff5b..bac776e1 100644 --- a/internal/model/cmd_buff.go +++ b/internal/model/cmd_buff.go @@ -3,9 +3,9 @@ package model const maxBuff = 10 const ( - // Command represents a command buffer. + // CommandBuffer represents a command buffer. CommandBuffer BufferKind = 1 << iota - // Filter represents a filter buffer. + // FilterBuffer represents a filter buffer. FilterBuffer ) @@ -40,17 +40,25 @@ func NewCmdBuff(key rune, kind BufferKind) *CmdBuff { } } +// CurrentSuggestion returns the current suggestion. func (c *CmdBuff) CurrentSuggestion() (string, bool) { return "", false } + +// NextSuggestion returns the next suggestion. func (c *CmdBuff) NextSuggestion() (string, bool) { return "", false } + +// PrevSuggestion returns the prev suggestion. func (c *CmdBuff) PrevSuggestion() (string, bool) { return "", false } + +// ClearSuggestions clear out all suggestions. func (c *CmdBuff) ClearSuggestions() {} +// AutoSuggests returns true if model implements auto suggestions. func (c *CmdBuff) AutoSuggests() bool { return false } @@ -84,7 +92,7 @@ func (c *CmdBuff) GetText() string { return string(c.buff) } -// Set initializes the buffer with a command. +// SetText initializes the buffer with a command. func (c *CmdBuff) SetText(cmd string) { c.buff = []rune(cmd) c.fireBufferChanged() diff --git a/internal/model/fish_buff.go b/internal/model/fish_buff.go index 13546878..ebe4cf7a 100644 --- a/internal/model/fish_buff.go +++ b/internal/model/fish_buff.go @@ -33,6 +33,7 @@ func NewFishBuff(key rune, kind BufferKind) *FishBuff { } } +// PrevSuggestion returns the prev suggestion. func (c *FishBuff) PrevSuggestion() (string, bool) { if c.suggestionIndex < 0 { return "", false @@ -44,6 +45,7 @@ func (c *FishBuff) PrevSuggestion() (string, bool) { return c.suggestions[c.suggestionIndex], true } +// NextSuggestion returns the next suggestion. func (c *FishBuff) NextSuggestion() (string, bool) { if c.suggestionIndex < 0 { return "", false @@ -55,10 +57,12 @@ func (c *FishBuff) NextSuggestion() (string, bool) { return c.suggestions[c.suggestionIndex], true } +// ClearSuggestions clear out all suggestions. func (c *FishBuff) ClearSuggestions() { c.suggestion, c.suggestionIndex = "", -1 } +// CurrentSuggestion returns the current suggestion. func (c *FishBuff) CurrentSuggestion() (string, bool) { if c.suggestionIndex < 0 { return "", false @@ -66,10 +70,12 @@ func (c *FishBuff) CurrentSuggestion() (string, bool) { return c.suggestions[c.suggestionIndex], true } +// AutoSuggests returns true if model implements auto suggestions. func (c *FishBuff) AutoSuggests() bool { return true } +// Suggestions returns suggestions. func (f *FishBuff) Suggestions() []string { if f.suggestionFn != nil { return f.suggestionFn(string(f.buff)) diff --git a/internal/ui/app.go b/internal/ui/app.go index 62b05499..4435ed96 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -115,6 +115,7 @@ func (a *App) BailOut() { a.Stop() } +// ResetPrompt reset the prompt model and marks buffer as active. func (a *App) ResetPrompt(m PromptModel) { a.Prompt().SetModel(m) a.SetFocus(a.Prompt()) @@ -220,7 +221,7 @@ func (a *App) Logo() *Logo { return a.views["logo"].(*Logo) } -// Cmd returns app cmd. +// Prompt returns command prompt. func (a *App) Prompt() *Prompt { return a.views["prompt"].(*Prompt) } diff --git a/internal/ui/prompt.go b/internal/ui/prompt.go index eaf6c825..894c715d 100644 --- a/internal/ui/prompt.go +++ b/internal/ui/prompt.go @@ -19,10 +19,18 @@ var _ Suggester = (*model.CmdBuff)(nil) var _ PromptModel = (*model.FishBuff)(nil) var _ Suggester = (*model.FishBuff)(nil) +// Suggester provides suggestions. type Suggester interface { + // CurrentSuggestion returns the current suggestion. CurrentSuggestion() (string, bool) + + // NextSuggestion returns the next suggestion. NextSuggestion() (string, bool) + + // PrevSuggestion returns the prev suggestion. PrevSuggestion() (string, bool) + + // ClearSuggestions clear out all suggestions. ClearSuggestions() } @@ -51,9 +59,16 @@ type PromptModel interface { // RemoveListener removes a listener. RemoveListener(model.BuffWatcher) + // IsActive returns true if prompt is active. IsActive() bool + + // SetActive sets whether the prompt is active or not. SetActive(bool) + + // Add adds a new char to the prompt. Add(rune) + + // Delete deletes the last prompt character. Delete() } @@ -104,6 +119,7 @@ func (p *Prompt) SendStrokes(s string) { } } +// SetModel sets the prompt buffer model. func (c *Prompt) SetModel(m PromptModel) { if c.model != nil { c.model.RemoveListener(c) diff --git a/internal/ui/table.go b/internal/ui/table.go index 5fe660a7..118edd3f 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -148,6 +148,7 @@ func (t *Table) FilterInput(r rune) bool { return true } +// Filter filters out table data. func (t *Table) Filter(s string) { t.ClearSelection() t.doUpdate(t.filtered(t.GetModel().Peek()))