mirror of https://github.com/Hilbis/Hilbish
Compare commits
7 Commits
2fb481c4cb
...
61c9e12a4a
Author | SHA1 | Date |
---|---|---|
Renzix | 61c9e12a4a | |
TorchedSammy | 0aba60b5de | |
TorchedSammy | 62a6cc56b9 | |
TorchedSammy | e5d841a0a7 | |
TorchedSammy | 3e50e608c1 | |
TorchedSammy | 76f100ca77 | |
TorchedSammy | 0cad0e7e66 |
14
api.go
14
api.go
|
@ -28,6 +28,7 @@ var exports = map[string]lua.LGFunction {
|
||||||
"exec": hlexec,
|
"exec": hlexec,
|
||||||
"runnerMode": hlrunnerMode,
|
"runnerMode": hlrunnerMode,
|
||||||
"goro": hlgoro,
|
"goro": hlgoro,
|
||||||
|
"highlighter": hlhighlighter,
|
||||||
"hinter": hlhinter,
|
"hinter": hlhinter,
|
||||||
"multiprompt": hlmlprompt,
|
"multiprompt": hlmlprompt,
|
||||||
"prependPath": hlprependPath,
|
"prependPath": hlprependPath,
|
||||||
|
@ -517,3 +518,16 @@ func hlhinter(L *lua.LState) int {
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// highlighter(cb)
|
||||||
|
// Sets the highlighter function. This is mainly for syntax hightlighting, but in
|
||||||
|
// reality could set the input of the prompt to display anything. The callback
|
||||||
|
// is passed the current line as typed and is expected to return a line that will
|
||||||
|
// be used to display in the line.
|
||||||
|
// --- @param cb function
|
||||||
|
func hlhighlighter(L *lua.LState) int {
|
||||||
|
highlighterCb := L.CheckFunction(1)
|
||||||
|
highlighter = highlighterCb
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,11 @@ exec(cmd) > Replaces running hilbish with `cmd`
|
||||||
|
|
||||||
goro(fn) > Puts `fn` in a goroutine
|
goro(fn) > Puts `fn` in a goroutine
|
||||||
|
|
||||||
|
highlighter(cb) > Sets the highlighter function. This is mainly for syntax hightlighting, but in
|
||||||
|
reality could set the input of the prompt to display anything. The callback
|
||||||
|
is passed the current line as typed and is expected to return a line that will
|
||||||
|
be used to display in the line.
|
||||||
|
|
||||||
hinter(cb) > Sets the hinter function. This will be called on every key insert to determine
|
hinter(cb) > Sets the hinter function. This will be called on every key insert to determine
|
||||||
what text to use as an inline hint. The callback is passed 2 arguments:
|
what text to use as an inline hint. The callback is passed 2 arguments:
|
||||||
the current line and the position. It is expected to return a string
|
the current line and the position. It is expected to return a string
|
||||||
|
|
|
@ -33,6 +33,13 @@ function hilbish.exec(cmd) end
|
||||||
--- @param fn function
|
--- @param fn function
|
||||||
function hilbish.goro(fn) end
|
function hilbish.goro(fn) end
|
||||||
|
|
||||||
|
--- Sets the highlighter function. This is mainly for syntax hightlighting, but in
|
||||||
|
--- reality could set the input of the prompt to display anything. The callback
|
||||||
|
--- is passed the current line as typed and is expected to return a line that will
|
||||||
|
--- be used to display in the line.
|
||||||
|
--- @param cb function
|
||||||
|
function hilbish.highlighter(cb) end
|
||||||
|
|
||||||
--- Sets the hinter function. This will be called on every key insert to determine
|
--- Sets the hinter function. This will be called on every key insert to determine
|
||||||
--- what text to use as an inline hint. The callback is passed 2 arguments:
|
--- what text to use as an inline hint. The callback is passed 2 arguments:
|
||||||
--- the current line and the position. It is expected to return a string
|
--- the current line and the position. It is expected to return a string
|
||||||
|
|
|
@ -176,3 +176,9 @@ func (rl *Instance) deleteToBeginning() {
|
||||||
rl.line = rl.line[rl.pos:]
|
rl.line = rl.line[rl.pos:]
|
||||||
rl.pos = 0
|
rl.pos = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rl *Instance) deleteToEnd() {
|
||||||
|
rl.resetVirtualComp(false)
|
||||||
|
// Keep everything before the cursor
|
||||||
|
rl.line = rl.line[:rl.pos]
|
||||||
|
}
|
||||||
|
|
|
@ -189,6 +189,16 @@ func (rl *Instance) Readline() (string, error) {
|
||||||
rl.resetHelpers()
|
rl.resetHelpers()
|
||||||
rl.updateHelpers()
|
rl.updateHelpers()
|
||||||
|
|
||||||
|
case charCtrlK:
|
||||||
|
if rl.modeTabCompletion {
|
||||||
|
rl.resetVirtualComp(true)
|
||||||
|
}
|
||||||
|
// Delete everything after the cursor position
|
||||||
|
rl.saveBufToRegister(rl.line[rl.pos:])
|
||||||
|
rl.deleteToEnd()
|
||||||
|
rl.resetHelpers()
|
||||||
|
rl.updateHelpers()
|
||||||
|
|
||||||
case charBackspace, charBackspace2:
|
case charBackspace, charBackspace2:
|
||||||
// When currently in history completion, we refresh and automatically
|
// When currently in history completion, we refresh and automatically
|
||||||
// insert the first (filtered) candidate, virtually
|
// insert the first (filtered) candidate, virtually
|
||||||
|
|
29
rl.go
29
rl.go
|
@ -13,7 +13,8 @@ type lineReader struct {
|
||||||
rl *readline.Instance
|
rl *readline.Instance
|
||||||
}
|
}
|
||||||
var fileHist *fileHistory
|
var fileHist *fileHistory
|
||||||
var hinter lua.LValue
|
var hinter lua.LValue = lua.LNil
|
||||||
|
var highlighter lua.LValue = lua.LNil
|
||||||
|
|
||||||
// other gophers might hate this naming but this is local, shut up
|
// other gophers might hate this naming but this is local, shut up
|
||||||
func newLineReader(prompt string, noHist bool) *lineReader {
|
func newLineReader(prompt string, noHist bool) *lineReader {
|
||||||
|
@ -46,6 +47,10 @@ func newLineReader(prompt string, noHist bool) *lineReader {
|
||||||
hooks.Em.Emit("hilbish.vimAction", actionStr, args)
|
hooks.Em.Emit("hilbish.vimAction", actionStr, args)
|
||||||
}
|
}
|
||||||
rl.HintText = func(line []rune, pos int) []rune {
|
rl.HintText = func(line []rune, pos int) []rune {
|
||||||
|
if hinter == lua.LNil {
|
||||||
|
return []rune{}
|
||||||
|
}
|
||||||
|
|
||||||
err := l.CallByParam(lua.P{
|
err := l.CallByParam(lua.P{
|
||||||
Fn: hinter,
|
Fn: hinter,
|
||||||
NRet: 1,
|
NRet: 1,
|
||||||
|
@ -64,6 +69,28 @@ func newLineReader(prompt string, noHist bool) *lineReader {
|
||||||
|
|
||||||
return []rune(hintText)
|
return []rune(hintText)
|
||||||
}
|
}
|
||||||
|
rl.SyntaxHighlighter = func(line []rune) string {
|
||||||
|
if highlighter == lua.LNil {
|
||||||
|
return string(line)
|
||||||
|
}
|
||||||
|
err := l.CallByParam(lua.P{
|
||||||
|
Fn: highlighter,
|
||||||
|
NRet: 1,
|
||||||
|
Protect: true,
|
||||||
|
}, lua.LString(string(line)))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return string(line)
|
||||||
|
}
|
||||||
|
|
||||||
|
retVal := l.Get(-1)
|
||||||
|
highlighted := ""
|
||||||
|
if luaStr, ok := retVal.(lua.LString); retVal != lua.LNil && ok {
|
||||||
|
highlighted = luaStr.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
return highlighted
|
||||||
|
}
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue