cleaning up
parent
69707fecd7
commit
399b331b42
|
|
@ -34,44 +34,44 @@ func NewFishBuff(key rune, kind BufferKind) *FishBuff {
|
|||
}
|
||||
|
||||
// PrevSuggestion returns the prev suggestion.
|
||||
func (c *FishBuff) PrevSuggestion() (string, bool) {
|
||||
if c.suggestionIndex < 0 {
|
||||
func (f *FishBuff) PrevSuggestion() (string, bool) {
|
||||
if f.suggestionIndex < 0 {
|
||||
return "", false
|
||||
}
|
||||
c.suggestionIndex--
|
||||
if c.suggestionIndex < 0 {
|
||||
c.suggestionIndex = len(c.suggestions) - 1
|
||||
f.suggestionIndex--
|
||||
if f.suggestionIndex < 0 {
|
||||
f.suggestionIndex = len(f.suggestions) - 1
|
||||
}
|
||||
return c.suggestions[c.suggestionIndex], true
|
||||
return f.suggestions[f.suggestionIndex], true
|
||||
}
|
||||
|
||||
// NextSuggestion returns the next suggestion.
|
||||
func (c *FishBuff) NextSuggestion() (string, bool) {
|
||||
if c.suggestionIndex < 0 {
|
||||
func (f *FishBuff) NextSuggestion() (string, bool) {
|
||||
if f.suggestionIndex < 0 {
|
||||
return "", false
|
||||
}
|
||||
c.suggestionIndex++
|
||||
if c.suggestionIndex >= len(c.suggestions) {
|
||||
c.suggestionIndex = 0
|
||||
f.suggestionIndex++
|
||||
if f.suggestionIndex >= len(f.suggestions) {
|
||||
f.suggestionIndex = 0
|
||||
}
|
||||
return c.suggestions[c.suggestionIndex], true
|
||||
return f.suggestions[f.suggestionIndex], true
|
||||
}
|
||||
|
||||
// ClearSuggestions clear out all suggestions.
|
||||
func (c *FishBuff) ClearSuggestions() {
|
||||
c.suggestion, c.suggestionIndex = "", -1
|
||||
func (f *FishBuff) ClearSuggestions() {
|
||||
f.suggestion, f.suggestionIndex = "", -1
|
||||
}
|
||||
|
||||
// CurrentSuggestion returns the current suggestion.
|
||||
func (c *FishBuff) CurrentSuggestion() (string, bool) {
|
||||
if c.suggestionIndex < 0 {
|
||||
func (f *FishBuff) CurrentSuggestion() (string, bool) {
|
||||
if f.suggestionIndex < 0 {
|
||||
return "", false
|
||||
}
|
||||
return c.suggestions[c.suggestionIndex], true
|
||||
return f.suggestions[f.suggestionIndex], true
|
||||
}
|
||||
|
||||
// AutoSuggests returns true if model implements auto suggestions.
|
||||
func (c *FishBuff) AutoSuggests() bool {
|
||||
func (f *FishBuff) AutoSuggests() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,26 +85,26 @@ type Prompt struct {
|
|||
|
||||
// NewPrompt returns a new command view.
|
||||
func NewPrompt(noIcons bool, styles *config.Styles) *Prompt {
|
||||
c := Prompt{
|
||||
p := Prompt{
|
||||
styles: styles,
|
||||
noIcons: noIcons,
|
||||
TextView: tview.NewTextView(),
|
||||
spacer: defaultSpacer,
|
||||
}
|
||||
if noIcons {
|
||||
c.spacer--
|
||||
p.spacer--
|
||||
}
|
||||
c.SetWordWrap(true)
|
||||
c.SetWrap(true)
|
||||
c.SetDynamicColors(true)
|
||||
c.SetBorder(true)
|
||||
c.SetBorderPadding(0, 0, 1, 1)
|
||||
c.SetBackgroundColor(styles.BgColor())
|
||||
c.SetTextColor(styles.FgColor())
|
||||
styles.AddListener(&c)
|
||||
c.SetInputCapture(c.keyboard)
|
||||
p.SetWordWrap(true)
|
||||
p.SetWrap(true)
|
||||
p.SetDynamicColors(true)
|
||||
p.SetBorder(true)
|
||||
p.SetBorderPadding(0, 0, 1, 1)
|
||||
p.SetBackgroundColor(styles.BgColor())
|
||||
p.SetTextColor(styles.FgColor())
|
||||
styles.AddListener(&p)
|
||||
p.SetInputCapture(p.keyboard)
|
||||
|
||||
return &c
|
||||
return &p
|
||||
}
|
||||
|
||||
// SendKey sends an keyboard event (testing only!).
|
||||
|
|
@ -120,46 +120,46 @@ 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)
|
||||
func (p *Prompt) SetModel(m PromptModel) {
|
||||
if p.model != nil {
|
||||
p.model.RemoveListener(p)
|
||||
}
|
||||
c.model = m
|
||||
c.model.AddListener(c)
|
||||
p.model = m
|
||||
p.model.AddListener(p)
|
||||
}
|
||||
|
||||
func (c *Prompt) keyboard(evt *tcell.EventKey) *tcell.EventKey {
|
||||
m, ok := c.model.(Suggester)
|
||||
func (p *Prompt) keyboard(evt *tcell.EventKey) *tcell.EventKey {
|
||||
m, ok := p.model.(Suggester)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch evt.Key() {
|
||||
case tcell.KeyBackspace2, tcell.KeyBackspace, tcell.KeyDelete:
|
||||
c.model.Delete()
|
||||
p.model.Delete()
|
||||
case tcell.KeyRune:
|
||||
c.model.Add(evt.Rune())
|
||||
p.model.Add(evt.Rune())
|
||||
case tcell.KeyEscape:
|
||||
c.model.ClearText()
|
||||
c.model.SetActive(false)
|
||||
p.model.ClearText()
|
||||
p.model.SetActive(false)
|
||||
case tcell.KeyEnter, tcell.KeyCtrlE:
|
||||
if curr, ok := m.CurrentSuggestion(); ok {
|
||||
c.model.SetText(c.model.GetText() + curr)
|
||||
p.model.SetText(p.model.GetText() + curr)
|
||||
}
|
||||
c.model.SetActive(false)
|
||||
p.model.SetActive(false)
|
||||
case tcell.KeyCtrlW, tcell.KeyCtrlU:
|
||||
c.model.ClearText()
|
||||
p.model.ClearText()
|
||||
case tcell.KeyDown:
|
||||
if next, ok := m.NextSuggestion(); ok {
|
||||
c.suggest(c.model.GetText(), next)
|
||||
p.suggest(p.model.GetText(), next)
|
||||
}
|
||||
case tcell.KeyUp:
|
||||
if prev, ok := m.PrevSuggestion(); ok {
|
||||
c.suggest(c.model.GetText(), prev)
|
||||
p.suggest(p.model.GetText(), prev)
|
||||
}
|
||||
case tcell.KeyTab, tcell.KeyRight, tcell.KeyCtrlF:
|
||||
if curr, ok := m.CurrentSuggestion(); ok {
|
||||
c.model.SetText(c.model.GetText() + curr)
|
||||
p.model.SetText(p.model.GetText() + curr)
|
||||
m.ClearSuggestions()
|
||||
}
|
||||
}
|
||||
|
|
@ -167,78 +167,78 @@ func (c *Prompt) keyboard(evt *tcell.EventKey) *tcell.EventKey {
|
|||
}
|
||||
|
||||
// StylesChanged notifies skin changed.
|
||||
func (c *Prompt) StylesChanged(s *config.Styles) {
|
||||
c.styles = s
|
||||
c.SetBackgroundColor(s.BgColor())
|
||||
c.SetTextColor(s.FgColor())
|
||||
func (p *Prompt) StylesChanged(s *config.Styles) {
|
||||
p.styles = s
|
||||
p.SetBackgroundColor(s.BgColor())
|
||||
p.SetTextColor(s.FgColor())
|
||||
}
|
||||
|
||||
// InCmdMode returns true if command is active, false otherwise.
|
||||
func (c *Prompt) InCmdMode() bool {
|
||||
if c.model == nil {
|
||||
func (p *Prompt) InCmdMode() bool {
|
||||
if p.model == nil {
|
||||
return false
|
||||
}
|
||||
return c.model.IsActive()
|
||||
return p.model.IsActive()
|
||||
}
|
||||
|
||||
func (c *Prompt) activate() {
|
||||
c.SetCursorIndex(len(c.model.GetText()))
|
||||
c.write(c.model.GetText(), "")
|
||||
c.model.Notify()
|
||||
func (p *Prompt) activate() {
|
||||
p.SetCursorIndex(len(p.model.GetText()))
|
||||
p.write(p.model.GetText(), "")
|
||||
p.model.Notify()
|
||||
}
|
||||
|
||||
func (c *Prompt) update(s string) {
|
||||
c.Clear()
|
||||
c.write(s, "")
|
||||
func (p *Prompt) update(s string) {
|
||||
p.Clear()
|
||||
p.write(s, "")
|
||||
}
|
||||
|
||||
func (c *Prompt) suggest(text, suggestion string) {
|
||||
c.Clear()
|
||||
c.write(text, suggestion)
|
||||
func (p *Prompt) suggest(text, suggestion string) {
|
||||
p.Clear()
|
||||
p.write(text, suggestion)
|
||||
}
|
||||
|
||||
func (c *Prompt) write(text, suggest string) {
|
||||
c.SetCursorIndex(c.spacer + len(text))
|
||||
func (p *Prompt) write(text, suggest string) {
|
||||
p.SetCursorIndex(p.spacer + len(text))
|
||||
txt := text
|
||||
if suggest != "" {
|
||||
txt += "[gray::-]" + suggest
|
||||
}
|
||||
fmt.Fprintf(c, defaultPrompt, c.icon, txt)
|
||||
fmt.Fprintf(p, defaultPrompt, p.icon, txt)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Event Listener protocol...
|
||||
|
||||
// BufferChanged indicates the buffer was changed.
|
||||
func (c *Prompt) BufferChanged(s string) {
|
||||
c.update(s)
|
||||
func (p *Prompt) BufferChanged(s string) {
|
||||
p.update(s)
|
||||
}
|
||||
|
||||
func (c *Prompt) SuggestionChanged(text, sugg string) {
|
||||
c.Clear()
|
||||
c.write(text, sugg)
|
||||
func (p *Prompt) SuggestionChanged(text, sugg string) {
|
||||
p.Clear()
|
||||
p.write(text, sugg)
|
||||
}
|
||||
|
||||
// BufferActive indicates the buff activity changed.
|
||||
func (c *Prompt) BufferActive(activate bool, kind model.BufferKind) {
|
||||
func (p *Prompt) BufferActive(activate bool, kind model.BufferKind) {
|
||||
if activate {
|
||||
c.ShowCursor(true)
|
||||
c.SetBorder(true)
|
||||
c.SetTextColor(c.styles.FgColor())
|
||||
c.SetBorderColor(colorFor(kind))
|
||||
c.icon = c.iconFor(kind)
|
||||
c.activate()
|
||||
p.ShowCursor(true)
|
||||
p.SetBorder(true)
|
||||
p.SetTextColor(p.styles.FgColor())
|
||||
p.SetBorderColor(colorFor(kind))
|
||||
p.icon = p.iconFor(kind)
|
||||
p.activate()
|
||||
return
|
||||
}
|
||||
|
||||
c.ShowCursor(false)
|
||||
c.SetBorder(false)
|
||||
c.SetBackgroundColor(c.styles.BgColor())
|
||||
c.Clear()
|
||||
p.ShowCursor(false)
|
||||
p.SetBorder(false)
|
||||
p.SetBackgroundColor(p.styles.BgColor())
|
||||
p.Clear()
|
||||
}
|
||||
|
||||
func (c *Prompt) iconFor(k model.BufferKind) rune {
|
||||
if c.noIcons {
|
||||
func (p *Prompt) iconFor(k model.BufferKind) rune {
|
||||
if p.noIcons {
|
||||
return ' '
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -468,14 +468,16 @@ func (t TreeNode) toEmojiTitle() (title string) {
|
|||
}
|
||||
|
||||
func toEmoji(gvr string) string {
|
||||
if ic := toEmojiXRay(gvr); ic != "" {
|
||||
return ic
|
||||
if e := v1Emoji(gvr); e != "" {
|
||||
return e
|
||||
}
|
||||
if e := appsEmoji(gvr); e != "" {
|
||||
return e
|
||||
}
|
||||
if e := issueEmoji(gvr); e != "" {
|
||||
return e
|
||||
}
|
||||
switch gvr {
|
||||
case "apps/v1/replicasets":
|
||||
return "👯♂️"
|
||||
case "v1/nodes":
|
||||
return "🖥 "
|
||||
case "autoscaling/v1/horizontalpodautoscalers":
|
||||
return "♎️"
|
||||
case "rbac.authorization.k8s.io/v1/clusterrolebindings", "rbac.authorization.k8s.io/v1/clusterroles":
|
||||
|
|
@ -488,6 +490,17 @@ func toEmoji(gvr string) string {
|
|||
return "🏷 "
|
||||
case "policy/v1beta1/podsecuritypolicies":
|
||||
return "👮♂️"
|
||||
case "containers":
|
||||
return "🐳"
|
||||
case "report":
|
||||
return "🧼"
|
||||
default:
|
||||
return "📎"
|
||||
}
|
||||
}
|
||||
|
||||
func issueEmoji(gvr string) string {
|
||||
switch gvr {
|
||||
case "issue_0":
|
||||
return "👍"
|
||||
case "issue_1":
|
||||
|
|
@ -496,19 +509,17 @@ func toEmoji(gvr string) string {
|
|||
return "☣️ "
|
||||
case "issue_3":
|
||||
return "🧨"
|
||||
case "report":
|
||||
return "🧼"
|
||||
default:
|
||||
return "📎"
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func toEmojiXRay(gvr string) string {
|
||||
func v1Emoji(gvr string) string {
|
||||
switch gvr {
|
||||
case "containers":
|
||||
return "🐳"
|
||||
case "v1/namespaces":
|
||||
return "🗂 "
|
||||
case "v1/nodes":
|
||||
return "🖥 "
|
||||
case "v1/pods":
|
||||
return "🚛"
|
||||
case "v1/services":
|
||||
|
|
@ -523,12 +534,21 @@ func toEmojiXRay(gvr string) string {
|
|||
return "🔒"
|
||||
case "v1/configmaps":
|
||||
return "🗺 "
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func appsEmoji(gvr string) string {
|
||||
switch gvr {
|
||||
case "apps/v1/deployments":
|
||||
return "🪂"
|
||||
case "apps/v1/statefulsets":
|
||||
return "🎎"
|
||||
case "apps/v1/daemonsets":
|
||||
return "😈"
|
||||
case "apps/v1/replicasets":
|
||||
return "👯♂️"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue