mirror of https://github.com/Hilbis/Hilbish
refactor: move hilbish.editor function impls to readline side
parent
a5b6fc8eda
commit
fbf420a0b9
|
@ -268,7 +268,7 @@ func main() {
|
||||||
os.Mkdir("docs/api", 0777)
|
os.Mkdir("docs/api", 0777)
|
||||||
os.Mkdir("emmyLuaDocs", 0777)
|
os.Mkdir("emmyLuaDocs", 0777)
|
||||||
|
|
||||||
dirs := []string{"./"}
|
dirs := []string{"./readline", "./"}
|
||||||
filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
|
filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
return nil
|
return nil
|
||||||
|
@ -295,7 +295,7 @@ func main() {
|
||||||
pieces := []docPiece{}
|
pieces := []docPiece{}
|
||||||
typePieces := []docPiece{}
|
typePieces := []docPiece{}
|
||||||
mod := l
|
mod := l
|
||||||
if mod == "main" {
|
if mod == "main" || mod == "readline" {
|
||||||
mod = "hilbish"
|
mod = "hilbish"
|
||||||
}
|
}
|
||||||
var hasInterfaces bool
|
var hasInterfaces bool
|
||||||
|
@ -457,6 +457,9 @@ func main() {
|
||||||
htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(dps.FuncSig, "<", `\<`, -1), func(typ string) string {
|
htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(dps.FuncSig, "<", `\<`, -1), func(typ string) string {
|
||||||
typName := typ[1:]
|
typName := typ[1:]
|
||||||
typLookup := typeTable[strings.ToLower(typName)]
|
typLookup := typeTable[strings.ToLower(typName)]
|
||||||
|
if len(typLookup) == 0 {
|
||||||
|
typLookup = []string{"WHAT", "WHAT"}
|
||||||
|
}
|
||||||
ifaces := typLookup[0] + "." + typLookup[1] + "/"
|
ifaces := typLookup[0] + "." + typLookup[1] + "/"
|
||||||
if typLookup[1] == "" {
|
if typLookup[1] == "" {
|
||||||
ifaces = ""
|
ifaces = ""
|
||||||
|
|
|
@ -12,15 +12,6 @@ The hilbish.editor interface provides functions to
|
||||||
directly interact with the line editor in use.
|
directly interact with the line editor in use.
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
### getLine() -> string
|
|
||||||
Returns the current input line.
|
|
||||||
|
|
||||||
### getVimRegister(register) -> string
|
|
||||||
Returns the text that is at the register.
|
|
||||||
|
|
||||||
### insert(text)
|
### insert(text)
|
||||||
Inserts text into the line.
|
Inserts text into the line.
|
||||||
|
|
||||||
### setVimRegister(register, text)
|
|
||||||
Sets the vim register at `register` to hold the passed text.
|
|
||||||
|
|
||||||
|
|
85
editor.go
85
editor.go
|
@ -1,8 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hilbish/util"
|
|
||||||
|
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,86 +9,5 @@ import (
|
||||||
// The hilbish.editor interface provides functions to
|
// The hilbish.editor interface provides functions to
|
||||||
// directly interact with the line editor in use.
|
// directly interact with the line editor in use.
|
||||||
func editorLoader(rtm *rt.Runtime) *rt.Table {
|
func editorLoader(rtm *rt.Runtime) *rt.Table {
|
||||||
exports := map[string]util.LuaExport{
|
return lr.rl.SetupLua(rtm)
|
||||||
"insert": {editorInsert, 1, false},
|
|
||||||
"setVimRegister": {editorSetRegister, 1, false},
|
|
||||||
"getVimRegister": {editorGetRegister, 2, false},
|
|
||||||
"getLine": {editorGetLine, 0, false},
|
|
||||||
}
|
|
||||||
|
|
||||||
mod := rt.NewTable()
|
|
||||||
util.SetExports(rtm, mod, exports)
|
|
||||||
|
|
||||||
return mod
|
|
||||||
}
|
|
||||||
|
|
||||||
// #interface editor
|
|
||||||
// insert(text)
|
|
||||||
// Inserts text into the line.
|
|
||||||
func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
text, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
lr.rl.Insert(text)
|
|
||||||
|
|
||||||
return c.Next(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// #interface editor
|
|
||||||
// setVimRegister(register, text)
|
|
||||||
// Sets the vim register at `register` to hold the passed text.
|
|
||||||
// --- @param register string
|
|
||||||
// --- @param text string
|
|
||||||
func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
register, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
text, err := c.StringArg(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
lr.rl.SetRegisterBuf(register, []rune(text))
|
|
||||||
|
|
||||||
return c.Next(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// #interface editor
|
|
||||||
// getVimRegister(register) -> string
|
|
||||||
// Returns the text that is at the register.
|
|
||||||
// --- @param register string
|
|
||||||
func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
register, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := lr.rl.GetFromRegister(register)
|
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, rt.StringValue(string(buf))), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// #interface editor
|
|
||||||
// getLine() -> string
|
|
||||||
// Returns the current input line.
|
|
||||||
func editorGetLine(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
buf := lr.rl.GetLine()
|
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, rt.StringValue(string(buf))), nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
local hilbish = {}
|
local hilbish = {}
|
||||||
|
|
||||||
|
--- Inserts text into the line.
|
||||||
|
function hilbish.editor.insert(text) end
|
||||||
|
|
||||||
--- This is an alias (ha) for the `hilbish.alias` function.
|
--- This is an alias (ha) for the `hilbish.alias` function.
|
||||||
--- @param alias string
|
--- @param alias string
|
||||||
--- @param cmd string
|
--- @param cmd string
|
||||||
|
@ -30,21 +33,6 @@ function hilbish.completions.call(name, query, ctx, fields) end
|
||||||
--- @param pos string
|
--- @param pos string
|
||||||
function hilbish.completions.handler(line, pos) end
|
function hilbish.completions.handler(line, pos) end
|
||||||
|
|
||||||
--- Returns the current input line.
|
|
||||||
function hilbish.editor.getLine() end
|
|
||||||
|
|
||||||
--- Returns the text that is at the register.
|
|
||||||
--- @param register string
|
|
||||||
function hilbish.editor.getVimRegister(register) end
|
|
||||||
|
|
||||||
--- Inserts text into the line.
|
|
||||||
function hilbish.editor.insert(text) end
|
|
||||||
|
|
||||||
--- Sets the vim register at `register` to hold the passed text.
|
|
||||||
--- @param register string
|
|
||||||
--- @param text string
|
|
||||||
function hilbish.editor.setVimRegister(register, text) end
|
|
||||||
|
|
||||||
--- Sets an alias of `cmd` to `orig`
|
--- Sets an alias of `cmd` to `orig`
|
||||||
--- @param cmd string
|
--- @param cmd string
|
||||||
--- @param orig string
|
--- @param orig string
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package readline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"hilbish/util"
|
||||||
|
|
||||||
|
rt "github.com/arnodel/golua/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (rl *Instance) SetupLua(rtm *rt.Runtime) *rt.Table {
|
||||||
|
exports := map[string]util.LuaExport{
|
||||||
|
"insert": {rl.editorInsert, 1, false},
|
||||||
|
}
|
||||||
|
|
||||||
|
mod := rt.NewTable()
|
||||||
|
util.SetExports(rtm, mod, exports)
|
||||||
|
|
||||||
|
return mod
|
||||||
|
}
|
||||||
|
|
||||||
|
// #interface editor
|
||||||
|
// insert(text)
|
||||||
|
// Inserts text into the line.
|
||||||
|
func (rl *Instance) editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
text, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.Insert(text)
|
||||||
|
|
||||||
|
return c.Next(), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue