mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "5175367b35c6581cf2594589be06f849157823d1" and "237bc19f687d6561f0c1405a9045a0b49f235f8a" have entirely different histories.
5175367b35
...
237bc19f68
18
api.go
18
api.go
|
@ -174,8 +174,10 @@ These will be formatted and replaced with the appropriate values.
|
||||||
--- @param str string
|
--- @param str string
|
||||||
*/
|
*/
|
||||||
func hlprompt(L *lua.LState) int {
|
func hlprompt(L *lua.LState) int {
|
||||||
prompt := L.CheckString(1)
|
prompt = L.CheckString(1)
|
||||||
lr.SetPrompt(fmtPrompt(prompt))
|
if lr != nil {
|
||||||
|
lr.SetPrompt(fmtPrompt())
|
||||||
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -274,13 +276,11 @@ func hlgoro(L *lua.LState) int {
|
||||||
|
|
||||||
// call fn
|
// call fn
|
||||||
go func() {
|
go func() {
|
||||||
if err := L.CallByParam(lua.P{
|
L.CallByParam(lua.P{
|
||||||
Fn: fn,
|
Fn: fn,
|
||||||
NRet: 0,
|
NRet: 0,
|
||||||
Protect: true,
|
Protect: true,
|
||||||
}, args...); err != nil {
|
}, args...)
|
||||||
fmt.Fprintln(os.Stderr, "Error in goro function:\n\n", err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -297,13 +297,11 @@ func hltimeout(L *lua.LState) int {
|
||||||
timeout := time.Duration(ms) * time.Millisecond
|
timeout := time.Duration(ms) * time.Millisecond
|
||||||
time.Sleep(timeout)
|
time.Sleep(timeout)
|
||||||
|
|
||||||
if err := L.CallByParam(lua.P{
|
L.CallByParam(lua.P{
|
||||||
Fn: cb,
|
Fn: cb,
|
||||||
NRet: 0,
|
NRet: 0,
|
||||||
Protect: true,
|
Protect: true,
|
||||||
}); err != nil {
|
})
|
||||||
fmt.Fprintln(os.Stderr, "Error in goro function:\n\n", err)
|
|
||||||
}
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
71
history.go
71
history.go
|
@ -1,71 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io/fs"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type fileHistory struct {
|
|
||||||
items []string
|
|
||||||
f *os.File
|
|
||||||
}
|
|
||||||
|
|
||||||
func newFileHistory() (*fileHistory, error) {
|
|
||||||
data, err := os.ReadFile(defaultHistPath)
|
|
||||||
if err != nil {
|
|
||||||
if !errors.Is(err, fs.ErrNotExist) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var itms []string
|
|
||||||
for _, l := range strings.Split(string(data), "\n") {
|
|
||||||
itms = append(itms, l)
|
|
||||||
}
|
|
||||||
f, err := os.OpenFile(defaultHistPath, os.O_RDWR | os.O_CREATE, 0755)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
fh := &fileHistory{
|
|
||||||
items: itms,
|
|
||||||
f: f,
|
|
||||||
}
|
|
||||||
|
|
||||||
return fh, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *fileHistory) Write(line string) (int, error) {
|
|
||||||
if line == "" {
|
|
||||||
return len(h.items), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := h.f.WriteString(line + "\n")
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
h.f.Sync()
|
|
||||||
|
|
||||||
h.items = append(h.items, line)
|
|
||||||
return len(h.items), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *fileHistory) GetLine(idx int) (string, error) {
|
|
||||||
if len(h.items) == 0 {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
if idx == -1 { // this should be fixed readline side
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
return h.items[idx], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *fileHistory) Len() int {
|
|
||||||
return len(h.items)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *fileHistory) Dump() interface{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
5
main.go
5
main.go
|
@ -114,7 +114,6 @@ func main() {
|
||||||
|
|
||||||
go handleSignals()
|
go handleSignals()
|
||||||
luaInit()
|
luaInit()
|
||||||
lr = newLineReader("")
|
|
||||||
// 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
|
||||||
|
@ -163,10 +162,12 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lr = newLineReader("")
|
||||||
input:
|
input:
|
||||||
for interactive {
|
for interactive {
|
||||||
running = false
|
running = false
|
||||||
|
|
||||||
|
lr.SetPrompt(fmtPrompt())
|
||||||
input, err := lr.Read()
|
input, err := lr.Read()
|
||||||
|
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
@ -224,7 +225,7 @@ func continuePrompt(prev string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This semi cursed function formats our prompt (obviously)
|
// This semi cursed function formats our prompt (obviously)
|
||||||
func fmtPrompt(prompt string) string {
|
func fmtPrompt() string {
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
|
|
5
rl.go
5
rl.go
|
@ -18,11 +18,6 @@ type lineReader struct {
|
||||||
// other gophers might hate this naming but this is local, shut up
|
// other gophers might hate this naming but this is local, shut up
|
||||||
func newLineReader(prompt string) *lineReader {
|
func newLineReader(prompt string) *lineReader {
|
||||||
rl := readline.NewInstance()
|
rl := readline.NewInstance()
|
||||||
fileHist, err := newFileHistory()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
rl.SetHistoryCtrlR("file", fileHist)
|
|
||||||
rl.ShowVimMode = false
|
rl.ShowVimMode = false
|
||||||
rl.ViModeCallback = func(mode readline.ViMode) {
|
rl.ViModeCallback = func(mode readline.ViMode) {
|
||||||
modeStr := ""
|
modeStr := ""
|
||||||
|
|
1
vars.go
1
vars.go
|
@ -7,6 +7,7 @@ var (
|
||||||
defaultHistDir = ""
|
defaultHistDir = ""
|
||||||
commonRequirePaths = "';./libs/?/init.lua;./?/init.lua;./?/?.lua'"
|
commonRequirePaths = "';./libs/?/init.lua;./?/init.lua;./?/?.lua'"
|
||||||
|
|
||||||
|
prompt string // Prompt will always get changed anyway
|
||||||
multilinePrompt = "> "
|
multilinePrompt = "> "
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue