Compare commits

..

7 Commits

Author SHA1 Message Date
TorchedSammy 91222f9d74
fix(readline): dont reduce pos if its at 0 2022-03-13 20:00:11 -04:00
TorchedSammy feb2ea18fb
docs: document hilbish.vimAction hook 2022-03-13 17:44:54 -04:00
TorchedSammy 726d265cca
feat: add hilbish.vimAction hook (closes #108) 2022-03-13 16:44:11 -04:00
TorchedSammy 7d9c7ddf18
fix: empty multiline prompt if entire prompt is single line 2022-03-13 16:42:14 -04:00
TorchedSammy 5e505d0a8d
fix: increate pos by 1 at paste instead of 2 2022-03-13 16:40:58 -04:00
TorchedSammy e5b6a2586b
chore: update lunacolors 2022-03-13 16:37:33 -04:00
TorchedSammy c5dd05bb1e
refactor: remove mode from prompt func in default conf and dont refresh in vim mode 2022-03-13 16:12:34 -04:00
8 changed files with 31 additions and 8 deletions

2
.gitmodules vendored
View File

@ -1,6 +1,6 @@
[submodule "libs/lunacolors"]
path = libs/lunacolors
url = https://github.com/Hilbis/Lunacolors
url = https://github.com/Rosettea/Lunacolors
[submodule "libs/succulent"]
path = libs/succulent
url = https://github.com/Rosettea/Succulent

View File

@ -3,7 +3,7 @@ local lunacolors = require 'lunacolors'
local bait = require 'bait'
local ansikit = require 'ansikit'
local function doPrompt(fail, mode)
local function doPrompt(fail)
hilbish.prompt(lunacolors.format(
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. ''
))
@ -23,6 +23,4 @@ bait.catch('hilbish.vimMode', function(mode)
else
ansikit.cursorStyle(ansikit.lineCursor)
end
doPrompt(false, mode)
end)

View File

@ -1,3 +1,7 @@
+ `hilbish.exit` > Sent when Hilbish is about to exit.
+ `hilbish.vimMode` > Sent when Hilbish's Vim mode is changed (example insert to normal mode)
+ `hilbish.vimMode` -> modeName > Sent when Hilbish's Vim mode is changed (example insert to normal mode),
`modeName` is the name of the mode changed to (can be `insert`, `normal`, `delete` or `replace`).
+ `hilbish.vimAction` -> actionName, args > Sent when the user does a "vim action," being something
like yanking or pasting text. See `doc vimMode actions` for more info.

@ -1 +1 @@
Subproject commit d200fca13df1c47e133b269420223d7e257dbc41
Subproject commit 5a59d0f4543eb982593750c52f7393e2fd2d15f9

View File

@ -180,6 +180,7 @@ type Instance struct {
mutex sync.Mutex
ViModeCallback func(ViMode)
ViActionCallback func(ViAction, []string)
}
// NewInstance is used to create a readline instance and initialise it with sane defaults.

View File

@ -214,7 +214,7 @@ func (rl *Instance) Readline() (string, error) {
if rl.InputMode == Vim {
if rl.modeViMode == VimInsert {
rl.backspace()
} else {
} else if rl.pos != 0 {
rl.pos--
}
rl.renderHelpers()

View File

@ -33,6 +33,12 @@ var (
VimKeysStr = "[N]"
)
type ViAction int
const (
VimActionYank = iota
VimActionPaste
)
var (
// registerFreeKeys - Some Vim keys don't act on/ aren't affected by registers,
// and using these keys will automatically cancel any active register.
@ -47,6 +53,7 @@ var (
// have been moved away, and only the rl.pos is adjusted: when echoing the input line, the shell
// will compute the new cursor pos accordingly.
func (rl *Instance) vi(r rune) {
activeRegister := string(rl.registers.currentRegister)
// Check if we are in register mode. If yes, and for some characters,
// we select the register and exit this func immediately.
@ -194,10 +201,11 @@ func (rl *Instance) vi(r rune) {
case 'p':
// paste after the cursor position
rl.viUndoSkipAppend = true
rl.pos += 2
rl.pos++
buffer := rl.pasteFromRegister()
vii := rl.getViIterations()
rl.ViActionCallback(VimActionPaste, []string{activeRegister, string(buffer)})
for i := 1; i <= vii; i++ {
rl.insert(buffer)
}
@ -208,6 +216,7 @@ func (rl *Instance) vi(r rune) {
rl.viUndoSkipAppend = true
buffer := rl.pasteFromRegister()
vii := rl.getViIterations()
rl.ViActionCallback(VimActionPaste, []string{activeRegister, string(buffer)})
for i := 1; i <= vii; i++ {
rl.insert(buffer)
}
@ -311,6 +320,7 @@ func (rl *Instance) vi(r rune) {
case 'y':
if rl.viIsYanking {
rl.ViActionCallback(VimActionYank, []string{activeRegister, string(rl.line)})
rl.saveBufToRegister(rl.line)
rl.viIsYanking = false
}
@ -318,6 +328,7 @@ func (rl *Instance) vi(r rune) {
rl.viUndoSkipAppend = true
case 'Y':
rl.ViActionCallback(VimActionYank, []string{activeRegister, string(rl.line)})
rl.saveBufToRegister(rl.line)
rl.viUndoSkipAppend = true

9
rl.go
View File

@ -36,6 +36,14 @@ func newLineReader(prompt string, noHist bool) *lineReader {
}
setVimMode(modeStr)
}
rl.ViActionCallback = func(action readline.ViAction, args []string) {
actionStr := ""
switch action {
case readline.VimActionPaste: actionStr = "paste"
case readline.VimActionYank: actionStr = "yank"
}
hooks.Em.Emit("hilbish.vimAction", actionStr, args)
}
rl.TabCompleter = func(line []rune, pos int, _ readline.DelayedTabContext) (string, []*readline.CompletionGroup) {
ctx := string(line)
var completions []string
@ -192,6 +200,7 @@ func (lr *lineReader) SetPrompt(p string) {
lr.rl.MultilinePrompt = halfPrompt[len(halfPrompt) - 1:][0]
} else {
lr.rl.Multiline = false
lr.rl.MultilinePrompt = ""
lr.rl.SetPrompt(p)
}
if initialized && !running {