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{}
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 {
switch cb := args.(type) {
case func() string:
@ -51,9 +58,6 @@ func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.
}
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) {
if !kit.HasPrefixList(arg, 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:])
}
}
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 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 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"
)
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 {
case ice.RENDER_RESULT:
kit.If(len(args) > 0, func() { msg.Resultv(args) })
res = msg.Result()
kit.If(len(args) > 0, func() { m.Resultv(args) })
res = m.Result()
case ice.RENDER_VOID:
return res
default:
if res = msg.Result(); res == "" {
res = msg.TableEcho().Result()
if res = m.Result(); res == "" {
res = m.TableEchoWithStatus().Result()
}
}
if fmt.Fprint(msg.O, res); !strings.HasSuffix(res, lex.NL) {
fmt.Fprint(msg.O, lex.NL)
if fmt.Fprint(m.O, res); !strings.HasSuffix(res, lex.NL) {
fmt.Fprint(m.O, lex.NL)
}
return res
}

View File

@ -102,11 +102,11 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
return ""
}
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.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)
m.I, m.O = f.stdin, f.stdout
for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) {
if len(bio.Text()) == 0 && h == STDIO {
continue
@ -116,20 +116,16 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
line += lex.NL
ps = f.ps2
continue
}
if len(bio.Text()) == 0 {
} else if len(bio.Text()) == 0 {
continue
}
if strings.HasSuffix(bio.Text(), "\\") {
} else if strings.HasSuffix(bio.Text(), "\\") {
line += bio.Text()[:len(bio.Text())-1]
ps = f.ps2
continue
}
if strings.HasPrefix(strings.TrimSpace(line), "#") {
} else if strings.HasPrefix(strings.TrimSpace(line), "#") {
line = ""
continue
}
if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors {
} else if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors {
f.printf(m, "\033[0m")
}
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) {
switch strings.Split(os.Getenv(cli.TERM), "-")[0] {
case "xterm", "screen":
ice.Info.Colors = true
default:
ice.Info.Colors = false
}
ice.Info.Colors = kit.IsIn(strings.Split(os.Getenv(cli.TERM), "-")[0], "xterm", "screen")
}
func (f *Frame) Start(m *ice.Message, arg ...string) {
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>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 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 th { 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)
m.Assert(h != "")
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)))
} 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 {
text := strings.Split(value[mdb.TEXT], lex.NL)
@ -60,7 +60,7 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm {
}).(xterm.XTerm)
}
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)
}
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)
cn := (len(s) - len([]rune(s))) / 2
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 {
return b.GetWidth(str...) + b.MarginX

View File

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

11
meta.go
View File

@ -288,6 +288,17 @@ func (m *Message) TableEcho() *Message {
}
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 (
STR = "str"

View File

@ -276,9 +276,9 @@ func (s iterm) exec(m *ice.Message, res string) string {
res, s.pipe = "", w
env := kit.EnvList(
"TERM", "xterm",
"SHELL", "/bin/ish",
"LINES", m.Option("rows"),
"COLUMNS", m.Option("cols"),
"SHELL", "/bin/ish",
"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) {
@ -286,7 +286,7 @@ func (s iterm) exec(m *ice.Message, res string) string {
end = bytes.HasSuffix(buf, []byte(lex.NL))
}), cli.CMD_ENV, env))
} else {
kit.If(msg.Result() == "", func() { msg.TableEcho() })
kit.If(msg.Result() == "", func() { msg.TableEchoWithStatus() })
res += strings.ReplaceAll(msg.Result(), lex.NL, CRNL)
end = strings.HasSuffix(res, lex.NL)
}

View File

@ -47,7 +47,7 @@ func (m *Message) MergePod(pod string, arg ...Any) string {
ls := []string{"chat"}
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...) })
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 {
ls := []string{"chat"}