forked from x/icebergs
add xterm.go
This commit is contained in:
parent
3fe511f14a
commit
fa7d3d6b4e
49
core/code/xterm.go
Normal file
49
core/code/xterm.go
Normal file
@ -0,0 +1,49 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
)
|
||||
|
||||
const XTERM = "xterm"
|
||||
|
||||
func init() {
|
||||
cache := map[string]io.Writer{}
|
||||
cache1 := map[string]io.Writer{}
|
||||
|
||||
Index.MergeCommands(ice.Commands{
|
||||
XTERM: {Name: "xterm auto", Help: "终端", Actions: ice.MergeAction(ice.Actions{
|
||||
"input": {Name: "input", Help: "输入", Hand: func(m *ice.Message, arg ...string) {
|
||||
if w, ok := cache[m.Option("channel")]; ok {
|
||||
m.Debug("write %v", []byte(arg[0]))
|
||||
w.Write([]byte(arg[0]))
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
r0, w0, e0 := os.Pipe()
|
||||
m.Assert(e0)
|
||||
r1, w1, e1 := os.Pipe()
|
||||
m.Assert(e1)
|
||||
m.Option(cli.CMD_INPUT, r0)
|
||||
m.Option(cli.CMD_OUTPUT, w1)
|
||||
m.Cmd(cli.DAEMON, "bash")
|
||||
m.Go(func() {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, e := r1.Read(buf)
|
||||
m.Assert(e)
|
||||
m.Debug("what %v", string(buf[:n]))
|
||||
m.PushNotice("grow", string(buf[:n]))
|
||||
}
|
||||
})
|
||||
|
||||
cache["1"] = w0
|
||||
cache1["1"] = w1
|
||||
m.DisplayLocal("", "channel", "1")
|
||||
}},
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user