goinput
Table Of Contents
Intro
Go library for building an interface and entering user data.
License
The goinput is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3.
Learn
Module
For more information about the module, use the link.
Use
Processing user input and executing commands:
func testInput() (err error) {
var (
data = goinput.Data{
Slice: make([]byte, 32),
}
input = &goinput.Input{
Fd: syscall.Stdin,
}
sigInt = make(chan os.Signal, 1)
keys = goinput.Keys{
"a": {
EventFunc: func(key *goinput.Key) (err error) {
fmt.Println("a")
return
},
},
"c": {
EventFunc: func(key *goinput.Key) (err error) {
key.Data[0].(chan os.Signal) <- syscall.SIGINT
return
},
Data: append(make([]any, 0, 0), sigInt),
},
"1 2 3": {
EventFunc: func(key *goinput.Key) (err error) {
fmt.Println("1 2 3")
return
},
},
}
)
defer func() {
close(sigInt)
}()
if err = keys.Compile(); err != nil {
return
}
signal.Notify(sigInt, syscall.SIGINT)
for {
var (
pressedKeys = keys.PressedKeys()
pairNum = 0
)
if !input.IsRaw() {
if err = input.SetRaw(); err != nil {
return
}
}
_loop:
if err = input.Read(&data); err != nil {
return
}
for _, name := range *pressedKeys.Update(keys, data, pairNum) {
switch key := keys[name]; {
case pairNum == key.Len()-1:
if err = input.ResetRaw(); err != nil {
return
}
key.Event()
select {
case <-sigInt:
return
default:
}
case pairNum < key.Len()-1:
pairNum++
goto _loop
}
}
}
}
Start
Get
To get, execute the command:
~ $ go get -v notabug.org/_percival/goinput@latest
Update
To update, execute the command:
~ $ go get -u -v notabug.org/_percival/goinput@latest