mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "cb88db8cfcd511a87889484c4b2ba1dfb23ff2ea" and "200fe1054f0c866a69cd40ed7d275f5b3046f043" have entirely different histories.
cb88db8cfc
...
200fe1054f
7
api.go
7
api.go
|
@ -163,17 +163,12 @@ Check out the {blue}{bold}guide{reset} command to get started.
|
||||||
jobModule := jobs.loader(rtm)
|
jobModule := jobs.loader(rtm)
|
||||||
util.Document(jobModule, "(Background) job interface.")
|
util.Document(jobModule, "(Background) job interface.")
|
||||||
mod.Set(rt.StringValue("jobs"), rt.TableValue(jobModule))
|
mod.Set(rt.StringValue("jobs"), rt.TableValue(jobModule))
|
||||||
|
|
||||||
// hilbish.timers table
|
|
||||||
timers = newTimerHandler()
|
timers = newTimerHandler()
|
||||||
timerModule := timers.loader(rtm)
|
timerModule := timers.loader(rtm)
|
||||||
util.Document(timerModule, "Timer interface, for control of all intervals and timeouts.")
|
util.Document(timerModule, "Timer interface, for control of all intervals and timeouts.")
|
||||||
mod.Set(rt.StringValue("timers"), rt.TableValue(timerModule))
|
mod.Set(rt.StringValue("timers"), rt.TableValue(timerModule))
|
||||||
|
|
||||||
editorModule := editorLoader(rtm)
|
|
||||||
util.Document(editorModule, "")
|
|
||||||
mod.Set(rt.StringValue("editor"), rt.TableValue(editorModule))
|
|
||||||
|
|
||||||
return rt.TableValue(fakeMod), nil
|
return rt.TableValue(fakeMod), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
70
editor.go
70
editor.go
|
@ -1,70 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"hilbish/util"
|
|
||||||
|
|
||||||
rt "github.com/arnodel/golua/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func editorLoader(rtm *rt.Runtime) *rt.Table {
|
|
||||||
exports := map[string]util.LuaExport{
|
|
||||||
"insert": {editorInsert, 1, false},
|
|
||||||
"setVimRegister": {editorSetRegister, 1, false},
|
|
||||||
"getVimRegister": {editorGetRegister, 2, false},
|
|
||||||
}
|
|
||||||
|
|
||||||
mod := rt.NewTable()
|
|
||||||
util.SetExports(rtm, mod, exports)
|
|
||||||
|
|
||||||
return mod
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
5
exec.go
5
exec.go
|
@ -362,9 +362,12 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
|
||||||
if bg {
|
if bg {
|
||||||
j = jobs.getLatest()
|
j = jobs.getLatest()
|
||||||
j.setHandle(cmd.Process)
|
j.setHandle(cmd.Process)
|
||||||
j.start(cmd.Process.Pid)
|
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if bg {
|
||||||
|
j.start(cmd.Process.Pid)
|
||||||
|
}
|
||||||
|
|
||||||
if done := ctx.Done(); done != nil {
|
if done := ctx.Done(); done != nil {
|
||||||
go func() {
|
go func() {
|
||||||
<-done
|
<-done
|
||||||
|
|
26
job.go
26
job.go
|
@ -59,7 +59,6 @@ func (j *job) lua() rt.Value {
|
||||||
func (j *job) luaStop(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (j *job) luaStop(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if j.running {
|
if j.running {
|
||||||
j.stop()
|
j.stop()
|
||||||
j.finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Next(), nil
|
return c.Next(), nil
|
||||||
|
@ -79,19 +78,16 @@ func newJobHandler() *jobHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *jobHandler) add(cmd string) *job {
|
func (j *jobHandler) add(cmd string) {
|
||||||
j.mu.Lock()
|
j.mu.Lock()
|
||||||
defer j.mu.Unlock()
|
defer j.mu.Unlock()
|
||||||
|
|
||||||
j.latestID++
|
j.latestID++
|
||||||
jb := &job{
|
j.jobs[j.latestID] = &job{
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
running: false,
|
running: false,
|
||||||
id: j.latestID,
|
id: j.latestID,
|
||||||
}
|
}
|
||||||
j.jobs[j.latestID] = jb
|
|
||||||
|
|
||||||
return jb
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *jobHandler) getLatest() *job {
|
func (j *jobHandler) getLatest() *job {
|
||||||
|
@ -105,7 +101,6 @@ func (j *jobHandler) loader(rtm *rt.Runtime) *rt.Table {
|
||||||
jobFuncs := map[string]util.LuaExport{
|
jobFuncs := map[string]util.LuaExport{
|
||||||
"all": {j.luaAllJobs, 0, false},
|
"all": {j.luaAllJobs, 0, false},
|
||||||
"get": {j.luaGetJob, 1, false},
|
"get": {j.luaGetJob, 1, false},
|
||||||
"add": {j.luaAddJob, 1, false},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
luaJob := rt.NewTable()
|
luaJob := rt.NewTable()
|
||||||
|
@ -134,23 +129,6 @@ func (j *jobHandler) luaGetJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.PushingNext1(t.Runtime, job.lua()), nil
|
return c.PushingNext1(t.Runtime, job.lua()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *jobHandler) luaAddJob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|
||||||
j.mu.RLock()
|
|
||||||
defer j.mu.RUnlock()
|
|
||||||
|
|
||||||
if err := c.Check1Arg(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
cmd, err := c.StringArg(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
jb := j.add(cmd)
|
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, jb.lua()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *jobHandler) luaAllJobs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (j *jobHandler) luaAllJobs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
j.mu.RLock()
|
j.mu.RLock()
|
||||||
defer j.mu.RUnlock()
|
defer j.mu.RUnlock()
|
||||||
|
|
|
@ -7,7 +7,6 @@ package.path = package.path .. ';' .. hilbish.dataDir .. '/?/init.lua'
|
||||||
require 'nature.commands'
|
require 'nature.commands'
|
||||||
require 'nature.completions'
|
require 'nature.completions'
|
||||||
require 'nature.opts'
|
require 'nature.opts'
|
||||||
require 'nature.vim'
|
|
||||||
|
|
||||||
local shlvl = tonumber(os.getenv 'SHLVL')
|
local shlvl = tonumber(os.getenv 'SHLVL')
|
||||||
if shlvl ~= nil then
|
if shlvl ~= nil then
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
local vim = {}
|
|
||||||
hilbish.vim = {
|
|
||||||
registers = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
setmetatable(hilbish.vim.registers, {
|
|
||||||
__newindex = function(_, k, v)
|
|
||||||
hilbish.editor.setVimRegister(k, v)
|
|
||||||
end,
|
|
||||||
__index = function(_, k)
|
|
||||||
return hilbish.editor.getVimRegister(k)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
setmetatable(hilbish.vim, {
|
|
||||||
__index = function(_, k)
|
|
||||||
if k == 'mode' then return hilbish.vimMode end
|
|
||||||
end
|
|
||||||
})
|
|
|
@ -107,10 +107,6 @@ func (rl *Instance) insert(r []rune) {
|
||||||
rl.updateHelpers()
|
rl.updateHelpers()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Instance) Insert(t string) {
|
|
||||||
rl.insert([]rune(t))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *Instance) deleteX() {
|
func (rl *Instance) deleteX() {
|
||||||
switch {
|
switch {
|
||||||
case len(rl.line) == 0:
|
case len(rl.line) == 0:
|
||||||
|
|
|
@ -105,10 +105,7 @@ func (rl *Instance) saveToRegisterTokenize(tokeniser tokeniser, jumper func(toke
|
||||||
// let the caller pass directly this buffer, yet relying on the register system to
|
// let the caller pass directly this buffer, yet relying on the register system to
|
||||||
// determine which register will store the buffer.
|
// determine which register will store the buffer.
|
||||||
func (rl *Instance) saveBufToRegister(buffer []rune) {
|
func (rl *Instance) saveBufToRegister(buffer []rune) {
|
||||||
rl.SetRegisterBuf(string(rl.registers.currentRegister), buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *Instance) SetRegisterBuf(reg string, buffer []rune) {
|
|
||||||
// We must make an immutable version of the buffer first.
|
// We must make an immutable version of the buffer first.
|
||||||
buf := string(buffer)
|
buf := string(buffer)
|
||||||
|
|
||||||
|
@ -127,7 +124,7 @@ func (rl *Instance) SetRegisterBuf(reg string, buffer []rune) {
|
||||||
// If there is an active register, directly give it the buffer.
|
// If there is an active register, directly give it the buffer.
|
||||||
// Check if its a numbered or lettered register, and put it in.
|
// Check if its a numbered or lettered register, and put it in.
|
||||||
if rl.registers.onRegister {
|
if rl.registers.onRegister {
|
||||||
num, err := strconv.Atoi(reg)
|
num, err := strconv.Atoi(string(rl.registers.currentRegister))
|
||||||
if err == nil && num < 10 {
|
if err == nil && num < 10 {
|
||||||
rl.registers.writeNumberedRegister(num, []rune(buf), false)
|
rl.registers.writeNumberedRegister(num, []rune(buf), false)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -152,12 +149,8 @@ func (rl *Instance) pasteFromRegister() (buffer []rune) {
|
||||||
}
|
}
|
||||||
activeRegister := string(rl.registers.currentRegister)
|
activeRegister := string(rl.registers.currentRegister)
|
||||||
|
|
||||||
return rl.GetFromRegister(activeRegister)
|
// Else find the active register, and return its content.
|
||||||
}
|
num, err := strconv.Atoi(activeRegister)
|
||||||
|
|
||||||
func (rl *Instance) GetFromRegister(reg string) []rune {
|
|
||||||
// Find the active register, and return its content.
|
|
||||||
num, err := strconv.Atoi(reg)
|
|
||||||
|
|
||||||
// Either from the numbered ones.
|
// Either from the numbered ones.
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -165,20 +158,20 @@ func (rl *Instance) GetFromRegister(reg string) []rune {
|
||||||
if found {
|
if found {
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
return []rune{}
|
return
|
||||||
}
|
}
|
||||||
// or the lettered ones
|
// or the lettered ones
|
||||||
buf, found := rl.registers.alpha[reg]
|
buf, found := rl.registers.alpha[activeRegister]
|
||||||
if found {
|
if found {
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
// Or the read-only ones
|
// Or the read-only ones
|
||||||
buf, found = rl.registers.ro[reg]
|
buf, found = rl.registers.ro[activeRegister]
|
||||||
if found {
|
if found {
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
return []rune{}
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// setActiveRegister - The user has typed "<regiserID>, and we don't know yet
|
// setActiveRegister - The user has typed "<regiserID>, and we don't know yet
|
||||||
|
|
Loading…
Reference in New Issue