Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
Vim can now be toggled in command mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Perez committed Nov 18, 2020
1 parent 6de4e41 commit eea5b6b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func SetupApplicationWithAccount(app *tview.Application, account string) {
window.RegisterCommand(serverCreateCmd)
window.RegisterCommand(commandimpls.NewServerCommand(serverJoinCmd, serverLeaveCmd, serverCreateCmd))
window.RegisterCommand(commandimpls.NewNickSetCmd(discord, window))
window.RegisterCommand(commandimpls.NewVimCmd())
window.RegisterCommand(commandimpls.NewVimCmd(config.Current))
tfaEnableCmd := commandimpls.NewTFAEnableCommand(window, discord)
tfaDisableCmd := commandimpls.NewTFADisableCommand(discord)
tfaBackupGetCmd := commandimpls.NewTFABackupGetCmd(discord, window)
Expand Down
26 changes: 17 additions & 9 deletions commands/commandimpls/vim.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ const (
)

type VimHelp struct {
Config *config.Config
}

func NewVimCmd() *VimHelp {
return new(VimHelp)
func NewVimCmd(c *config.Config) *VimHelp {
return &VimHelp{Config: c}
}

// PrintHelp prints a static help page for this command
Expand All @@ -44,14 +45,21 @@ func (v VimHelp) PrintHelp(writer io.Writer) {
}

func (v VimHelp) Execute(writer io.Writer, parameters []string) {
if config.Current.VimMode.CurrentMode == vim.Disabled {
config.Current.VimMode.Normal()
fmt.Fprintf(writer, "Vim mode enabled")
} else {
config.Current.VimMode.SetMode(vim.Disabled)
fmt.Fprintf(writer, "Vim mode disabled")
if len(parameters) < 1 {
fmt.Fprintf(writer, "You did not specify any parameter for this command.")
return
}
switch parameters[0] {
case "on","enable":
v.Config.VimMode.CurrentMode = vim.NormalMode
fmt.Fprintf(writer, "Vim mode has been enabled.")
case "off","disable":
v.Config.VimMode.CurrentMode = vim.NormalMode
v.Config.VimMode.CurrentMode = vim.Disabled
fmt.Fprintf(writer, "Vim mode has been disabled.")
default:
fmt.Fprintf(writer, "Parameter %s not recognized.", parameters[0])
}
config.PersistConfig()
}

// Name returns the primary name for this command. This name will also be
Expand Down
44 changes: 23 additions & 21 deletions ui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -2140,28 +2140,30 @@ func (window *Window) handleGlobalShortcuts(event *tcell.EventKey) *tcell.EventK
return nil
}

if shortcuts.VimInsertMode.Equals(event) {
config.Current.VimMode.Insert()
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString())
return nil
} else if shortcuts.VimVisualMode.Equals(event) {
config.Current.VimMode.Visual()
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString())
return nil
} else if shortcuts.VimNormalMode.Equals(event) && window.app.GetRoot() == window.rootContainer {
config.Current.VimMode.Normal()
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString())
return nil
}
if config.Current.VimMode.CurrentMode != vim.Disabled {
if shortcuts.VimInsertMode.Equals(event) {
config.Current.VimMode.Insert()
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString())
return nil
} else if shortcuts.VimVisualMode.Equals(event) {
config.Current.VimMode.Visual()
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString())
return nil
} else if shortcuts.VimNormalMode.Equals(event) && window.app.GetRoot() == window.rootContainer {
config.Current.VimMode.Normal()
window.vimStatus.Content = fmt.Sprintf("Vim: %s",config.Current.VimMode.CurrentModeString())
return nil
}

if shortcuts.VimSimKeyDown.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyDown, rune(tcell.KeyDown), tcell.ModNone)
} else if shortcuts.VimSimKeyUp.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone)
} else if shortcuts.VimSimKeyLeft.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyLeft, rune(tcell.KeyLeft), tcell.ModNone)
} else if shortcuts.VimSimKeyRight.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyRight, rune(tcell.KeyRight), tcell.ModNone)
if shortcuts.VimSimKeyDown.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyDown, rune(tcell.KeyDown), tcell.ModNone)
} else if shortcuts.VimSimKeyUp.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyUp, rune(tcell.KeyUp), tcell.ModNone)
} else if shortcuts.VimSimKeyLeft.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyLeft, rune(tcell.KeyLeft), tcell.ModNone)
} else if shortcuts.VimSimKeyRight.Equals(event) && config.Current.VimMode.CurrentMode == vim.VisualMode {
return tcell.NewEventKey(tcell.KeyRight, rune(tcell.KeyRight), tcell.ModNone)
}
}

window.app.QueueUpdateDraw(func() {
Expand Down

0 comments on commit eea5b6b

Please sign in to comment.