diff --git a/README.md b/README.md index e9f3776d..f08a1b8e 100644 --- a/README.md +++ b/README.md @@ -248,7 +248,7 @@ Usage of powerline-go: (default "patched") -modules string The list of modules to load, separated by ',' - (valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl) + (valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl) Unrecognized modules will be invoked as 'powerline-go-MODULE' executable plugins and should output a (possibly empty) list of JSON objects that unmarshal to powerline-go's Segment structs. (default "venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root") -modules-right string @@ -266,7 +266,7 @@ Usage of powerline-go: Use '~' for your home dir. You may need to escape this character to avoid shell substitution. -priority string Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ',' - (valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl) + (valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl) (default "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path") -shell string Set this to your shell type @@ -293,6 +293,8 @@ Usage of powerline-go: (default 16) -venv-name-size-limit int Show indicator instead of virtualenv name if name is longer than this limit (defaults to 0, which is unlimited) + -vi-mode string + The current vi-mode (eg. KEYMAP for zsh) for vi-module module ``` ### Eval diff --git a/args.go b/args.go index 0843458c..6ba3ce89 100644 --- a/args.go +++ b/args.go @@ -45,6 +45,7 @@ type arguments struct { Condensed *bool IgnoreWarnings *bool Time *string + ViMode *string } var args = arguments{ @@ -126,7 +127,7 @@ var args = arguments{ "modules", strings.Join(defaults.Modules, ","), commentsWithDefaults("The list of modules to load, separated by ','", - "(valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl)", + "(valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl)", "Unrecognized modules will be invoked as 'powerline-go-MODULE' executable plugins and should output a (possibly empty) list of JSON objects that unmarshal to powerline-go's Segment structs.")), ModulesRight: flag.String( "modules-right", @@ -138,7 +139,7 @@ var args = arguments{ "priority", strings.Join(defaults.Priority, ","), commentsWithDefaults("Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ','", - "(valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl)")), + "(valid choices: aws, bzr, cwd, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl)")), MaxWidthPercentage: flag.Int( "max-width", defaults.MaxWidthPercentage, @@ -221,4 +222,8 @@ var args = arguments{ "ignore-warnings", defaults.IgnoreWarnings, comments("Ignores all warnings regarding unset or broken variables")), + ViMode: flag.String( + "vi-mode", + defaults.ViMode, + comments("The current vi-mode (eg. KEYMAP for zsh) for vi-module module")), } diff --git a/config.go b/config.go index 941d7181..0660cd42 100644 --- a/config.go +++ b/config.go @@ -55,6 +55,7 @@ type Config struct { Shells ShellMap `json:"shells"` Themes ThemeMap `json:"themes"` Time string `json:"-"` + ViMode string `json:"vi-mode"` } func (mode *SymbolTemplate) UnmarshalJSON(data []byte) error { diff --git a/defaults.go b/defaults.go index e7de6b8a..40b747b1 100644 --- a/defaults.go +++ b/defaults.go @@ -530,6 +530,11 @@ var defaults = Config{ 254: 242, 255: 243, }, + + ViModeCommandFg: 0, + ViModeCommandBg: 250, + ViModeInsertFg: 22, + ViModeInsertBg: 70, }, "low-contrast": { Reset: 0xFF, @@ -890,6 +895,11 @@ var defaults = Config{ 254: 242, 255: 243, }, + + ViModeCommandFg: 0, + ViModeCommandBg: 250, + ViModeInsertFg: 22, + ViModeInsertBg: 70, }, "solarized-dark16": { Reset: 8, @@ -1224,6 +1234,11 @@ var defaults = Config{ 254: 242, 255: 243, }, + + ViModeCommandFg: 0, + ViModeCommandBg: 250, + ViModeInsertFg: 22, + ViModeInsertBg: 70, }, "solarized-light16": { Reset: 0, @@ -1558,6 +1573,11 @@ var defaults = Config{ 254: 242, 255: 243, }, + + ViModeCommandFg: 0, + ViModeCommandBg: 250, + ViModeInsertFg: 22, + ViModeInsertBg: 70, }, "gruvbox": { /* based on https://github.com/b-ryan/powerline-shell/blob/master/powerline_shell/themes/gruvbox.py */ @@ -1633,9 +1653,15 @@ var defaults = Config{ LoadThresholdBad: 1.0, NixShellFg: gruvbox_light0, NixShellBg: gruvbox_faded_purple, + + ViModeCommandFg: 0, + ViModeCommandBg: 250, + ViModeInsertFg: 22, + ViModeInsertBg: 70, }, }, - Time: "15:04:05", + Time: "15:04:05", + ViMode: "", } const ( diff --git a/main.go b/main.go index 890a08e7..84ffa492 100644 --- a/main.go +++ b/main.go @@ -105,6 +105,7 @@ var modules = map[string]func(*powerline) []pwl.Segment{ "user": segmentUser, "venv": segmentVirtualEnv, "vgo": segmentVirtualGo, + "vi-mode": segmentViMode, "wsl": segmentWSL, "nix-shell": segmentNixShell, } @@ -210,6 +211,8 @@ func main() { cfg.IgnoreWarnings = *args.IgnoreWarnings case "time": cfg.Time = *args.Time + case "vi-mode": + cfg.ViMode = *args.ViMode } }) diff --git a/segment-vimode.go b/segment-vimode.go new file mode 100644 index 00000000..8d91eee8 --- /dev/null +++ b/segment-vimode.go @@ -0,0 +1,30 @@ +package main + +import ( + pwl "github.com/justjanne/powerline-go/powerline" +) + +func segmentViMode(p *powerline) []pwl.Segment { + mode := p.cfg.ViMode + if mode == "" { + warn("'--vi-mode' is not set.") + return []pwl.Segment{} + } + + switch mode { + case "vicmd": + return []pwl.Segment{{ + Name: "vi-mode", + Content: "C", + Foreground: p.theme.ViModeCommandFg, + Background: p.theme.ViModeCommandBg, + }} + default: // usually "viins" or "main" + return []pwl.Segment{{ + Name: "vi-mode", + Content: "I", + Foreground: p.theme.ViModeInsertFg, + Background: p.theme.ViModeInsertBg, + }} + } +} diff --git a/themes.go b/themes.go index 16967d72..c9d1165e 100644 --- a/themes.go +++ b/themes.go @@ -151,4 +151,9 @@ type Theme struct { DurationFg uint8 DurationBg uint8 + + ViModeCommandFg uint8 + ViModeCommandBg uint8 + ViModeInsertFg uint8 + ViModeInsertBg uint8 } diff --git a/themes/default.json b/themes/default.json index 9e296785..e1146dd1 100644 --- a/themes/default.json +++ b/themes/default.json @@ -332,5 +332,9 @@ "253": 240, "254": 242, "255": 243 - } + }, + "ViModeCommandFg": 0, + "ViModeCommandBg": 250, + "ViModeInsertFg": 22, + "ViModeInsertBg": 70 }