diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-01-13 15:32:52 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-01-13 15:32:52 -0500 |
commit | cf664620005cf65d060e689fbb27b939dd3192a7 (patch) | |
tree | a74ea7f69e6004cd407e272ab80768b5ee314735 /widgets/directories.go | |
parent | 257affcd4841b8f595a4a13cdb0fd2a1a2dd0faa (diff) | |
download | aerc-cf664620005cf65d060e689fbb27b939dd3192a7.tar.gz |
Simplify approach to directory list
This doesn't really need to be abstract tbh
Diffstat (limited to 'widgets/directories.go')
-rw-r--r-- | widgets/directories.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/widgets/directories.go b/widgets/directories.go index 16b0e5a..1602b3c 100644 --- a/widgets/directories.go +++ b/widgets/directories.go @@ -16,6 +16,7 @@ type DirectoryList struct { dirs []string logger *log.Logger onInvalidate func(d ui.Drawable) + selected string worker *types.Worker } @@ -25,7 +26,7 @@ func NewDirectoryList(conf *config.AccountConfig, return &DirectoryList{conf: conf, logger: logger, worker: worker} } -func (dirlist *DirectoryList) UpdateList() { +func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) { var dirs []string dirlist.worker.PostAction( &types.ListDirectories{}, func(msg types.WorkerMessage) { @@ -37,10 +38,18 @@ func (dirlist *DirectoryList) UpdateList() { sort.Strings(dirs) dirlist.dirs = dirs dirlist.Invalidate() + if done != nil { + done(dirs) + } } }) } +func (dirlist *DirectoryList) Select(name string) { + dirlist.selected = name + dirlist.Invalidate() +} + func (dirlist *DirectoryList) OnInvalidate(onInvalidate func(d ui.Drawable)) { dirlist.onInvalidate = onInvalidate } @@ -58,14 +67,20 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) { if row >= ctx.Height() { break } - if len(dirlist.conf.Folders) > 1 { + if len(dirlist.conf.Folders) > 1 && name != dirlist.selected { idx := sort.SearchStrings(dirlist.conf.Folders, name) if idx == len(dirlist.conf.Folders) || dirlist.conf.Folders[idx] != name { continue } } - ctx.Printf(0, row, tcell.StyleDefault, "%s", name) + style := tcell.StyleDefault + if name == dirlist.selected { + style = style.Background(tcell.ColorWhite). + Foreground(tcell.ColorBlack) + } + ctx.Fill(0, row, ctx.Width(), 1, ' ', style) + ctx.Printf(0, row, style, "%s", name) row++ } } |