Skip to content

Commit

Permalink
Merge pull request #336 from blackheaven/segment/vi-mode
Browse files Browse the repository at this point in the history
Add vi-mode segment
  • Loading branch information
justjanne authored Mar 8, 2022
2 parents c1f9df8 + 8ee88a0 commit 324c55e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type arguments struct {
Condensed *bool
IgnoreWarnings *bool
Time *string
ViMode *string
}

var args = arguments{
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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")),
}
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 27 additions & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ var defaults = Config{
254: 242,
255: 243,
},

ViModeCommandFg: 0,
ViModeCommandBg: 250,
ViModeInsertFg: 22,
ViModeInsertBg: 70,
},
"low-contrast": {
Reset: 0xFF,
Expand Down Expand Up @@ -893,6 +898,11 @@ var defaults = Config{
254: 242,
255: 243,
},

ViModeCommandFg: 0,
ViModeCommandBg: 250,
ViModeInsertFg: 22,
ViModeInsertBg: 70,
},
"solarized-dark16": {
Reset: 8,
Expand Down Expand Up @@ -1227,6 +1237,11 @@ var defaults = Config{
254: 242,
255: 243,
},

ViModeCommandFg: 0,
ViModeCommandBg: 250,
ViModeInsertFg: 22,
ViModeInsertBg: 70,
},
"solarized-light16": {
Reset: 0,
Expand Down Expand Up @@ -1561,6 +1576,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 */
Expand Down Expand Up @@ -1636,9 +1656,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 (
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -210,6 +211,8 @@ func main() {
cfg.IgnoreWarnings = *args.IgnoreWarnings
case "time":
cfg.Time = *args.Time
case "vi-mode":
cfg.ViMode = *args.ViMode
}
})

Expand Down
30 changes: 30 additions & 0 deletions segment-vimode.go
Original file line number Diff line number Diff line change
@@ -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,
}}
}
}
5 changes: 5 additions & 0 deletions themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,9 @@ type Theme struct {

DurationFg uint8
DurationBg uint8

ViModeCommandFg uint8
ViModeCommandBg uint8
ViModeInsertFg uint8
ViModeInsertBg uint8
}
6 changes: 5 additions & 1 deletion themes/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,9 @@
"253": 240,
"254": 242,
"255": 243
}
},
"ViModeCommandFg": 0,
"ViModeCommandBg": 250,
"ViModeInsertFg": 22,
"ViModeInsertBg": 70
}

0 comments on commit 324c55e

Please sign in to comment.