cleaning up
parent
c8ffc824f7
commit
69707fecd7
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue