refactor!: move hilbish.greeting to an opt (closes #184)

lua-history
TorchedSammy 2022-07-09 17:15:13 -04:00
parent 90ed12d551
commit a106f4aea0
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
5 changed files with 15 additions and 11 deletions

View File

@ -9,8 +9,6 @@ local function doPrompt(fail)
)) ))
end end
print(lunacolors.format(hilbish.greeting))
doPrompt() doPrompt()
bait.catch('command.exit', function(code) bait.catch('command.exit', function(code)

View File

@ -78,11 +78,12 @@ User input has been added to the return to account for runners wanting to
prompt for continued input, and to add it properly to history. `continue` prompt for continued input, and to add it properly to history. `continue`
got added so that it would be easier for runners to get continued input got added so that it would be easier for runners to get continued input
without having to actually handle it at all. without having to actually handle it at all.
- **Breaking Change:** Job objects and timers are now Lua userdata instead - **Breaking Change:** Job objects and timers are now Lua userdata instead
of a table, so their functions require you to call them with a colon instead of a table, so their functions require you to call them with a colon instead
of a dot. (ie. `job.stop()` -> `job:stop()`) of a dot. (ie. `job.stop()` -> `job:stop()`)
- All `fs` module functions which take paths now implicitly expand ~ to home. - All `fs` module functions which take paths now implicitly expand ~ to home.
- **Breaking Change:** `hilbish.greeting` has been moved to an opt (`hilbish.opts.greeting`) and is
always printed by default. To disable it, set the opt to false.
### Fixed ### Fixed
- If in Vim replace mode, input at the end of the line inserts instead of - If in Vim replace mode, input at the end of the line inserts instead of

6
api.go
View File

@ -44,7 +44,6 @@ var exports = map[string]util.LuaExport{
"which": {hlwhich, 1, false}, "which": {hlwhich, 1, false},
} }
var greeting string
var hshMod *rt.Table var hshMod *rt.Table
var hilbishLoader = packagelib.Loader{ var hilbishLoader = packagelib.Loader{
Load: hilbishLoad, Load: hilbishLoad,
@ -103,10 +102,6 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
} }
greeting = `Welcome to {magenta}Hilbish{reset}, {cyan}` + username + `{reset}.
The nice lil shell for {blue}Lua{reset} fanatics!
Check out the {blue}{bold}guide{reset} command to get started.
`
util.SetFieldProtected(fakeMod, mod, "ver", rt.StringValue(getVersion()), "Hilbish version") util.SetFieldProtected(fakeMod, mod, "ver", rt.StringValue(getVersion()), "Hilbish version")
util.SetFieldProtected(fakeMod, mod, "user", rt.StringValue(username), "Username of user") util.SetFieldProtected(fakeMod, mod, "user", rt.StringValue(username), "Username of user")
util.SetFieldProtected(fakeMod, mod, "host", rt.StringValue(host), "Host name of the machine") util.SetFieldProtected(fakeMod, mod, "host", rt.StringValue(host), "Host name of the machine")
@ -114,7 +109,6 @@ Check out the {blue}{bold}guide{reset} command to get started.
util.SetFieldProtected(fakeMod, mod, "dataDir", rt.StringValue(dataDir), "Directory for Hilbish's data files") util.SetFieldProtected(fakeMod, mod, "dataDir", rt.StringValue(dataDir), "Directory for Hilbish's data files")
util.SetFieldProtected(fakeMod, mod, "interactive", rt.BoolValue(interactive), "If this is an interactive shell") util.SetFieldProtected(fakeMod, mod, "interactive", rt.BoolValue(interactive), "If this is an interactive shell")
util.SetFieldProtected(fakeMod, mod, "login", rt.BoolValue(login), "Whether this is a login shell") util.SetFieldProtected(fakeMod, mod, "login", rt.BoolValue(login), "Whether this is a login shell")
util.SetFieldProtected(fakeMod, mod, "greeting", rt.StringValue(greeting), "Hilbish's welcome message for interactive shells. It has Lunacolors formatting.")
util.SetFieldProtected(fakeMod, mod, "vimMode", rt.NilValue, "Current Vim mode of Hilbish (nil if not in Vim mode)") util.SetFieldProtected(fakeMod, mod, "vimMode", rt.NilValue, "Current Vim mode of Hilbish (nil if not in Vim mode)")
util.SetFieldProtected(fakeMod, mod, "exitCode", rt.IntValue(0), "Exit code of last exected command") util.SetFieldProtected(fakeMod, mod, "exitCode", rt.IntValue(0), "Exit code of last exected command")
util.Document(fakeMod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.") util.Document(fakeMod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")

View File

@ -0,0 +1,8 @@
local bait = require 'bait'
local lunacolors = require 'lunacolors'
bait.catch('hilbish.init', function()
if hilbish.interactive and type(hilbish.opts.greeting) == 'string' then
print(lunacolors.format(hilbish.opts.greeting))
end
end)

View File

@ -20,7 +20,10 @@ local function setupOpt(name, default)
end end
local defaultOpts = { local defaultOpts = {
autocd = false autocd = false,
greeting = string.format([[Welcome to {magenta}Hilbish{reset}, {cyan}%s{reset}.
The nice lil shell for {blue}Lua{reset} fanatics!
]], hilbish.user)
} }
for optsName, default in pairs(defaultOpts) do for optsName, default in pairs(defaultOpts) do