summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorGregory Mullen <greg@cmdline.org>2019-06-27 10:33:11 -0700
committerDrew DeVault <sir@cmpwn.com>2019-06-29 14:24:19 -0400
commit2a0961701c4cabecc53d134ed1782e5612e64580 (patch)
tree57952ac82fb7104113ca7fc0e25dc3d225f77ea7 /widgets
parent177651bddab145c8a56cdfeb0d57b5fd95a6d0e2 (diff)
downloadaerc-2a0961701c4cabecc53d134ed1782e5612e64580.tar.gz
Implement basic tab completion support
Tab completion currently only works on commands. Contextual completion
will be added in the future.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/aerc.go6
-rw-r--r--widgets/dirlist.go4
-rw-r--r--widgets/exline.go24
3 files changed, 26 insertions, 8 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 8aa1e2c..ade56d1 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -14,6 +14,7 @@ import (
 type Aerc struct {
 	accounts    map[string]*AccountView
 	cmd         func(cmd string) error
+	complete    func(cmd string) []string
 	conf        *config.AercConfig
 	focused     libui.Interactive
 	grid        *libui.Grid
@@ -26,7 +27,7 @@ type Aerc struct {
 }
 
 func NewAerc(conf *config.AercConfig, logger *log.Logger,
-	cmd func(cmd string) error) *Aerc {
+	cmd func(cmd string) error, complete func(cmd string) []string) *Aerc {
 
 	tabs := libui.NewTabs()
 
@@ -49,6 +50,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
 		accounts:   make(map[string]*AccountView),
 		conf:       conf,
 		cmd:        cmd,
+		complete:   complete,
 		grid:       grid,
 		logger:     logger,
 		statusbar:  statusbar,
@@ -289,6 +291,8 @@ func (aerc *Aerc) BeginExCommand() {
 	}, func() {
 		aerc.statusbar.Pop()
 		aerc.focus(previous)
+	}, func(cmd string) []string {
+		return aerc.complete(cmd)
 	})
 	aerc.statusbar.Push(exline)
 	aerc.focus(exline)
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 2b4773a..71cf79d 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -40,6 +40,10 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
 	return dirlist
 }
 
+func (dirlist *DirectoryList) List() []string {
+	return dirlist.dirs
+}
+
 func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
 	var dirs []string
 	dirlist.worker.PostAction(
diff --git a/widgets/exline.go b/widgets/exline.go
index ff18d13..e984ee1 100644
--- a/widgets/exline.go
+++ b/widgets/exline.go
@@ -8,17 +8,21 @@ import (
 
 type ExLine struct {
 	ui.Invalidatable
-	cancel func()
-	commit func(cmd string)
-	input  *ui.TextInput
+	cancel      func()
+	commit      func(cmd string)
+	tabcomplete func(cmd string) []string
+	input       *ui.TextInput
 }
 
-func NewExLine(commit func(cmd string), cancel func()) *ExLine {
+func NewExLine(commit func(cmd string), cancel func(),
+	tabcomplete func(cmd string) []string) *ExLine {
+
 	input := ui.NewTextInput("").Prompt(":")
 	exline := &ExLine{
-		cancel: cancel,
-		commit: commit,
-		input:  input,
+		cancel:      cancel,
+		commit:      commit,
+		tabcomplete: tabcomplete,
+		input:       input,
 	}
 	input.OnInvalidate(func(d ui.Drawable) {
 		exline.Invalidate()
@@ -48,6 +52,12 @@ func (ex *ExLine) Event(event tcell.Event) bool {
 		case tcell.KeyEsc, tcell.KeyCtrlC:
 			ex.input.Focus(false)
 			ex.cancel()
+		case tcell.KeyTab:
+			complete := ex.tabcomplete(ex.input.StringLeft())
+			if len(complete) == 1 {
+				ex.input.Set(complete[0] + " " + ex.input.StringRight())
+			}
+			ex.Invalidate()
 		default:
 			return ex.input.Event(event)
 		}