mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "284248fc08829cb97795ecd851206135564bfaf4" and "062f40e9e51baabff8d7a17884a332445edce68d" have entirely different histories.
284248fc08
...
062f40e9e5
51
api.go
51
api.go
|
@ -15,7 +15,6 @@ import (
|
|||
"hilbish/util"
|
||||
|
||||
"github.com/yuin/gopher-lua"
|
||||
"github.com/maxlandon/readline"
|
||||
"mvdan.cc/sh/v3/interp"
|
||||
)
|
||||
|
||||
|
@ -27,7 +26,6 @@ var exports = map[string]lua.LGFunction {
|
|||
"multiprompt": hlmlprompt,
|
||||
"prependPath": hlprependPath,
|
||||
"prompt": hlprompt,
|
||||
"inputMode": hlinputMode,
|
||||
"interval": hlinterval,
|
||||
"read": hlread,
|
||||
"run": hlrun,
|
||||
|
@ -36,11 +34,9 @@ var exports = map[string]lua.LGFunction {
|
|||
}
|
||||
|
||||
var greeting string
|
||||
var hshMod *lua.LTable
|
||||
|
||||
func hilbishLoader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
hshMod = mod
|
||||
|
||||
host, _ := os.Hostname()
|
||||
username := curuser.Username
|
||||
|
@ -61,7 +57,6 @@ The nice lil shell for {blue}Lua{reset} fanatics!
|
|||
util.SetField(L, mod, "interactive", lua.LBool(interactive), "If this is an interactive shell")
|
||||
util.SetField(L, mod, "login", lua.LBool(interactive), "Whether this is a login shell")
|
||||
util.SetField(L, mod, "greeting", lua.LString(greeting), "Hilbish's welcome message for interactive shells. It has Lunacolors formatting.")
|
||||
util.SetField(l, mod, "vimMode", lua.LNil, "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
||||
util.Document(L, mod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
|
||||
|
||||
// hilbish.userDir table
|
||||
|
@ -88,15 +83,6 @@ The nice lil shell for {blue}Lua{reset} fanatics!
|
|||
return 1
|
||||
}
|
||||
|
||||
func setVimMode(mode string) {
|
||||
hooks.Em.Emit("hilbish.vimMode", mode)
|
||||
util.SetField(l, hshMod, "vimMode", lua.LString(mode), "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
||||
}
|
||||
|
||||
func unsetVimMode() {
|
||||
util.SetField(l, hshMod, "vimMode", lua.LNil, "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
||||
}
|
||||
|
||||
// run(cmd)
|
||||
// Runs `cmd` in Hilbish's sh interpreter.
|
||||
// --- @param cmd string
|
||||
|
@ -164,9 +150,6 @@ These will be formatted and replaced with the appropriate values.
|
|||
*/
|
||||
func hlprompt(L *lua.LState) int {
|
||||
prompt = L.CheckString(1)
|
||||
if lr != nil {
|
||||
lr.SetPrompt(fmtPrompt())
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
@ -229,7 +212,6 @@ func appendPath(dir string) {
|
|||
func hlexec(L *lua.LState) int {
|
||||
cmd := L.CheckString(1)
|
||||
cmdArgs, _ := splitInput(cmd)
|
||||
if runtime.GOOS != "windows" {
|
||||
cmdPath, err := exec.LookPath(cmdArgs[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -239,17 +221,9 @@ func hlexec(L *lua.LState) int {
|
|||
|
||||
// syscall.Exec requires an absolute path to a binary
|
||||
// path, args, string slice of environments
|
||||
// TODO: alternative for windows
|
||||
syscall.Exec(cmdPath, cmdArgs, os.Environ())
|
||||
} else {
|
||||
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Run()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
return 0
|
||||
return 0 // random thought: does this ever return?
|
||||
}
|
||||
|
||||
// goro(fn)
|
||||
|
@ -335,8 +309,6 @@ func hlinterval(L *lua.LState) int {
|
|||
// replacing <cmd> with the name of the command (for example `command.git`).
|
||||
// `cb` must be a function that returns a table of the entries to complete.
|
||||
// Nested tables will be used as sub-completions.
|
||||
// --- @param scope string
|
||||
// --- @param cb function
|
||||
func hlcomplete(L *lua.LState) int {
|
||||
scope := L.CheckString(1)
|
||||
cb := L.CheckFunction(2)
|
||||
|
@ -348,7 +320,6 @@ func hlcomplete(L *lua.LState) int {
|
|||
|
||||
// prependPath(dir)
|
||||
// Prepends `dir` to $PATH
|
||||
// --- @param dir string
|
||||
func hlprependPath(L *lua.LState) int {
|
||||
dir := L.CheckString(1)
|
||||
dir = strings.Replace(dir, "~", curuser.HomeDir, 1)
|
||||
|
@ -364,7 +335,6 @@ func hlprependPath(L *lua.LState) int {
|
|||
|
||||
// which(binName)
|
||||
// Searches for an executable called `binName` in the directories of $PATH
|
||||
// --- @param binName string
|
||||
func hlwhich(L *lua.LState) int {
|
||||
binName := L.CheckString(1)
|
||||
path, err := exec.LookPath(binName)
|
||||
|
@ -376,20 +346,3 @@ func hlwhich(L *lua.LState) int {
|
|||
l.Push(lua.LString(path))
|
||||
return 1
|
||||
}
|
||||
|
||||
// inputMode(mode)
|
||||
// Sets the input mode for Hilbish's line reader. Accepts either emacs for vim
|
||||
// --- @param mode string
|
||||
func hlinputMode(L *lua.LState) int {
|
||||
mode := L.CheckString(1)
|
||||
switch mode {
|
||||
case "emacs":
|
||||
unsetVimMode()
|
||||
lr.rl.InputMode = readline.Emacs
|
||||
case "vim":
|
||||
setVimMode("insert")
|
||||
lr.rl.InputMode = readline.Vim
|
||||
default: L.RaiseError("inputMode: expected vim or emacs, received " + mode)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ exec(cmd) > Replaces running hilbish with `cmd`
|
|||
|
||||
goro(fn) > Puts `fn` in a goroutine
|
||||
|
||||
inputMode(mode) > Sets the input mode for Hilbish's line reader. Accepts either emacs for vim
|
||||
|
||||
interval(cb, time) > Runs the `cb` function every `time` milliseconds
|
||||
|
||||
multiprompt(str) > Changes the continued line prompt to `str`
|
||||
|
|
|
@ -16,9 +16,7 @@ function hilbish.appendPath(dir) end
|
|||
--- replacing <cmd> with the name of the command (for example `command.git`).
|
||||
--- `cb` must be a function that returns a table of the entries to complete.
|
||||
--- Nested tables will be used as sub-completions.
|
||||
--- @param scope string
|
||||
--- @param cb function
|
||||
function hilbish.complete(scope, cb) end
|
||||
function hilbish.complete() end
|
||||
|
||||
--- Returns the current directory of the shell
|
||||
function hilbish.cwd() end
|
||||
|
@ -31,10 +29,6 @@ function hilbish.exec(cmd) end
|
|||
--- @param fn function
|
||||
function hilbish.goroutine(fn) end
|
||||
|
||||
--- Sets the input mode for Hilbish's line reader. Accepts either emacs for vim
|
||||
--- @param mode string
|
||||
function hilbish.inputMode(mode) end
|
||||
|
||||
--- Runs the `cb` function every `time` milliseconds
|
||||
--- @param cb function
|
||||
--- @param time number
|
||||
|
@ -45,8 +39,7 @@ function hilbish.interval(cb, time) end
|
|||
function hilbish.mlprompt(str) end
|
||||
|
||||
--- Prepends `dir` to $PATH
|
||||
--- @param dir string
|
||||
function hilbish.prependPath(dir) end
|
||||
function hilbish.prependPath() end
|
||||
|
||||
--- Changes the shell prompt to `str`
|
||||
--- There are a few verbs that can be used in the prompt text.
|
||||
|
@ -73,7 +66,6 @@ function hilbish.run(cmd) end
|
|||
function hilbish.timeout(cb, time) end
|
||||
|
||||
--- Searches for an executable called `binName` in the directories of $PATH
|
||||
--- @param binName string
|
||||
function hilbish.which(binName) end
|
||||
function hilbish.which() end
|
||||
|
||||
return hilbish
|
||||
|
|
2
go.mod
2
go.mod
|
@ -15,6 +15,6 @@ require (
|
|||
|
||||
replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5
|
||||
|
||||
replace github.com/maxlandon/readline => github.com/Rosettea/readline-1 v0.0.0-20220302012429-9ce5d23760f7
|
||||
replace github.com/maxlandon/readline => github.com/Rosettea/readline-1 v0.1.0-beta.0.20220228022904-61f5e4493011
|
||||
|
||||
replace layeh.com/gopher-luar => github.com/layeh/gopher-luar v1.0.10
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,5 +1,3 @@
|
|||
github.com/Rosettea/readline-1 v0.0.0-20220302012429-9ce5d23760f7 h1:LoY+kBKqMQqBcilRpVvifBTVve84asa3btpx3D/+IvM=
|
||||
github.com/Rosettea/readline-1 v0.0.0-20220302012429-9ce5d23760f7/go.mod h1:QiUAvbhg8PzCA4hlafCUl0bKD/0VmcocM4AjqtszAJs=
|
||||
github.com/Rosettea/readline-1 v0.1.0-beta.0.20211207003625-341c7985ad7d h1:KBttN41h/tPahmpaZavviwQ8q4rCkt5CD0HdVmfgPVA=
|
||||
github.com/Rosettea/readline-1 v0.1.0-beta.0.20211207003625-341c7985ad7d/go.mod h1:QiUAvbhg8PzCA4hlafCUl0bKD/0VmcocM4AjqtszAJs=
|
||||
github.com/Rosettea/readline-1 v0.1.0-beta.0.20220228022904-61f5e4493011 h1:+a61iNamZiO3Xru+l/1qtpKqqltVfWEm2r/rxH9hXxY=
|
||||
|
|
19
rl.go
19
rl.go
|
@ -18,18 +18,7 @@ type lineReader struct {
|
|||
// other gophers might hate this naming but this is local, shut up
|
||||
func newLineReader(prompt string) *lineReader {
|
||||
rl := readline.NewInstance()
|
||||
rl.ShowVimMode = false
|
||||
rl.ViModeCallback = func(mode readline.ViMode) {
|
||||
modeStr := ""
|
||||
switch mode {
|
||||
case readline.VimKeys: modeStr = "normal"
|
||||
case readline.VimInsert: modeStr = "insert"
|
||||
case readline.VimDelete: modeStr = "delete"
|
||||
case readline.VimReplaceOnce:
|
||||
case readline.VimReplaceMany: modeStr = "replace"
|
||||
}
|
||||
setVimMode(modeStr)
|
||||
}
|
||||
rl.Multiline = true
|
||||
rl.TabCompleter = func(line []rune, pos int, _ readline.DelayedTabContext) (string, []*readline.CompletionGroup) {
|
||||
ctx := string(line)
|
||||
var completions []string
|
||||
|
@ -207,7 +196,6 @@ func (lr *lineReader) Read() (string, error) {
|
|||
s, err := lr.rl.Readline()
|
||||
// this is so dumb
|
||||
if err == readline.EOF {
|
||||
fmt.Println("")
|
||||
return "", io.EOF
|
||||
}
|
||||
|
||||
|
@ -221,13 +209,10 @@ func (lr *lineReader) SetPrompt(prompt string) {
|
|||
lr.rl.MultilinePrompt = halfPrompt[len(halfPrompt) - 1:][0]
|
||||
} else {
|
||||
// print cursor up ansi code
|
||||
//fmt.Printf("\033[1A")
|
||||
fmt.Printf("\033[1A")
|
||||
lr.rl.SetPrompt("")
|
||||
lr.rl.MultilinePrompt = halfPrompt[len(halfPrompt) - 1:][0]
|
||||
}
|
||||
if !running {
|
||||
lr.rl.RefreshPromptInPlace("")
|
||||
}
|
||||
}
|
||||
|
||||
func (lr *lineReader) AddHistory(cmd string) {
|
||||
|
|
Loading…
Reference in New Issue