1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-28 10:12:02 +08:00
This commit is contained in:
shylinux@163.com 2022-08-30 07:20:34 +08:00
parent cab4df37b9
commit 0ead20ce3b
5 changed files with 44 additions and 28 deletions

View File

@ -67,26 +67,6 @@ func _system_out(m *ice.Message, out string) io.Writer {
} }
return nil return nil
} }
func _system_find(m *ice.Message, bin string, dir ...string) string {
if strings.Contains(bin, ice.DF) {
return bin
}
if strings.HasPrefix(bin, ice.PS) {
return bin
}
if strings.HasPrefix(bin, nfs.PWD) {
return bin
}
if len(dir) == 0 {
dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...)
}
for _, p := range dir {
if nfs.ExistsFile(m, path.Join(p, bin)) {
return kit.Path(p, bin)
}
}
return ""
}
func _system_exec(m *ice.Message, cmd *exec.Cmd) { func _system_exec(m *ice.Message, cmd *exec.Cmd) {
if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok { if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok {
cmd.Stdin = r // 输入流 cmd.Stdin = r // 输入流
@ -115,6 +95,26 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
} }
m.Push(mdb.TIME, m.Time()).Push(CODE, int(cmd.ProcessState.ExitCode())) m.Push(mdb.TIME, m.Time()).Push(CODE, int(cmd.ProcessState.ExitCode()))
} }
func _system_find(m Message, bin string, dir ...string) string {
if strings.Contains(bin, ice.DF) {
return bin
}
if strings.HasPrefix(bin, ice.PS) {
return bin
}
if strings.HasPrefix(bin, nfs.PWD) {
return bin
}
if len(dir) == 0 {
dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...)
}
for _, p := range dir {
if nfs.ExistsFile(m, path.Join(p, bin)) {
return kit.Path(p, bin)
}
}
return ""
}
const ( const (
CMD_DIR = "cmd_dir" CMD_DIR = "cmd_dir"
@ -156,10 +156,15 @@ func init() {
}) })
} }
func IsSuccess(m *ice.Message) bool { type Message interface {
Append(key string, arg ...ice.Any) string
Optionv(key string, arg ...ice.Any) ice.Any
}
func IsSuccess(m Message) bool {
return m.Append(CODE) == "0" || m.Append(CODE) == "" return m.Append(CODE) == "0" || m.Append(CODE) == ""
} }
func SystemFind(m *ice.Message, bin string, dir ...string) string { func SystemFind(m Message, bin string, dir ...string) string {
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 { if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
dir = append(dir, strings.Split(text, ice.NL)...) dir = append(dir, strings.Split(text, ice.NL)...)
} }

View File

@ -71,7 +71,7 @@ var DiskFile = file.NewDiskFile()
func init() { file.Init(OptionFiles(ice.Pulse, DiskFile, PackFile)) } func init() { file.Init(OptionFiles(ice.Pulse, DiskFile, PackFile)) }
func OptionFiles(m *ice.Message, f ...file.File) file.File { func OptionFiles(m Message, f ...file.File) file.File {
if len(f) > 1 { if len(f) > 1 {
m.Optionv(ice.MSG_FILES, file.NewMultiFile(f...)) m.Optionv(ice.MSG_FILES, file.NewMultiFile(f...))
} else if len(f) > 0 { } else if len(f) > 0 {
@ -79,10 +79,10 @@ func OptionFiles(m *ice.Message, f ...file.File) file.File {
} }
return m.Optionv(ice.MSG_FILES).(file.File) return m.Optionv(ice.MSG_FILES).(file.File)
} }
func StatFile(m *ice.Message, p string) (os.FileInfo, error) { func StatFile(m Message, p string) (os.FileInfo, error) {
return OptionFiles(m).StatFile(p) return OptionFiles(m).StatFile(p)
} }
func OpenFile(m *ice.Message, p string) (io.ReadCloser, error) { func OpenFile(m Message, p string) (io.ReadCloser, error) {
return OptionFiles(m).OpenFile(p) return OptionFiles(m).OpenFile(p)
} }
func CreateFile(m *ice.Message, p string) (io.WriteCloser, string, error) { func CreateFile(m *ice.Message, p string) (io.WriteCloser, string, error) {
@ -127,7 +127,11 @@ func Link(m *ice.Message, oldname string, newname string) error {
return OptionFiles(m).Link(oldname, newname) return OptionFiles(m).Link(oldname, newname)
} }
func ExistsFile(m *ice.Message, p string) bool { type Message interface {
Optionv(key string, arg ...ice.Any) ice.Any
}
func ExistsFile(m Message, p string) bool {
if _, e := OptionFiles(m).StatFile(p); e == nil { if _, e := OptionFiles(m).StatFile(p); e == nil {
return true return true
} }

View File

@ -173,6 +173,9 @@ func init() {
_inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg)) _inner_make(m, m.Cmd(cli.SYSTEM, cli.MAKE, arg))
}}, }},
FAVOR: {Name: "favor", Help: "收藏"}, FAVOR: {Name: "favor", Help: "收藏"},
"man": {Name: "man", Help: "手册", Hand: func(m *ice.Message, arg ...string) {
m.Result(kit.Split(arg[0]))
}},
}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { }, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
if arg[0] = strings.Split(arg[0], ice.FS)[0]; !strings.HasSuffix(arg[0], ice.PS) { if arg[0] = strings.Split(arg[0], ice.FS)[0]; !strings.HasSuffix(arg[0], ice.PS) {
arg[1] = kit.Slice(strings.Split(arg[0], ice.PS), -1)[0] arg[1] = kit.Slice(strings.Split(arg[0], ice.PS), -1)[0]

View File

@ -151,7 +151,7 @@ func _chart_show(m *ice.Message, kind, text string, arg ...string) {
m.Option(HEIGHT, chart.GetHeight()) m.Option(HEIGHT, chart.GetHeight())
// 渲染引擎 // 渲染引擎
_wiki_template(m, CHART, "", text) _wiki_template(m, CHART, "", text, arg...)
defer m.Echo("</svg>") defer m.Echo("</svg>")
chart.Draw(m, 0, 0) chart.Draw(m, 0, 0)
m.RenderResult() m.RenderResult()
@ -191,7 +191,7 @@ func init() {
}, Configs: ice.Configs{ }, Configs: ice.Configs{
CHART: {Name: CHART, Help: "图表", Value: kit.Data( CHART: {Name: CHART, Help: "图表", Value: kit.Data(
nfs.TEMPLATE, `<svg xmlns="http://www.w3.org/2000/svg" vertion="1.1" nfs.TEMPLATE, `<svg xmlns="http://www.w3.org/2000/svg" vertion="1.1"
{{.OptionTemplate}} height="{{.Option "height"}}" width="{{.Option "width"}}" {{.OptionTemplate}} data-index="{{.Option "index"}}" height="{{.Option "height"}}" width="{{.Option "width"}}"
stroke-width="{{.Option "stroke-width"}}" stroke="{{.Option "stroke"}}" fill="{{.Option "fill"}}" stroke-width="{{.Option "stroke-width"}}" stroke="{{.Option "stroke"}}" fill="{{.Option "fill"}}"
font-size="{{.Option "font-size"}}" font-family="{{.Option "font-family"}}" text-anchor="middle" dominant-baseline="middle">`, font-size="{{.Option "font-size"}}" font-family="{{.Option "font-family"}}" text-anchor="middle" dominant-baseline="middle">`,
)}, )},

View File

@ -127,6 +127,10 @@ func (m *Message) ProcessDisplay(arg ...Any) {
m.Option(MSG_DISPLAY, arg...) m.Option(MSG_DISPLAY, arg...)
} }
func (m *Message) ProcessStory(arg ...Any) {
m.Option(MSG_PROCESS, "_story")
m.Option(PROCESS_ARG, arg...)
}
func (m *Message) ProcessField(arg ...Any) { func (m *Message) ProcessField(arg ...Any) {
m.Process(PROCESS_FIELD) m.Process(PROCESS_FIELD)
m.Option(FIELD_PREFIX, arg...) m.Option(FIELD_PREFIX, arg...)