cleaning up

mine
derailed 2020-04-04 22:07:30 -06:00
parent c8ffc824f7
commit 69707fecd7
5 changed files with 36 additions and 4 deletions

View File

@ -3,9 +3,9 @@ package model
const maxBuff = 10 const maxBuff = 10
const ( const (
// Command represents a command buffer. // CommandBuffer represents a command buffer.
CommandBuffer BufferKind = 1 << iota CommandBuffer BufferKind = 1 << iota
// Filter represents a filter buffer. // FilterBuffer represents a filter buffer.
FilterBuffer FilterBuffer
) )
@ -40,17 +40,25 @@ func NewCmdBuff(key rune, kind BufferKind) *CmdBuff {
} }
} }
// CurrentSuggestion returns the current suggestion.
func (c *CmdBuff) CurrentSuggestion() (string, bool) { func (c *CmdBuff) CurrentSuggestion() (string, bool) {
return "", false return "", false
} }
// NextSuggestion returns the next suggestion.
func (c *CmdBuff) NextSuggestion() (string, bool) { func (c *CmdBuff) NextSuggestion() (string, bool) {
return "", false return "", false
} }
// PrevSuggestion returns the prev suggestion.
func (c *CmdBuff) PrevSuggestion() (string, bool) { func (c *CmdBuff) PrevSuggestion() (string, bool) {
return "", false return "", false
} }
// ClearSuggestions clear out all suggestions.
func (c *CmdBuff) ClearSuggestions() {} func (c *CmdBuff) ClearSuggestions() {}
// AutoSuggests returns true if model implements auto suggestions.
func (c *CmdBuff) AutoSuggests() bool { func (c *CmdBuff) AutoSuggests() bool {
return false return false
} }
@ -84,7 +92,7 @@ func (c *CmdBuff) GetText() string {
return string(c.buff) return string(c.buff)
} }
// Set initializes the buffer with a command. // SetText initializes the buffer with a command.
func (c *CmdBuff) SetText(cmd string) { func (c *CmdBuff) SetText(cmd string) {
c.buff = []rune(cmd) c.buff = []rune(cmd)
c.fireBufferChanged() c.fireBufferChanged()

View File

@ -33,6 +33,7 @@ func NewFishBuff(key rune, kind BufferKind) *FishBuff {
} }
} }
// PrevSuggestion returns the prev suggestion.
func (c *FishBuff) PrevSuggestion() (string, bool) { func (c *FishBuff) PrevSuggestion() (string, bool) {
if c.suggestionIndex < 0 { if c.suggestionIndex < 0 {
return "", false return "", false
@ -44,6 +45,7 @@ func (c *FishBuff) PrevSuggestion() (string, bool) {
return c.suggestions[c.suggestionIndex], true return c.suggestions[c.suggestionIndex], true
} }
// NextSuggestion returns the next suggestion.
func (c *FishBuff) NextSuggestion() (string, bool) { func (c *FishBuff) NextSuggestion() (string, bool) {
if c.suggestionIndex < 0 { if c.suggestionIndex < 0 {
return "", false return "", false
@ -55,10 +57,12 @@ func (c *FishBuff) NextSuggestion() (string, bool) {
return c.suggestions[c.suggestionIndex], true return c.suggestions[c.suggestionIndex], true
} }
// ClearSuggestions clear out all suggestions.
func (c *FishBuff) ClearSuggestions() { func (c *FishBuff) ClearSuggestions() {
c.suggestion, c.suggestionIndex = "", -1 c.suggestion, c.suggestionIndex = "", -1
} }
// CurrentSuggestion returns the current suggestion.
func (c *FishBuff) CurrentSuggestion() (string, bool) { func (c *FishBuff) CurrentSuggestion() (string, bool) {
if c.suggestionIndex < 0 { if c.suggestionIndex < 0 {
return "", false return "", false
@ -66,10 +70,12 @@ func (c *FishBuff) CurrentSuggestion() (string, bool) {
return c.suggestions[c.suggestionIndex], true return c.suggestions[c.suggestionIndex], true
} }
// AutoSuggests returns true if model implements auto suggestions.
func (c *FishBuff) AutoSuggests() bool { func (c *FishBuff) AutoSuggests() bool {
return true return true
} }
// Suggestions returns suggestions.
func (f *FishBuff) Suggestions() []string { func (f *FishBuff) Suggestions() []string {
if f.suggestionFn != nil { if f.suggestionFn != nil {
return f.suggestionFn(string(f.buff)) return f.suggestionFn(string(f.buff))

View File

@ -115,6 +115,7 @@ func (a *App) BailOut() {
a.Stop() a.Stop()
} }
// ResetPrompt reset the prompt model and marks buffer as active.
func (a *App) ResetPrompt(m PromptModel) { func (a *App) ResetPrompt(m PromptModel) {
a.Prompt().SetModel(m) a.Prompt().SetModel(m)
a.SetFocus(a.Prompt()) a.SetFocus(a.Prompt())
@ -220,7 +221,7 @@ func (a *App) Logo() *Logo {
return a.views["logo"].(*Logo) return a.views["logo"].(*Logo)
} }
// Cmd returns app cmd. // Prompt returns command prompt.
func (a *App) Prompt() *Prompt { func (a *App) Prompt() *Prompt {
return a.views["prompt"].(*Prompt) return a.views["prompt"].(*Prompt)
} }

View File

@ -19,10 +19,18 @@ var _ Suggester = (*model.CmdBuff)(nil)
var _ PromptModel = (*model.FishBuff)(nil) var _ PromptModel = (*model.FishBuff)(nil)
var _ Suggester = (*model.FishBuff)(nil) var _ Suggester = (*model.FishBuff)(nil)
// Suggester provides suggestions.
type Suggester interface { type Suggester interface {
// CurrentSuggestion returns the current suggestion.
CurrentSuggestion() (string, bool) CurrentSuggestion() (string, bool)
// NextSuggestion returns the next suggestion.
NextSuggestion() (string, bool) NextSuggestion() (string, bool)
// PrevSuggestion returns the prev suggestion.
PrevSuggestion() (string, bool) PrevSuggestion() (string, bool)
// ClearSuggestions clear out all suggestions.
ClearSuggestions() ClearSuggestions()
} }
@ -51,9 +59,16 @@ type PromptModel interface {
// RemoveListener removes a listener. // RemoveListener removes a listener.
RemoveListener(model.BuffWatcher) RemoveListener(model.BuffWatcher)
// IsActive returns true if prompt is active.
IsActive() bool IsActive() bool
// SetActive sets whether the prompt is active or not.
SetActive(bool) SetActive(bool)
// Add adds a new char to the prompt.
Add(rune) Add(rune)
// Delete deletes the last prompt character.
Delete() Delete()
} }
@ -104,6 +119,7 @@ func (p *Prompt) SendStrokes(s string) {
} }
} }
// SetModel sets the prompt buffer model.
func (c *Prompt) SetModel(m PromptModel) { func (c *Prompt) SetModel(m PromptModel) {
if c.model != nil { if c.model != nil {
c.model.RemoveListener(c) c.model.RemoveListener(c)

View File

@ -148,6 +148,7 @@ func (t *Table) FilterInput(r rune) bool {
return true return true
} }
// Filter filters out table data.
func (t *Table) Filter(s string) { func (t *Table) Filter(s string) {
t.ClearSelection() t.ClearSelection()
t.doUpdate(t.filtered(t.GetModel().Peek())) t.doUpdate(t.filtered(t.GetModel().Peek()))