-
Notifications
You must be signed in to change notification settings - Fork 135
Add new feature: Vim mode #368
base: master
Are you sure you want to change the base?
Changes from 32 commits
10de420
f0515f4
a15d76c
26d6a15
714e23b
ce00566
56fcff0
2016462
2c86b71
7219309
155c160
ad82e0e
9e0b15d
1b1c0c1
86df4fd
a2cc7de
5050954
422d825
87a8946
b55c343
b38cbd9
6de4e41
eea5b6b
1cc4e20
9e8bd4c
b2bd175
9d79a7f
076d73b
8774ec7
1e22b40
e7e4512
dfdc8c6
30b8b96
68d0832
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} | ||
|
||
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.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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"} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment what exactly this entails when it is set to true. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -211,6 +213,7 @@ func createDefaultConfig() *Config { | |
FileOpenHandlers: make(map[string]string), | ||
FileOpenSaveFilesPermanently: false, | ||
FileDownloadSaveLocation: "~/Downloads", | ||
VimEnabled: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please format the whole codebase with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previous |
||
golang.org/x/tools/gopls v0.5.2 // indirect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.