mirror of https://github.com/Hilbis/Hilbish
feat: add input mode
parent
183b22e565
commit
5a3b28142c
39
api.go
39
api.go
|
@ -4,6 +4,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
// "os/exec"
|
// "os/exec"
|
||||||
|
@ -16,7 +17,7 @@ import (
|
||||||
|
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
"github.com/arnodel/golua/lib/packagelib"
|
"github.com/arnodel/golua/lib/packagelib"
|
||||||
// "github.com/maxlandon/readline"
|
"github.com/maxlandon/readline"
|
||||||
// "github.com/blackfireio/osinfo"
|
// "github.com/blackfireio/osinfo"
|
||||||
// "mvdan.cc/sh/v3/interp"
|
// "mvdan.cc/sh/v3/interp"
|
||||||
)
|
)
|
||||||
|
@ -38,11 +39,9 @@ var exports = map[string]util.LuaExport{
|
||||||
"prependPath": hlprependPath,
|
"prependPath": hlprependPath,
|
||||||
*/
|
*/
|
||||||
"prompt": util.LuaExport{hlprompt, 1, false},
|
"prompt": util.LuaExport{hlprompt, 1, false},
|
||||||
/*
|
"inputMode": util.LuaExport{hlinputMode, 1, false},
|
||||||
"inputMode": hlinputMode,
|
|
||||||
*/
|
|
||||||
"interval": util.LuaExport{hlinterval, 2, false},
|
"interval": util.LuaExport{hlinterval, 2, false},
|
||||||
"read": util.LuaExport{hlprompt, 1, false},
|
"read": util.LuaExport{hlread, 1, false},
|
||||||
/*
|
/*
|
||||||
"run": hlrun,
|
"run": hlrun,
|
||||||
"timeout": hltimeout,
|
"timeout": hltimeout,
|
||||||
|
@ -51,7 +50,7 @@ var exports = map[string]util.LuaExport{
|
||||||
}
|
}
|
||||||
|
|
||||||
var greeting string
|
var greeting string
|
||||||
//var hshMod *lua.LTable
|
var hshMod *rt.Table
|
||||||
var hilbishLoader = packagelib.Loader{
|
var hilbishLoader = packagelib.Loader{
|
||||||
Load: hilbishLoad,
|
Load: hilbishLoad,
|
||||||
Name: "hilbish",
|
Name: "hilbish",
|
||||||
|
@ -60,7 +59,7 @@ var hilbishLoader = packagelib.Loader{
|
||||||
func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
|
func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
mod := rt.NewTable()
|
mod := rt.NewTable()
|
||||||
util.SetExports(rtm, mod, exports)
|
util.SetExports(rtm, mod, exports)
|
||||||
// hshMod = mod
|
hshMod = mod
|
||||||
|
|
||||||
// host, _ := os.Hostname()
|
// host, _ := os.Hostname()
|
||||||
username := curuser.Username
|
username := curuser.Username
|
||||||
|
@ -200,13 +199,14 @@ func luaBinaryComplete(L *lua.LState) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func setVimMode(mode string) {
|
func setVimMode(mode string) {
|
||||||
// util.SetField(l, hshMod, "vimMode", lua.LString(mode), "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
util.SetField(l, hshMod, "vimMode", rt.StringValue(mode), "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
||||||
// hooks.Em.Emit("hilbish.vimMode", mode)
|
hooks.Em.Emit("hilbish.vimMode", mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func unsetVimMode() {
|
func unsetVimMode() {
|
||||||
// util.SetField(l, hshMod, "vimMode", lua.LNil, "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
util.SetField(l, hshMod, "vimMode", rt.NilValue, "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -517,12 +517,20 @@ func hlwhich(L *lua.LState) int {
|
||||||
l.Push(lua.LString(path))
|
l.Push(lua.LString(path))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// inputMode(mode)
|
// inputMode(mode)
|
||||||
// Sets the input mode for Hilbish's line reader. Accepts either emacs for vim
|
// Sets the input mode for Hilbish's line reader. Accepts either emacs for vim
|
||||||
// --- @param mode string
|
// --- @param mode string
|
||||||
func hlinputMode(L *lua.LState) int {
|
func hlinputMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
mode := L.CheckString(1)
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mode, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case "emacs":
|
case "emacs":
|
||||||
unsetVimMode()
|
unsetVimMode()
|
||||||
|
@ -530,11 +538,14 @@ func hlinputMode(L *lua.LState) int {
|
||||||
case "vim":
|
case "vim":
|
||||||
setVimMode("insert")
|
setVimMode("insert")
|
||||||
lr.rl.InputMode = readline.Vim
|
lr.rl.InputMode = readline.Vim
|
||||||
default: L.RaiseError("inputMode: expected vim or emacs, received " + mode)
|
default:
|
||||||
|
return nil, errors.New("inputMode: expected vim or emacs, received " + mode)
|
||||||
}
|
}
|
||||||
return 0
|
|
||||||
|
return c.Next(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// runnerMode(mode)
|
// runnerMode(mode)
|
||||||
// Sets the execution/runner mode for interactive Hilbish. This determines whether
|
// Sets the execution/runner mode for interactive Hilbish. This determines whether
|
||||||
// Hilbish wll try to run input as Lua and/or sh or only do one of either.
|
// Hilbish wll try to run input as Lua and/or sh or only do one of either.
|
||||||
|
|
Loading…
Reference in New Issue