1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-07-21 15:48:55 +08:00
parent 495083a249
commit 4ef21b479e
10 changed files with 44 additions and 47 deletions

View File

@ -11,6 +11,13 @@ const PROCESS = "process"
var _process = map[string]ice.Any{} var _process = map[string]ice.Any{}
func AddProcess(key string, val ice.Any) { _process[key] = val } func AddProcess(key string, val ice.Any) { _process[key] = val }
func ProcessAction() ice.Actions {
return ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { AddProcess(m.CommandKey(), m.PrefixKey()) }},
PROCESS: {Hand: func(m *ice.Message, arg ...string) { ProcessField(m, m.PrefixKey(), arg, arg...) }},
}
}
func _process_args(m *ice.Message, args ice.Any) []string { func _process_args(m *ice.Message, args ice.Any) []string {
switch cb := args.(type) { switch cb := args.(type) {
case func() string: case func() string:
@ -51,9 +58,6 @@ func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.
} }
return m return m
} }
func ProcessFloat(m *ice.Message, arg ...string) {
m.Cmdy(COMMAND, arg[0]).Options(ice.MSG_PROCESS, ice.PROCESS_FLOAT, ice.PROCESS_ARG, arg)
}
func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) { func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) {
if !kit.HasPrefixList(arg, ice.RUN) { if !kit.HasPrefixList(arg, ice.RUN) {
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(args)).ProcessField(cmd, ice.RUN) m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(args)).ProcessField(cmd, ice.RUN)
@ -61,18 +65,8 @@ func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) {
m.Cmdy(cmd, arg[1:]) m.Cmdy(cmd, arg[1:])
} }
} }
func ProcessCmds(m *ice.Message, cmd string, arg ...string) {
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(arg)).ProcessField(ACTION, ice.RUN, cmd)
}
func ProcessRefresh(m *ice.Message, arg ...string) { m.ProcessRefresh(arg...) } func ProcessRefresh(m *ice.Message, arg ...string) { m.ProcessRefresh(arg...) }
func ProcessRewrite(m *ice.Message, arg ...ice.Any) { m.ProcessRewrite(arg...) } func ProcessRewrite(m *ice.Message, arg ...ice.Any) { m.ProcessRewrite(arg...) }
func ProcessHold(m *ice.Message, text ...ice.Any) { m.Process(ice.PROCESS_HOLD, text...) } func ProcessHold(m *ice.Message, text ...ice.Any) { m.Process(ice.PROCESS_HOLD, text...) }
func ProcessOpen(m *ice.Message, url string) { m.Process(ice.PROCESS_OPEN, url) } func ProcessOpen(m *ice.Message, url string) { m.Process(ice.PROCESS_OPEN, url) }
func ProcessAction() ice.Actions {
return ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { AddProcess(m.CommandKey(), m.PrefixKey()) }},
PROCESS: {Hand: func(m *ice.Message, arg ...string) { ProcessField(m, m.PrefixKey(), arg, arg...) }},
}
}

View File

@ -9,20 +9,20 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func Render(msg *ice.Message, cmd string, arg ...ice.Any) (res string) { func Render(m *ice.Message, cmd string, arg ...ice.Any) (res string) {
switch args := kit.Simple(arg...); cmd { switch args := kit.Simple(arg...); cmd {
case ice.RENDER_RESULT: case ice.RENDER_RESULT:
kit.If(len(args) > 0, func() { msg.Resultv(args) }) kit.If(len(args) > 0, func() { m.Resultv(args) })
res = msg.Result() res = m.Result()
case ice.RENDER_VOID: case ice.RENDER_VOID:
return res return res
default: default:
if res = msg.Result(); res == "" { if res = m.Result(); res == "" {
res = msg.TableEcho().Result() res = m.TableEchoWithStatus().Result()
} }
} }
if fmt.Fprint(msg.O, res); !strings.HasSuffix(res, lex.NL) { if fmt.Fprint(m.O, res); !strings.HasSuffix(res, lex.NL) {
fmt.Fprint(msg.O, lex.NL) fmt.Fprint(m.O, lex.NL)
} }
return res return res
} }

View File

@ -102,11 +102,11 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
return "" return ""
} }
func (f *Frame) scan(m *ice.Message, h, line string) *Frame { func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
// kit.If(f.source == STDIO, func() { m.Options(MESSAGE, m, ice.LOG_DISABLE, ice.TRUE) }) kit.If(f.source == STDIO, func() { m.Option(ice.LOG_DISABLE, ice.TRUE) })
f.ps1 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS1))) f.ps1 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS1)))
f.ps2 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS2))) f.ps2 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS2)))
m.I, m.O = f.stdin, f.stdout
ps, bio := f.ps1, bufio.NewScanner(f.stdin) ps, bio := f.ps1, bufio.NewScanner(f.stdin)
m.I, m.O = f.stdin, f.stdout
for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) { for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) {
if len(bio.Text()) == 0 && h == STDIO { if len(bio.Text()) == 0 && h == STDIO {
continue continue
@ -116,20 +116,16 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
line += lex.NL line += lex.NL
ps = f.ps2 ps = f.ps2
continue continue
} } else if len(bio.Text()) == 0 {
if len(bio.Text()) == 0 {
continue continue
} } else if strings.HasSuffix(bio.Text(), "\\") {
if strings.HasSuffix(bio.Text(), "\\") {
line += bio.Text()[:len(bio.Text())-1] line += bio.Text()[:len(bio.Text())-1]
ps = f.ps2 ps = f.ps2
continue continue
} } else if strings.HasPrefix(strings.TrimSpace(line), "#") {
if strings.HasPrefix(strings.TrimSpace(line), "#") {
line = "" line = ""
continue continue
} } else if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors {
if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors {
f.printf(m, "\033[0m") f.printf(m, "\033[0m")
} }
line = f.parse(m, h, line) line = f.parse(m, h, line)
@ -138,12 +134,7 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
} }
func (f *Frame) Begin(m *ice.Message, arg ...string) { func (f *Frame) Begin(m *ice.Message, arg ...string) {
switch strings.Split(os.Getenv(cli.TERM), "-")[0] { ice.Info.Colors = kit.IsIn(strings.Split(os.Getenv(cli.TERM), "-")[0], "xterm", "screen")
case "xterm", "screen":
ice.Info.Colors = true
default:
ice.Info.Colors = false
}
} }
func (f *Frame) Start(m *ice.Message, arg ...string) { func (f *Frame) Start(m *ice.Message, arg ...string) {
m.Optionv(FRAME, f) m.Optionv(FRAME, f)

View File

@ -23,6 +23,7 @@ fieldset.macos.desktop>div.output>div.desktop>div.item:hover { background-color:
fieldset.macos.desktop>div.output>div.desktop>div.item img { width:80px; border-radius:80px; } fieldset.macos.desktop>div.output>div.desktop>div.item img { width:80px; border-radius:80px; }
fieldset.macos.desktop>div.output>div.desktop>div.item>div.name { font-size:12px; width:80px; overflow:hidden; } fieldset.macos.desktop>div.output>div.desktop>div.item>div.name { font-size:12px; width:80px; overflow:hidden; }
fieldset.macos.desktop>div.output>div.desktop>fieldset { border-radius:10px; position:absolute; } fieldset.macos.desktop>div.output>div.desktop>fieldset { border-radius:10px; position:absolute; }
fieldset.macos.desktop>div.output>div.desktop>fieldset input:not([type=button]) {width: 150px;}
fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content { width:100%; } fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content { width:100%; }
fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content th { padding:10px; } fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content th { padding:10px; }
fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content td { padding:10px; } fieldset.macos.desktop>div.output>div.desktop>fieldset>div.output>table.content td { padding:10px; }

View File

@ -22,9 +22,9 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm {
h = kit.Select(m.Option(mdb.HASH), h) h = kit.Select(m.Option(mdb.HASH), h)
m.Assert(h != "") m.Assert(h != "")
if m.Option(ice.MSG_USERPOD) == "" { if m.Option(ice.MSG_USERPOD) == "" {
mdb.HashModify(m, mdb.TIME, m.Time(), cli.DAEMON, kit.Keys(m.Option("__target"), m.Option(ice.MSG_DAEMON)))
} else {
mdb.HashModify(m, mdb.TIME, m.Time(), cli.DAEMON, kit.Keys(m.Option(ice.MSG_DAEMON))) mdb.HashModify(m, mdb.TIME, m.Time(), cli.DAEMON, kit.Keys(m.Option(ice.MSG_DAEMON)))
} else {
mdb.HashModify(m, mdb.TIME, m.Time(), cli.DAEMON, kit.Keys(kit.Slice(kit.Simple(m.Optionv("__target")), 0, -1), m.Option(ice.MSG_DAEMON)))
} }
return mdb.HashSelectTarget(m, h, func(value ice.Maps) ice.Any { return mdb.HashSelectTarget(m, h, func(value ice.Maps) ice.Any {
text := strings.Split(value[mdb.TEXT], lex.NL) text := strings.Split(value[mdb.TEXT], lex.NL)
@ -60,7 +60,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm {
}).(xterm.XTerm) }).(xterm.XTerm)
} }
func _xterm_echo(m *ice.Message, h string, str string) { func _xterm_echo(m *ice.Message, h string, str string) {
m.Options(ice.MSG_DAEMON, mdb.HashSelectField(m, h, cli.DAEMON)) m.Options(ice.LOG_DISABLE, ice.TRUE, "__target", "", ice.MSG_DAEMON, mdb.HashSelectField(m, h, cli.DAEMON))
web.PushNoticeGrow(m, h, str) web.PushNoticeGrow(m, h, str)
} }
func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) { func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) {

View File

@ -79,7 +79,7 @@ func (b *Block) GetWidth(str ...string) int {
s := kit.Select(b.Text, str, 0) s := kit.Select(b.Text, str, 0)
cn := (len(s) - len([]rune(s))) / 2 cn := (len(s) - len([]rune(s))) / 2
en := len([]rune(s)) - cn en := len([]rune(s)) - cn
return cn*b.FontSize + en*b.FontSize*10/16 + b.Padding return cn*b.FontSize + en*b.FontSize*12/16 + b.Padding
} }
func (b *Block) GetWidths(str ...string) int { func (b *Block) GetWidths(str ...string) int {
return b.GetWidth(str...) + b.MarginX return b.GetWidth(str...) + b.MarginX

View File

@ -89,10 +89,10 @@ const CHAIN = "chain"
func init() { func init() {
wiki.AddChart(CHAIN, func(m *ice.Message) wiki.Chart { wiki.AddChart(CHAIN, func(m *ice.Message) wiki.Chart {
m.Option(wiki.FONT_SIZE, "18") m.OptionDefault(wiki.FONT_SIZE, "18")
m.Option(wiki.MARGINX, "60") m.OptionDefault(wiki.MARGINX, "60")
m.Option(wiki.MARGINY, "16") m.OptionDefault(wiki.MARGINY, "16")
m.Option(wiki.PADDING, "10") m.OptionDefault(wiki.PADDING, "10")
wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS) wiki.AddGroupOption(m, SHIP, wiki.FILL, cli.GLASS)
return &Chain{} return &Chain{}
}) })

11
meta.go
View File

@ -288,6 +288,17 @@ func (m *Message) TableEcho() *Message {
} }
return m return m
} }
func (m *Message) TableEchoWithStatus() *Message {
m.TableEcho()
list := []string{}
kit.For(kit.UnMarshal(m.Option(MSG_STATUS)), func(index int, value Map) {
list = append(list, kit.Format("%s: %s", value[NAME], value[VALUE]))
})
if len(list) > 0 {
m.Echo(strings.Join(list, SP)).Echo(NL)
}
return m
}
const ( const (
STR = "str" STR = "str"

View File

@ -276,9 +276,9 @@ func (s iterm) exec(m *ice.Message, res string) string {
res, s.pipe = "", w res, s.pipe = "", w
env := kit.EnvList( env := kit.EnvList(
"TERM", "xterm", "TERM", "xterm",
"SHELL", "/bin/ish",
"LINES", m.Option("rows"), "LINES", m.Option("rows"),
"COLUMNS", m.Option("cols"), "COLUMNS", m.Option("cols"),
"SHELL", "/bin/ish",
"USER", m.Option(ice.MSG_USERNAME), "USER", m.Option(ice.MSG_USERNAME),
) )
m.Cmd(cli.SYSTEM, arg, kit.Dict(cli.CMD_INPUT, r, cli.CMD_OUTPUT, nfs.Pipe(m, func(buf []byte) { m.Cmd(cli.SYSTEM, arg, kit.Dict(cli.CMD_INPUT, r, cli.CMD_OUTPUT, nfs.Pipe(m, func(buf []byte) {
@ -286,7 +286,7 @@ func (s iterm) exec(m *ice.Message, res string) string {
end = bytes.HasSuffix(buf, []byte(lex.NL)) end = bytes.HasSuffix(buf, []byte(lex.NL))
}), cli.CMD_ENV, env)) }), cli.CMD_ENV, env))
} else { } else {
kit.If(msg.Result() == "", func() { msg.TableEcho() }) kit.If(msg.Result() == "", func() { msg.TableEchoWithStatus() })
res += strings.ReplaceAll(msg.Result(), lex.NL, CRNL) res += strings.ReplaceAll(msg.Result(), lex.NL, CRNL)
end = strings.HasSuffix(res, lex.NL) end = strings.HasSuffix(res, lex.NL)
} }

View File

@ -47,7 +47,7 @@ func (m *Message) MergePod(pod string, arg ...Any) string {
ls := []string{"chat"} ls := []string{"chat"}
kit.If(kit.Keys(m.Option(MSG_USERPOD), pod), func(p string) { ls = append(ls, POD, p) }) kit.If(kit.Keys(m.Option(MSG_USERPOD), pod), func(p string) { ls = append(ls, POD, p) })
kit.If(m.Option(DEBUG) == TRUE, func() { arg = append([]Any{DEBUG, TRUE}, arg...) }) kit.If(m.Option(DEBUG) == TRUE, func() { arg = append([]Any{DEBUG, TRUE}, arg...) })
return kit.MergeURL2(strings.Split(kit.Select(Info.Domain, m.Option(MSG_USERWEB)), QS)[0], PS+kit.Join(ls, PS), arg...) return kit.MergeURL2(strings.Split(kit.Select("http://localhost:9020", Info.Domain, m.Option(MSG_USERWEB)), QS)[0], PS+kit.Join(ls, PS), arg...)
} }
func (m *Message) MergePodCmd(pod, cmd string, arg ...Any) string { func (m *Message) MergePodCmd(pod, cmd string, arg ...Any) string {
ls := []string{"chat"} ls := []string{"chat"}