Compare commits

...

9 Commits

Author SHA1 Message Date
TorchedSammy 4b57dc2ed8
feat: add hilbish.exitCode property (closes #101) 2022-03-06 12:09:10 -04:00
TorchedSammy 928b829388
fix: set hilbish.vimMode property before throwing hook 2022-03-06 12:08:00 -04:00
TorchedSammy 7b693908df
docs: document hilbish scope hooks (closes #100 - 100th issue!!*) 2022-03-06 12:06:39 -04:00
TorchedSammy 8d8b298053
docs: clarify what hooks are from 2022-03-06 12:04:28 -04:00
TorchedSammy 281c443b7b
docs: add spacing between signal hooks 2022-03-06 12:04:01 -04:00
TorchedSammy 3805f13369
feat: throw hilbish.exit hook (closes #99) 2022-03-06 10:23:32 -04:00
TorchedSammy 0b1b5bff2d
feat: change cursor shape based on vim mode 2022-03-06 10:08:42 -04:00
TorchedSammy f8f8cd0b59
chore: update dependencies 2022-03-06 10:07:28 -04:00
TorchedSammy 4bb65572e4
fix(ansikit): define cursor consts 2022-03-06 09:42:35 -04:00
11 changed files with 35 additions and 9 deletions

View File

@ -1,8 +1,9 @@
-- Default Hilbish config -- Default Hilbish config
local lunacolors = require 'lunacolors' local lunacolors = require 'lunacolors'
local bait = require 'bait' local bait = require 'bait'
local ansikit = require 'ansikit'
function doPrompt(fail) local function doPrompt(fail, mode)
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}') .. ''
)) ))
@ -16,3 +17,12 @@ bait.catch('command.exit', function(code)
doPrompt(code ~= 0) doPrompt(code ~= 0)
end) end)
bait.catch('hilbish.vimMode', function(mode)
if mode ~= 'insert' then
ansikit.cursorStyle(ansikit.blockCursor)
else
ansikit.cursorStyle(ansikit.lineCursor)
end
doPrompt(false, mode)
end)

3
api.go
View File

@ -65,6 +65,7 @@ The nice lil shell for {blue}Lua{reset} fanatics!
util.SetField(L, mod, "login", lua.LBool(interactive), "Whether this is a login 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, "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.SetField(l, mod, "vimMode", lua.LNil, "Current Vim mode of Hilbish (nil if not in Vim mode)")
util.SetField(l, hshMod, "exitCode", lua.LNumber(0), "Exit code of last exected command")
util.Document(L, mod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.") util.Document(L, mod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
// hilbish.userDir table // hilbish.userDir table
@ -154,8 +155,8 @@ func luaBinaryComplete(L *lua.LState) int {
} }
func setVimMode(mode string) { 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)") util.SetField(l, hshMod, "vimMode", lua.LString(mode), "Current Vim mode of Hilbish (nil if not in Vim mode)")
hooks.Em.Emit("hilbish.vimMode", mode)
} }
func unsetVimMode() { func unsetVimMode() {

View File

@ -0,0 +1,3 @@
+ `hilbish.exit` > Sent when Hilbish is about to exit.
+ `hilbish.vimMode` > Sent when Hilbish's Vim mode is changed (example insert to normal mode)

View File

@ -1,5 +1,5 @@
Here is listed all scopes for bait hooks. If a hook is related to a command, Here is a list of bait hooks that are thrown by Hilbish. If a hook is related
it will have the `command` scope, as example. to a command, it will have the `command` scope, as example.
Here is the format for a doc for a hook: Here is the format for a doc for a hook:
+ <hook name> -> <args> > <description> + <hook name> -> <args> > <description>

View File

@ -1,4 +1,7 @@
+ `signal.sigint` > Sent when Hilbish receives SIGINT (on Ctrl-C). + `signal.sigint` > Sent when Hilbish receives SIGINT (on Ctrl-C).
+ `signal.resize` > Sent when the terminal is resized. + `signal.resize` > Sent when the terminal is resized.
+ `signal.sigusr1` + `signal.sigusr1`
+ `signal.sigusr2` + `signal.sigusr2`

View File

@ -244,5 +244,6 @@ func cmdFinish(code uint8, cmdstr, oldInput string) {
if !strings.HasPrefix(oldInput, " ") || interactive { if !strings.HasPrefix(oldInput, " ") || interactive {
handleHistory(cmdstr) handleHistory(cmdstr)
} }
util.SetField(l, hshMod, "exitCode", lua.LNumber(code), "Exit code of last exected command")
hooks.Em.Emit("command.exit", code, cmdstr) hooks.Em.Emit("command.exit", code, cmdstr)
} }

2
go.mod
View File

@ -14,7 +14,7 @@ require (
mvdan.cc/sh/v3 v3.4.3 mvdan.cc/sh/v3 v3.4.3
) )
replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5 replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220306140409-795a84b00b4e
replace github.com/maxlandon/readline => github.com/Rosettea/readline-1 v0.0.0-20220305123014-31d4d4214c93 replace github.com/maxlandon/readline => github.com/Rosettea/readline-1 v0.0.0-20220305123014-31d4d4214c93

2
go.sum
View File

@ -10,6 +10,8 @@ github.com/Rosettea/readline-1 v0.1.0-beta.0.20220228022904-61f5e4493011 h1:+a61
github.com/Rosettea/readline-1 v0.1.0-beta.0.20220228022904-61f5e4493011/go.mod h1:QiUAvbhg8PzCA4hlafCUl0bKD/0VmcocM4AjqtszAJs= github.com/Rosettea/readline-1 v0.1.0-beta.0.20220228022904-61f5e4493011/go.mod h1:QiUAvbhg8PzCA4hlafCUl0bKD/0VmcocM4AjqtszAJs=
github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5 h1:ygwVRX8gf5MHA0VzSgOdscCEoAJLjM8joEotfQPgAd0= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5 h1:ygwVRX8gf5MHA0VzSgOdscCEoAJLjM8joEotfQPgAd0=
github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5/go.mod h1:R09vh/04ILvP2Gj8/Z9Jd0Dh0ZIvaucowMEs6abQpWs= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5/go.mod h1:R09vh/04ILvP2Gj8/Z9Jd0Dh0ZIvaucowMEs6abQpWs=
github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220306140409-795a84b00b4e h1:P2XupP8SaylWaudD1DqbWtZ3mIa8OsE9635LmR+Q+lg=
github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20220306140409-795a84b00b4e/go.mod h1:R09vh/04ILvP2Gj8/Z9Jd0Dh0ZIvaucowMEs6abQpWs=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/blackfireio/osinfo v1.0.3 h1:Yk2t2GTPjBcESv6nDSWZKO87bGMQgO+Hi9OoXPpxX8c= github.com/blackfireio/osinfo v1.0.3 h1:Yk2t2GTPjBcESv6nDSWZKO87bGMQgO+Hi9OoXPpxX8c=

View File

@ -1,8 +1,12 @@
-- We're basically porting Ansikit to lua
-- https://github.com/Luvella/AnsiKit/blob/master/lib/index.js
-- which is made by yours truly sammy :^)
local lunacolors = require 'lunacolors' local lunacolors = require 'lunacolors'
local ansikit = {} local ansikit = {
blockCursor = 1,
blockCursorSteady = 2,
underlineCursor = 3,
underlineCursorSteady = 4,
lineCursor = 5,
lineCursorSteady = 6,
}
ansikit.clear = function(scrollback) ansikit.clear = function(scrollback)
local typ = (scrollback and 3 or 2) local typ = (scrollback and 3 or 2)

View File

@ -172,6 +172,7 @@ input:
if err == io.EOF { if err == io.EOF {
// Exit if user presses ^D (ctrl + d) // Exit if user presses ^D (ctrl + d)
hooks.Em.Emit("hilbish.exit")
break break
} }
if err != nil { if err != nil {

View File

@ -45,6 +45,7 @@ commander.register('cd', function (args)
end) end)
commander.register('exit', function() commander.register('exit', function()
bait.throw('hilbish.exit')
os.exit(0) os.exit(0)
end) end)