diff options
author | Kalyan Sriram <coder.kalyan@gmail.com> | 2020-07-27 01:03:55 -0700 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-07-30 19:35:59 +0200 |
commit | 1ff687ca2b0821c2cacc1fa725abb3302d2af9da (patch) | |
tree | b84df04a645c1fd2ee94d7a08f2f9c717930e9ab /widgets/selecter.go | |
parent | 1bab1754f095a5c0537fc639d0214f6efbb340a2 (diff) | |
download | aerc-1ff687ca2b0821c2cacc1fa725abb3302d2af9da.tar.gz |
Implement style configuration.
Introduce the ability to configure stylesets, allowing customization of
aerc's look (color scheme, font weight, etc). Default styleset is
installed to /path/to/aerc/stylesets/default.
Diffstat (limited to 'widgets/selecter.go')
-rw-r--r-- | widgets/selecter.go | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/widgets/selecter.go b/widgets/selecter.go deleted file mode 100644 index 7fae9cda..00000000 --- a/widgets/selecter.go +++ /dev/null @@ -1,103 +0,0 @@ -package widgets - -import ( - "github.com/gdamore/tcell" - - "git.sr.ht/~sircmpwn/aerc/lib/ui" -) - -type Selecter struct { - ui.Invalidatable - chooser bool - focused bool - focus int - options []string - - onChoose func(option string) - onSelect func(option string) -} - -func NewSelecter(options []string, focus int) *Selecter { - return &Selecter{ - focus: focus, - options: options, - } -} - -func (sel *Selecter) Chooser(chooser bool) *Selecter { - sel.chooser = chooser - return sel -} - -func (sel *Selecter) Invalidate() { - sel.DoInvalidate(sel) -} - -func (sel *Selecter) Draw(ctx *ui.Context) { - ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault) - x := 2 - for i, option := range sel.options { - style := tcell.StyleDefault - if sel.focus == i { - if sel.focused { - style = style.Reverse(true) - } else if sel.chooser { - style = style.Bold(true) - } - } - x += ctx.Printf(x, 1, style, "[%s]", option) - x += 5 - } -} - -func (sel *Selecter) OnChoose(fn func(option string)) *Selecter { - sel.onChoose = fn - return sel -} - -func (sel *Selecter) OnSelect(fn func(option string)) *Selecter { - sel.onSelect = fn - return sel -} - -func (sel *Selecter) Selected() string { - return sel.options[sel.focus] -} - -func (sel *Selecter) Focus(focus bool) { - sel.focused = focus - sel.Invalidate() -} - -func (sel *Selecter) Event(event tcell.Event) bool { - switch event := event.(type) { - case *tcell.EventKey: - switch event.Key() { - case tcell.KeyCtrlH: - fallthrough - case tcell.KeyLeft: - if sel.focus > 0 { - sel.focus-- - sel.Invalidate() - } - if sel.onSelect != nil { - sel.onSelect(sel.Selected()) - } - case tcell.KeyCtrlL: - fallthrough - case tcell.KeyRight: - if sel.focus < len(sel.options)-1 { - sel.focus++ - sel.Invalidate() - } - if sel.onSelect != nil { - sel.onSelect(sel.Selected()) - } - case tcell.KeyEnter: - if sel.onChoose != nil { - sel.onChoose(sel.Selected()) - } - } - } - return false -} |