mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "5c6310b1ca7bdfce23dfcffc00fedee355a35a03" and "51b1219003acaaa515f5b105476c35a4d011f32b" have entirely different histories.
5c6310b1ca
...
51b1219003
16
go.mod
16
go.mod
|
@ -3,22 +3,16 @@ module hilbish
|
|||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/Rosettea/Hilbiline v0.0.0-20210624011007-8088a2d84b65
|
||||
github.com/Rosettea/readline v0.0.0-20211206201906-5570232ed3b3
|
||||
github.com/Rosettea/Hilbiline v0.0.0-20210603231612-80054dac3650
|
||||
github.com/Rosettea/readline v0.0.0-20211122152601-6d95ce44b7ed
|
||||
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e
|
||||
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9
|
||||
github.com/creack/goselect v0.1.2 // indirect
|
||||
github.com/creack/termios v0.0.0-20160714173321-88d0029e36a1 // indirect
|
||||
github.com/kr/pty v1.1.8 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/pborman/ansi v1.0.0 // indirect
|
||||
github.com/pborman/getopt v1.1.0
|
||||
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9
|
||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||
layeh.com/gopher-luar v1.0.10
|
||||
mvdan.cc/sh/v3 v3.4.1
|
||||
golang.org/x/term v0.0.0-20210916214954-140adaaadfaf
|
||||
layeh.com/gopher-luar v1.0.8
|
||||
mvdan.cc/sh/v3 v3.3.0
|
||||
)
|
||||
|
||||
replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5
|
||||
|
|
25
go.sum
25
go.sum
|
@ -1,13 +1,7 @@
|
|||
github.com/Rosettea/Hilbiline v0.0.0-20210603231612-80054dac3650 h1:nzFJUdJU8UJ1DA8mSQp4eoBtQyOJyecekVWusjfQsqE=
|
||||
github.com/Rosettea/Hilbiline v0.0.0-20210603231612-80054dac3650/go.mod h1:/FFZ4cgR6TXXYaskRUxyLIYdfG0PS4BPtWjWRQms754=
|
||||
github.com/Rosettea/Hilbiline v0.0.0-20210624011007-8088a2d84b65 h1:z6alP313nLg1U/V3bKSd6849L/A2LxDSwKv4CPqqzDk=
|
||||
github.com/Rosettea/Hilbiline v0.0.0-20210624011007-8088a2d84b65/go.mod h1:/FFZ4cgR6TXXYaskRUxyLIYdfG0PS4BPtWjWRQms754=
|
||||
github.com/Rosettea/Hilbiline v0.0.0-20210710124707-aa6e3ff34cb2 h1:6f1umn6mkodpGf6rK9LZjr4Gut2uS+b8QLoFBFTeOE8=
|
||||
github.com/Rosettea/Hilbiline v0.0.0-20210710124707-aa6e3ff34cb2/go.mod h1:0J2+sRC+d4a3swcH20sVlFvYUEXASvGTHJnVTTI4S9w=
|
||||
github.com/Rosettea/readline v0.0.0-20211122152601-6d95ce44b7ed h1:sGsGPG+b5h9OR1GjM0PiM4iemB9hmi0o8cg2YRSRKko=
|
||||
github.com/Rosettea/readline v0.0.0-20211122152601-6d95ce44b7ed/go.mod h1:OH+WJSCks0t2ISvaCFUT4ZxNGr4Etq4ju9JE/UxH/5o=
|
||||
github.com/Rosettea/readline v0.0.0-20211206201906-5570232ed3b3 h1:y+BeaQipF8CuIIkIjvGO7TWlA03t9Nlq+m+cSwXEJ7I=
|
||||
github.com/Rosettea/readline v0.0.0-20211206201906-5570232ed3b3/go.mod h1:OH+WJSCks0t2ISvaCFUT4ZxNGr4Etq4ju9JE/UxH/5o=
|
||||
github.com/Rosettea/sh/v3 v3.3.0 h1:0/xmOfzpy46gB1I2oPj8QwdYvyJzpdF5STcgNPRQHcI=
|
||||
github.com/Rosettea/sh/v3 v3.3.0/go.mod h1:dh3avhLDhJJ/MJKzbak6FYn+DJKUWk7Fb6Dh5mGdv6Y=
|
||||
github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5 h1:ygwVRX8gf5MHA0VzSgOdscCEoAJLjM8joEotfQPgAd0=
|
||||
|
@ -19,15 +13,10 @@ github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9/go.mod h1:2w
|
|||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
|
||||
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
|
||||
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/creack/pty v1.1.15/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
|
||||
github.com/creack/termios v0.0.0-20160714173321-88d0029e36a1 h1:3ZFknr3UZk2E18CuCeA0NMRk226zM/slMEFOmJTtJjI=
|
||||
github.com/creack/termios v0.0.0-20160714173321-88d0029e36a1/go.mod h1:141QqpYDZtzU1VJMRHPU6ZWkn9K5cE6X8elajH9hJk4=
|
||||
github.com/google/renameio v1.0.1-0.20210406141108-81588dbe0453/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
|
||||
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
|
@ -35,18 +24,12 @@ github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
|||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/pborman/ansi v1.0.0 h1:OqjHMhvlSuCCV5JT07yqPuJPQzQl+WXsiZ14gZsqOrQ=
|
||||
github.com/pborman/ansi v1.0.0/go.mod h1:SgWzwMAx1X/Ez7i90VqF8LRiQtx52pWDiQP+x3iGnzw=
|
||||
github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0=
|
||||
github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
|
@ -62,31 +45,23 @@ github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9/go.mod h1:E1AXubJB
|
|||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I=
|
||||
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210925032602-92d5a993a665 h1:QOQNt6vCjMpXE7JSK5VvAzJC1byuN3FgTNSBwf+CJgI=
|
||||
golang.org/x/sys v0.0.0-20210925032602-92d5a993a665/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E=
|
||||
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20210406210042-72f3dc4e9b72/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
|
||||
golang.org/x/term v0.0.0-20210916214954-140adaaadfaf h1:Ihq/mm/suC88gF8WFcVwk+OV6Tq+wyA1O0E5UEvDglI=
|
||||
golang.org/x/term v0.0.0-20210916214954-140adaaadfaf/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
layeh.com/gopher-luar v1.0.8 h1:Uqws1Z6T0vK6pZ7ehNNurLLSFcz7+E0EOHVM4FNiMQs=
|
||||
layeh.com/gopher-luar v1.0.8/go.mod h1:TPnIVCZ2RJBndm7ohXyaqfhzjlZ+OA2SZR/YwL8tECk=
|
||||
layeh.com/gopher-luar v1.0.10 h1:55b0mpBhN9XSshEd2Nz6WsbYXctyBT35azk4POQNSXo=
|
||||
layeh.com/gopher-luar v1.0.10/go.mod h1:TPnIVCZ2RJBndm7ohXyaqfhzjlZ+OA2SZR/YwL8tECk=
|
||||
mvdan.cc/editorconfig v0.2.0/go.mod h1:lvnnD3BNdBYkhq+B4uBuFFKatfp02eB6HixDvEz91C0=
|
||||
mvdan.cc/sh/v3 v3.3.0 h1:ujzElMnry63f4I5sjPFxzo6xia+gwsHZM0yyauuyZ6k=
|
||||
mvdan.cc/sh/v3 v3.3.0/go.mod h1:dh3avhLDhJJ/MJKzbak6FYn+DJKUWk7Fb6Dh5mGdv6Y=
|
||||
|
|
|
@ -22,7 +22,7 @@ var exports = map[string]lua.LGFunction {
|
|||
"read": hlread,
|
||||
}
|
||||
|
||||
func hilbishLoader(L *lua.LState) int {
|
||||
func HilbishLoader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
|
||||
host, _ := os.Hostname()
|
||||
|
@ -103,7 +103,7 @@ func getenv(key, fallback string) string {
|
|||
// Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
||||
func hlread(L *lua.LState) int {
|
||||
luaprompt := L.CheckString(1)
|
||||
lualr := newLineReader(luaprompt)
|
||||
lualr := NewLineReader(luaprompt)
|
||||
|
||||
input, err := lualr.Read()
|
||||
if err != nil {
|
||||
|
|
6
lua.go
6
lua.go
|
@ -34,7 +34,7 @@ func LuaInit() {
|
|||
l.SetGlobal("interval", l.NewFunction(hshinterval))
|
||||
|
||||
// yes this is stupid, i know
|
||||
l.PreloadModule("hilbish", hilbishLoader)
|
||||
l.PreloadModule("hilbish", HilbishLoader)
|
||||
l.DoString("hilbish = require 'hilbish'")
|
||||
|
||||
// Add fs and terminal module module to Lua
|
||||
|
@ -75,7 +75,7 @@ func LuaInit() {
|
|||
}
|
||||
}
|
||||
}
|
||||
func runConfig(confpath string) {
|
||||
func RunConfig(confpath string) {
|
||||
if !interactive {
|
||||
return
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ func runConfig(confpath string) {
|
|||
}
|
||||
}
|
||||
|
||||
func runLogin() {
|
||||
func RunLogin() {
|
||||
if _, err := os.Stat(curuser.HomeDir + "/.hprofile.lua"); os.IsNotExist(err) {
|
||||
return
|
||||
}
|
||||
|
|
43
main.go
43
main.go
|
@ -17,11 +17,12 @@ import (
|
|||
"github.com/pborman/getopt"
|
||||
"github.com/yuin/gopher-lua"
|
||||
"golang.org/x/term"
|
||||
"layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
var (
|
||||
l *lua.LState
|
||||
lr *lineReader
|
||||
lr *LineReader
|
||||
|
||||
commands = map[string]*lua.LFunction{}
|
||||
aliases = map[string]string{}
|
||||
|
@ -47,7 +48,7 @@ func main() {
|
|||
if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) {
|
||||
defaultConfPath = filepath.Join(homedir, "/.hilbishrc.lua")
|
||||
} else {
|
||||
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua")
|
||||
defaultConfPath = filepath.Join(confDir, "hilbish", "hilbishrc.lua")
|
||||
}
|
||||
} else {
|
||||
// else do ~ substitution
|
||||
|
@ -138,29 +139,26 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
go handleSignals()
|
||||
go HandleSignals()
|
||||
LuaInit()
|
||||
runLogin()
|
||||
runConfig(*configflag)
|
||||
RunLogin()
|
||||
RunConfig(*configflag)
|
||||
|
||||
lr = NewLineReader("")
|
||||
|
||||
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
|
||||
scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
|
||||
for scanner.Scan() {
|
||||
runInput(scanner.Text())
|
||||
RunInput(scanner.Text())
|
||||
}
|
||||
}
|
||||
|
||||
if *cmdflag != "" {
|
||||
runInput(*cmdflag)
|
||||
RunInput(*cmdflag)
|
||||
}
|
||||
|
||||
if getopt.NArgs() > 0 {
|
||||
luaArgs := l.NewTable()
|
||||
for _, arg := range getopt.Args() {
|
||||
luaArgs.Append(lua.LString(arg))
|
||||
}
|
||||
|
||||
l.SetGlobal("args", luaArgs)
|
||||
l.SetGlobal("args", luar.New(l, getopt.Args()))
|
||||
err := l.DoFile(getopt.Arg(0))
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
|
@ -169,7 +167,6 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
lr = newLineReader("")
|
||||
input:
|
||||
for interactive {
|
||||
running = false
|
||||
|
@ -194,7 +191,7 @@ input:
|
|||
|
||||
if strings.HasSuffix(input, "\\") {
|
||||
for {
|
||||
input, err = continuePrompt(strings.TrimSuffix(input, "\\"))
|
||||
input, err = ContinuePrompt(strings.TrimSuffix(input, "\\"))
|
||||
if err != nil {
|
||||
goto input // continue inside nested loop
|
||||
}
|
||||
|
@ -203,8 +200,9 @@ input:
|
|||
}
|
||||
}
|
||||
}
|
||||
handleHistory(input)
|
||||
runInput(input)
|
||||
running = true
|
||||
HandleHistory(input)
|
||||
RunInput(input)
|
||||
|
||||
termwidth, _, err := term.GetSize(0)
|
||||
if err != nil {
|
||||
|
@ -214,7 +212,7 @@ input:
|
|||
}
|
||||
}
|
||||
|
||||
func continuePrompt(prev string) (string, error) {
|
||||
func ContinuePrompt(prev string) (string, error) {
|
||||
hooks.Em.Emit("multiline", nil)
|
||||
lr.SetPrompt(multilinePrompt)
|
||||
cont, err := lr.Read()
|
||||
|
@ -259,7 +257,8 @@ func fmtPrompt() string {
|
|||
return nprompt
|
||||
}
|
||||
|
||||
func handleSignals() {
|
||||
// do i even have to say
|
||||
func HandleSignals() {
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGWINCH)
|
||||
|
||||
|
@ -267,19 +266,19 @@ func handleSignals() {
|
|||
switch s {
|
||||
case os.Interrupt:
|
||||
hooks.Em.Emit("signals.sigint")
|
||||
if !running && interactive {
|
||||
if !running {
|
||||
lr.ClearInput()
|
||||
}
|
||||
case syscall.SIGWINCH:
|
||||
hooks.Em.Emit("signals.resize")
|
||||
if !running && interactive {
|
||||
if !running {
|
||||
lr.Resize()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleHistory(cmd string) {
|
||||
func HandleHistory(cmd string) {
|
||||
lr.AddHistory(cmd)
|
||||
// TODO: load history again (history shared between sessions like this ye)
|
||||
}
|
||||
|
|
18
rl.go
18
rl.go
|
@ -16,13 +16,11 @@ import (
|
|||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
type lineReader struct {
|
||||
type LineReader struct {
|
||||
Prompt string
|
||||
}
|
||||
|
||||
func newLineReader(prompt string) *lineReader {
|
||||
readline.Init()
|
||||
|
||||
func NewLineReader(prompt string) *LineReader {
|
||||
readline.Completer = func(query string, ctx string) []string {
|
||||
var completions []string
|
||||
// trim whitespace from ctx
|
||||
|
@ -154,30 +152,30 @@ func newLineReader(prompt string) *lineReader {
|
|||
}
|
||||
readline.LoadHistory(defaultHistPath)
|
||||
|
||||
return &lineReader{
|
||||
return &LineReader{
|
||||
Prompt: prompt,
|
||||
}
|
||||
}
|
||||
|
||||
func (lr *lineReader) Read() (string, error) {
|
||||
func (lr *LineReader) Read() (string, error) {
|
||||
hooks.Em.Emit("command.precmd", nil)
|
||||
return readline.String(lr.Prompt)
|
||||
}
|
||||
|
||||
func (lr *lineReader) SetPrompt(prompt string) {
|
||||
func (lr *LineReader) SetPrompt(prompt string) {
|
||||
lr.Prompt = prompt
|
||||
}
|
||||
|
||||
func (lr *lineReader) AddHistory(cmd string) {
|
||||
func (lr *LineReader) AddHistory(cmd string) {
|
||||
readline.AddHistory(cmd)
|
||||
readline.SaveHistory(defaultHistPath)
|
||||
}
|
||||
|
||||
func (lr *lineReader) ClearInput() {
|
||||
func (lr *LineReader) ClearInput() {
|
||||
readline.ReplaceLine("", 0)
|
||||
readline.RefreshLine()
|
||||
}
|
||||
|
||||
func (lr *lineReader) Resize() {
|
||||
func (lr *LineReader) Resize() {
|
||||
readline.Resize()
|
||||
}
|
||||
|
|
|
@ -8,36 +8,36 @@ package main
|
|||
|
||||
import "github.com/Rosettea/Hilbiline"
|
||||
|
||||
type lineReader struct {
|
||||
type LineReader struct {
|
||||
hl *hilbiline.HilbilineState
|
||||
}
|
||||
|
||||
// other gophers might hate this naming but this is local, shut up
|
||||
func newLineReader(prompt string) *lineReader {
|
||||
func NewLineReader(prompt string) *LineReader {
|
||||
hl := hilbiline.New(prompt)
|
||||
|
||||
return &lineReader{
|
||||
return &LineReader{
|
||||
&hl,
|
||||
}
|
||||
}
|
||||
|
||||
func (lr *lineReader) Read() (string, error) {
|
||||
func (lr *LineReader) Read() (string, error) {
|
||||
return lr.hl.Read()
|
||||
}
|
||||
|
||||
func (lr *lineReader) SetPrompt(prompt string) {
|
||||
func (lr *LineReader) SetPrompt(prompt string) {
|
||||
lr.hl.SetPrompt(prompt)
|
||||
}
|
||||
|
||||
func (lr *lineReader) AddHistory(cmd string) {
|
||||
func (lr *LineReader) AddHistory(cmd string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (lr *lineReader) ClearInput() {
|
||||
func (lr *LineReader) ClearInput() {
|
||||
return
|
||||
}
|
||||
|
||||
func (lr *lineReader) Resize() {
|
||||
func (lr *LineReader) Resize() {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
5
shell.go
5
shell.go
|
@ -14,8 +14,7 @@ import (
|
|||
"mvdan.cc/sh/v3/syntax"
|
||||
)
|
||||
|
||||
func runInput(input string) {
|
||||
running = true
|
||||
func RunInput(input string) {
|
||||
cmdArgs, cmdString := splitInput(input)
|
||||
|
||||
// If alias was found, use command alias
|
||||
|
@ -61,7 +60,7 @@ func runInput(input string) {
|
|||
// If input is incomplete, start multiline prompting
|
||||
if syntax.IsIncomplete(err) {
|
||||
for {
|
||||
cmdString, err = continuePrompt(strings.TrimSuffix(cmdString, "\\"))
|
||||
cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\"))
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue