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

Add new feature: Vim mode #368

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
10de420
Started working on vim event modifiers
invalid-email-address Nov 13, 2020
f0515f4
Added most of the new vim keys (needs rework)
invalid-email-address Nov 14, 2020
a15d76c
Partially working vim movements. Cannot get ESC key to work.
invalid-email-address Nov 15, 2020
26d6a15
Removed some useless lines
invalid-email-address Nov 16, 2020
714e23b
Vim mode working. Added simulation keys inside some lists.
invalid-email-address Nov 16, 2020
ce00566
Dynamic status bar and shortcuts menu
invalid-email-address Nov 16, 2020
56fcff0
Dynamic status bar and shortcuts menu
invalid-email-address Nov 16, 2020
2016462
Fixed some keybindings
invalid-email-address Nov 16, 2020
2c86b71
Merged from upstream
invalid-email-address Nov 16, 2020
7219309
Fixed little issues
invalid-email-address Nov 16, 2020
155c160
Edited changelog
invalid-email-address Nov 16, 2020
ad82e0e
Fixed go.sum
invalid-email-address Nov 16, 2020
9e0b15d
Vim directional keys working everywhere (only in visual mode)
steewbsd Nov 17, 2020
1b1c0c1
Added brief manpage of vim mode
steewbsd Nov 17, 2020
86df4fd
Fixed normal mode binding
steewbsd Nov 17, 2020
a2cc7de
Removed useless go sum lines
steewbsd Nov 17, 2020
5050954
Added replace instruction in go.mod
steewbsd Nov 17, 2020
422d825
Removed upstream fork from go.mod
steewbsd Nov 17, 2020
87a8946
Fixed escape binding
steewbsd Nov 17, 2020
b55c343
Fixed shortcuts dialog inconsistency
steewbsd Nov 17, 2020
b38cbd9
Fixed weird behaviour in text input
steewbsd Nov 17, 2020
6de4e41
Changed expand selection shortcuts, conflicted with movement
steewbsd Nov 18, 2020
eea5b6b
Vim can now be toggled in command mode
steewbsd Nov 18, 2020
1cc4e20
Added vim command synopsis toggle line
steewbsd Nov 18, 2020
9e8bd4c
Moved VimMode to app instead of config
steewbsd Nov 19, 2020
b2bd175
Merged with upstream, fixed conflicts
steewbsd Nov 19, 2020
9d79a7f
Merge branch 'master' of https://github.com/Bios-Marcel/cordless into…
steewbsd Nov 20, 2020
076d73b
"Reverted merge
steewbsd Nov 21, 2020
8774ec7
Fixed windows build
steewbsd Nov 21, 2020
1e22b40
Fixed windows build
steewbsd Nov 21, 2020
e7e4512
Fixed SIGSEGV
steewbsd Nov 21, 2020
dfdc8c6
Attempt to fix appveyor compilation
steewbsd Nov 21, 2020
30b8b96
Fixed go.mod and go.sum
steewbsd Nov 22, 2020
68d0832
Fixed format and qol
steewbsd Nov 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func SetupApplicationWithAccount(app *tview.Application, account string) {
configuration.Token = configuration.GetAccountToken(account)
}

shortcutsLoadError := shortcuts.Load()
shortcutsLoadError := shortcuts.Load(app.VimMode)
shortcuts.InjectVim(app.VimMode)
if shortcutsLoadError != nil {
panic(shortcutsLoadError)
}
Expand Down Expand Up @@ -128,6 +129,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(app.VimMode))
tfaEnableCmd := commandimpls.NewTFAEnableCommand(window, discord)
tfaDisableCmd := commandimpls.NewTFADisableCommand(discord)
tfaBackupGetCmd := commandimpls.NewTFABackupGetCmd(discord, window)
Expand Down
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ clone_folder: c:\gopath\src\github.com\Bios-Marcel\cordless

environment:
GOPATH: c:\gopath
GO111MODULE: on
build: off
stack: go 1.13

Expand All @@ -16,4 +15,4 @@ build_script:

test_script:
- go vet ./...
- go test ./...
- go test ./...
75 changes: 75 additions & 0 deletions commands/commandimpls/vim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package commandimpls

import (
"fmt"
"io"

"github.com/Bios-Marcel/cordless/util/vim"
)

const (
vimOpenHelpPage = `[::b]NAME
vim-mode - minor vim mode for cordless

[::b]SYNOPSIS
[::b]Normal Mode: Navigate around the containers with hjkl.
Perform some usual commands inside text box input, as pasting, moving cursor or such.
Press ESC anywhere to return to normal mode.

[::b]Insert Mode: Type inside box input, perform actions inside chatview.
Insert without any key restriction inside the text box using insert mode.
Inside chat view, perform useful commands such as editing message "i" or replying to user "a"

[::b]Visual Mode: Move around everywhere with vim keys.
This mode allows to use hjkl pretty much anywhere inside the app. Due to some restrictions, this is
the only mode that officially supports using hjkl anywhere.
Also allows using same commands as insert mode inside chat view, or selecting text inside text input.


[::b]DESCRIPTION
This is a minor mode for vim. See all the shorcuts with Ctrl K, and edit them inside shortcuts/shortcuts.go
Toggle vim with vim on/off/enable/disable
`
)

type VimHelp struct {
vimMode *vim.Vim
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doubly tracked, the config already knows about this, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config only knows about VimEnabled, which is a bool only used when instantiating app.VimMode. This is needed to directly enable or disable vim interactively in the command line for this session.

}

func NewVimCmd(vimMode *vim.Vim) *VimHelp {
return &VimHelp{vimMode: vimMode}
}

// PrintHelp prints a static help page for this command
func (v VimHelp) PrintHelp(writer io.Writer) {
fmt.Fprintln(writer, vimOpenHelpPage)
}

func (v VimHelp) Execute(writer io.Writer, parameters []string) {
if len(parameters) < 1 {
fmt.Fprintf(writer, "You did not specify any parameter for this command.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be helpful to tell the user how to use this command if he does it wrong. A simple Usage: vim on/off is probably enough.

return
}
switch parameters[0] {
case "on","enable":
v.vimMode.CurrentMode = vim.NormalMode
fmt.Fprintf(writer, "Vim mode has been enabled.\n")
case "off","disable":
v.vimMode.CurrentMode = vim.NormalMode
v.vimMode.CurrentMode = vim.Disabled
fmt.Fprintf(writer, "Vim mode has been disabled.\n")
default:
fmt.Fprintf(writer, "Parameter %s not recognized.", parameters[0])
}
}

// Name returns the primary name for this command. This name will also be
// used for listing the command in the commandlist.
func (v VimHelp) Name() string {
return "vim"
}

// Aliases are a list of aliases for this command. There might be none.
func (v VimHelp) Aliases() []string {
return []string{"vim", "vim-mode"}
}
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ type Config struct {
// download files to. If FileOpenSaveFilesPermanently has been set to
// true, then all opened files are saved in this folder for example.
FileDownloadSaveLocation string

VimEnabled bool
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment what exactly this entails when it is set to true.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

}

// Account has a name and a token. The name is just for the users recognition.
Expand Down Expand Up @@ -211,6 +213,7 @@ func createDefaultConfig() *Config {
FileOpenHandlers: make(map[string]string),
FileOpenSaveFilesPermanently: false,
FileDownloadSaveLocation: "~/Downloads",
VimEnabled: false,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format the whole codebase with gofmt -w -s . And always use a formatter in your editor please if you forget to do this before the commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That indentation was correctly formatted some commits ago. I don't know what broke it

}
}

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/Bios-Marcel/shortnotforlong v1.1.1
github.com/alecthomas/chroma v0.7.3
github.com/atotto/clipboard v0.1.2
github.com/bunyk/gokeybr v0.0.0-20201019133936-f9e4ed3fdc5d // indirect
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installed some things while working on this, thought I had reverted go.sum and go.mod. Will fix

github.com/gdamore/tcell/v2 v2.0.0
github.com/gen2brain/beeep v0.0.0-20200526185328-e9c15c258e28
github.com/google/go-github/v29 v29.0.3
Expand All @@ -20,6 +21,8 @@ require (
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac
github.com/sergi/go-diff v1.1.0
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
golang.org/x/tools v0.0.0-20201112171726-b38955972a18 // indirect
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous

golang.org/x/tools/gopls v0.5.2 // indirect
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous

gopkg.in/sourcemap.v1 v1.0.5 // indirect
rsc.io/qr v0.2.0
)
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {
fmt.Printf("You are running cordless version %s\nKeep in mind that this version might not be correct for manually built versions, as those can contain additional commits.\n", version.Version)
} else {
//App that will be reused throughout the process runtime.
tviewApp := tview.NewApplication()
tviewApp := tview.NewApplication(config.Current.VimEnabled)

if accountToUse != nil && *accountToUse != "" {
app.SetupApplicationWithAccount(tviewApp, *accountToUse)
Expand Down
Loading