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"] [submodule "libs/lunacolors"]
path = libs/lunacolors path = libs/lunacolors
url = https://github.com/Hilbis/Lunacolors url = https://github.com/Rosettea/Lunacolors
[submodule "libs/succulent"] [submodule "libs/succulent"]
path = libs/succulent path = libs/succulent
url = https://github.com/Rosettea/Succulent url = https://github.com/Rosettea/Succulent

View File

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

View File

@ -1,3 +1,7 @@
+ `hilbish.exit` > Sent when Hilbish is about to exit. + `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 mutex sync.Mutex
ViModeCallback func(ViMode) ViModeCallback func(ViMode)
ViActionCallback func(ViAction, []string)
} }
// NewInstance is used to create a readline instance and initialise it with sane defaults. // 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.InputMode == Vim {
if rl.modeViMode == VimInsert { if rl.modeViMode == VimInsert {
rl.backspace() rl.backspace()
} else { } else if rl.pos != 0 {
rl.pos-- rl.pos--
} }
rl.renderHelpers() rl.renderHelpers()

View File

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

9
rl.go
View File

@ -36,6 +36,14 @@ func newLineReader(prompt string, noHist bool) *lineReader {
} }
setVimMode(modeStr) 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) { rl.TabCompleter = func(line []rune, pos int, _ readline.DelayedTabContext) (string, []*readline.CompletionGroup) {
ctx := string(line) ctx := string(line)
var completions []string var completions []string
@ -192,6 +200,7 @@ func (lr *lineReader) SetPrompt(p string) {
lr.rl.MultilinePrompt = halfPrompt[len(halfPrompt) - 1:][0] lr.rl.MultilinePrompt = halfPrompt[len(halfPrompt) - 1:][0]
} else { } else {
lr.rl.Multiline = false lr.rl.Multiline = false
lr.rl.MultilinePrompt = ""
lr.rl.SetPrompt(p) lr.rl.SetPrompt(p)
} }
if initialized && !running { if initialized && !running {