Compare commits

..

No commits in common. "5175367b35c6581cf2594589be06f849157823d1" and "237bc19f687d6561f0c1405a9045a0b49f235f8a" have entirely different histories.

5 changed files with 16 additions and 92 deletions

26
api.go
View File

@ -174,8 +174,10 @@ These will be formatted and replaced with the appropriate values.
--- @param str string
*/
func hlprompt(L *lua.LState) int {
prompt := L.CheckString(1)
lr.SetPrompt(fmtPrompt(prompt))
prompt = L.CheckString(1)
if lr != nil {
lr.SetPrompt(fmtPrompt())
}
return 0
}
@ -274,13 +276,11 @@ func hlgoro(L *lua.LState) int {
// call fn
go func() {
if err := L.CallByParam(lua.P{
Fn: fn,
NRet: 0,
L.CallByParam(lua.P{
Fn: fn,
NRet: 0,
Protect: true,
}, args...); err != nil {
fmt.Fprintln(os.Stderr, "Error in goro function:\n\n", err)
}
}, args...)
}()
return 0
@ -297,13 +297,11 @@ func hltimeout(L *lua.LState) int {
timeout := time.Duration(ms) * time.Millisecond
time.Sleep(timeout)
if err := L.CallByParam(lua.P{
Fn: cb,
NRet: 0,
L.CallByParam(lua.P{
Fn: cb,
NRet: 0,
Protect: true,
}); err != nil {
fmt.Fprintln(os.Stderr, "Error in goro function:\n\n", err)
}
})
return 0
}

View File

@ -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
}

View File

@ -114,7 +114,6 @@ func main() {
go handleSignals()
luaInit()
lr = newLineReader("")
// If user's config doesn't exixt,
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
// Read default from current directory
@ -163,10 +162,12 @@ func main() {
os.Exit(0)
}
lr = newLineReader("")
input:
for interactive {
running = false
lr.SetPrompt(fmtPrompt())
input, err := lr.Read()
if err == io.EOF {
@ -224,7 +225,7 @@ func continuePrompt(prev string) (string, error) {
}
// This semi cursed function formats our prompt (obviously)
func fmtPrompt(prompt string) string {
func fmtPrompt() string {
host, _ := os.Hostname()
cwd, _ := os.Getwd()

5
rl.go
View File

@ -18,11 +18,6 @@ type lineReader struct {
// other gophers might hate this naming but this is local, shut up
func newLineReader(prompt string) *lineReader {
rl := readline.NewInstance()
fileHist, err := newFileHistory()
if err != nil {
panic(err)
}
rl.SetHistoryCtrlR("file", fileHist)
rl.ShowVimMode = false
rl.ViModeCallback = func(mode readline.ViMode) {
modeStr := ""

View File

@ -7,6 +7,7 @@ var (
defaultHistDir = ""
commonRequirePaths = "';./libs/?/init.lua;./?/init.lua;./?/?.lua'"
prompt string // Prompt will always get changed anyway
multilinePrompt = "> "
)