Compare commits

...

5 Commits

Author SHA1 Message Date
sammyette e37abcb08b
feat: define preload file in var
same as before, enables changing at compile time
2021-06-08 21:00:31 -04:00
sammyette be5ebd6ada
feat: add back cancel input on ctrl c 2021-06-08 21:00:01 -04:00
sammyette 86dbb97cae
feat: define lua require paths in var
this makes it able to be changed compile time, which should help
in support for systems that dont follow fhs (damn nix)
and windows as well, but that'll be first class
2021-06-08 19:16:37 -04:00
sammyette 2a084fc03e
fix: make minimal config work with new version 2021-06-08 17:40:52 -04:00
sammyette ef45bafb54
fix: remove extra newline in error message 2021-06-08 17:24:54 -04:00
5 changed files with 40 additions and 23 deletions

17
lua.go
View File

@ -16,8 +16,8 @@ import (
)
var minimalconf = `
ansikit = require 'ansikit'
prompt(ansikit.format(
lunacolors = require 'lunacolors'
prompt(lunacolors.format(
'{blue}%u {cyan}%d {green}{reset} '
))
`
@ -58,18 +58,11 @@ func LuaInit() {
l.PreloadModule("bait", hooks.Loader)
// Add more paths that Lua can require from
l.DoString(`package.path = package.path
.. ';./libs/?/init.lua;./?/init.lua;./?/?.lua'
.. ';/usr/share/hilbish/libs/?/init.lua;'
.. ';/usr/share/hilbish/libs/?/?.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/init.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'
`)
l.DoString("package.path = package.path .. " + requirePaths)
err := l.DoFile("preload.lua")
if err != nil {
err = l.DoFile("/usr/share/hilbish/preload.lua")
err = l.DoFile(preloadPath)
if err != nil {
fmt.Fprintln(os.Stderr,
"Missing preload file, builtins may be missing.")
@ -83,7 +76,7 @@ func RunConfig(confpath string) {
err := l.DoFile(confpath)
if err != nil {
fmt.Fprintln(os.Stderr, err,
"\nAn error has occured while loading your config! Falling back to minimal default config.\n")
"\nAn error has occured while loading your config! Falling back to minimal default config.")
l.DoString(minimalconf)
}

12
main.go
View File

@ -18,26 +18,17 @@ import (
"golang.org/x/term"
)
var (
version = "v0.4.0"
l *lua.LState
lr *LineReader
prompt string // User's prompt, this will get set when lua side is initialized
multilinePrompt = "> "
commands = map[string]bool{}
aliases = map[string]string{}
homedir string
curuser *user.User
running bool // Is a command currently running
hooks bait.Bait
interactive bool
login bool // Are we the login shell?
noexecute bool // Should we run Lua or only report syntax errors
)
func main() {
@ -227,8 +218,7 @@ func HandleSignals() {
for range c {
if !running {
//readline.ReplaceLine("", 0)
//readline.RefreshLine()
lr.ClearInput()
}
}
}

5
rl.go
View File

@ -34,3 +34,8 @@ func (lr *LineReader) AddHistory(cmd string) {
readline.SaveHistory(homedir + "/.hilbish-history")
}
func (lr *LineReader) ClearInput() {
readline.ReplaceLine("", 0)
readline.RefreshLine()
}

View File

@ -32,3 +32,7 @@ func (lr *LineReader) AddHistory(cmd string) {
return
}
func (lr *LineReader) ClearInput() {
return
}

25
vars.go 100644
View File

@ -0,0 +1,25 @@
package main
// String vars that are free to be changed at compile time
var (
version = "v0.4.0"
requirePaths = `';./libs/?/init.lua;./?/init.lua;./?/?.lua'
.. ';/usr/share/hilbish/libs/?/init.lua;'
.. ';/usr/share/hilbish/libs/?/?.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/init.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'`
preloadPath = "/usr/share/hilbish/preload.lua"
prompt string // Prompt will always get changed anyway
multilinePrompt = "> "
)
// Flags
var (
running bool // Is a command currently running
interactive bool
login bool // Are we the login shell?
noexecute bool // Should we run Lua or only report syntax errors
)