summary refs log tree commit diff stats
path: root/aerc.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-21 16:30:23 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-21 16:30:23 -0400
commit8126d82956636a2525263e2d0d985d721fdb8074 (patch)
tree2c5f5c2e2fb2e5ecfb4c12eb8ef6bc575edc39f8 /aerc.go
parentfe79a9a5879936a7f5b16cc6a8be1d93ec1bfae7 (diff)
downloadaerc-8126d82956636a2525263e2d0d985d721fdb8074.tar.gz
Add context-specific commands
Diffstat (limited to 'aerc.go')
-rw-r--r--aerc.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/aerc.go b/aerc.go
index 0da80e9..d086f85 100644
--- a/aerc.go
+++ b/aerc.go
@@ -11,10 +11,23 @@ import (
 
 	"git.sr.ht/~sircmpwn/aerc2/config"
 	"git.sr.ht/~sircmpwn/aerc2/commands"
+	"git.sr.ht/~sircmpwn/aerc2/commands/account"
 	libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
 	"git.sr.ht/~sircmpwn/aerc2/widgets"
 )
 
+func getCommands(selected libui.Drawable) []*commands.Commands {
+	switch selected.(type) {
+	case *widgets.AccountView:
+		return []*commands.Commands{
+			commands.GlobalCommands,
+			account.AccountCommands,
+		}
+	default:
+		return []*commands.Commands{commands.GlobalCommands}
+	}
+}
+
 func main() {
 	var (
 		logOut io.Writer
@@ -38,12 +51,25 @@ func main() {
 		ui   *libui.UI
 	)
 	aerc = widgets.NewAerc(conf, logger, func(cmd string) error {
-		err = commands.ExecuteCommand(aerc, cmd)
-		if _, ok := err.(commands.ErrorExit); ok {
-			ui.Exit = true
-			return nil
+		cmds := getCommands(aerc.SelectedTab())
+		for i, set := range cmds {
+			err := set.ExecuteCommand(aerc, cmd)
+			if _, ok := err.(commands.NoSuchCommand); ok {
+				if i == len(cmds) - 1 {
+					return err
+				} else {
+					continue
+				}
+			} else if _, ok := err.(commands.ErrorExit); ok {
+				ui.Exit = true
+				return nil
+			} else if err != nil {
+				return err
+			} else {
+				break
+			}
 		}
-		return err
+		return nil
 	})
 
 	ui, err = libui.Initialize(conf, aerc)
' href='#n187'>187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289