Comparar commits

..

2 Commits

Autor SHA1 Mensaje Fecha
TorchedSammy
b65acca903
fix: initialize line reader before lua init 2022-07-10 22:07:01 -04:00
TorchedSammy
08e2951513
feat: add raw input hook (closes #180) 2022-07-10 20:34:00 -04:00
Se han modificado 5 ficheros con 9 adiciones y 1 borrados

Ver fichero

@ -65,6 +65,7 @@ will be ran on startup
- Message of the day on startup (`hilbish.motd`), mainly intended as quick - Message of the day on startup (`hilbish.motd`), mainly intended as quick
small news pieces for releases. It is printed by default. To disable it, small news pieces for releases. It is printed by default. To disable it,
set `hilbish.opts.motd` to false. set `hilbish.opts.motd` to false.
- `hilbish.rawInput` hook for input from the readline library
### Changed ### Changed
- **Breaking Change:** Upgraded to Lua 5.4. - **Breaking Change:** Upgraded to Lua 5.4.

4
lua.go
Ver fichero

@ -48,6 +48,10 @@ func luaInit() {
} }
}) })
lr.rl.RawInputCallback = func(r []rune) {
hooks.Em.Emit("hilbish.rawInput", string(r))
}
// Add more paths that Lua can require from // Add more paths that Lua can require from
err := util.DoString(l, "package.path = package.path .. " + requirePaths) err := util.DoString(l, "package.path = package.path .. " + requirePaths)
if err != nil { if err != nil {

Ver fichero

@ -116,8 +116,8 @@ func main() {
} }
go handleSignals() go handleSignals()
luaInit()
lr = newLineReader("", false) lr = newLineReader("", false)
luaInit()
// If user's config doesn't exixt, // If user's config doesn't exixt,
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath { if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
// Read default from current directory // Read default from current directory

Ver fichero

@ -198,6 +198,8 @@ type Instance struct {
ViModeCallback func(ViMode) ViModeCallback func(ViMode)
ViActionCallback func(ViAction, []string) ViActionCallback func(ViAction, []string)
RawInputCallback func([]rune) // called on all input
} }
// NewInstance is used to create a readline instance and initialise it with sane defaults. // NewInstance is used to create a readline instance and initialise it with sane defaults.

Ver fichero

@ -94,6 +94,7 @@ func (rl *Instance) Readline() (string, error) {
rl.skipStdinRead = false rl.skipStdinRead = false
r := []rune(string(b)) r := []rune(string(b))
rl.RawInputCallback(r[:i])
if isMultiline(r[:i]) || len(rl.multiline) > 0 { if isMultiline(r[:i]) || len(rl.multiline) > 0 {
rl.multiline = append(rl.multiline, b[:i]...) rl.multiline = append(rl.multiline, b[:i]...)