1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-28 18:22:02 +08:00

opt index

This commit is contained in:
harveyshao 2022-05-16 11:26:39 +08:00
parent e7fd0d1555
commit 7ca0a478fd
5 changed files with 40 additions and 17 deletions

View File

@ -43,7 +43,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
} }
} }
} }
return m return m // 打包文件
} }
list, e := ioutil.ReadDir(path.Join(root, name)) list, e := ioutil.ReadDir(path.Join(root, name))
@ -75,7 +75,8 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
} }
p := path.Join(root, name, f.Name()) p := path.Join(root, name, f.Name())
if !(dir_type == TYPE_CAT && f.IsDir() || dir_type == TYPE_DIR && !f.IsDir()) && (dir_reg == nil || dir_reg.MatchString(f.Name())) { isDir := f.IsDir() || kit.IsDir(p)
if !(dir_type == TYPE_CAT && isDir || dir_type == TYPE_DIR && !isDir) && (dir_reg == nil || dir_reg.MatchString(f.Name())) {
switch cb := m.OptionCB(DIR).(type) { switch cb := m.OptionCB(DIR).(type) {
case func(f os.FileInfo, p string): case func(f os.FileInfo, p string):
cb(f, p) cb(f, p)
@ -90,7 +91,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
case mdb.TIME: case mdb.TIME:
m.Push(field, f.ModTime().Format(ice.MOD_TIME)) m.Push(field, f.ModTime().Format(ice.MOD_TIME))
case mdb.TYPE: case mdb.TYPE:
m.Push(field, kit.Select(CAT, DIR, f.IsDir())) m.Push(field, kit.Select(CAT, DIR, isDir))
case "tree": case "tree":
if level == 0 { if level == 0 {
@ -99,16 +100,16 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
m.Push(field, strings.Repeat("| ", level-1)+"|-"+f.Name()) m.Push(field, strings.Repeat("| ", level-1)+"|-"+f.Name())
} }
case "full": case "full":
m.Push(field, path.Join(root, name, f.Name())+kit.Select("", ice.PS, f.IsDir())) m.Push(field, path.Join(root, name, f.Name())+kit.Select("", ice.PS, isDir))
case PATH: case PATH:
m.Push(field, path.Join(name, f.Name())+kit.Select("", ice.PS, f.IsDir())) m.Push(field, path.Join(name, f.Name())+kit.Select("", ice.PS, isDir))
case FILE: case FILE:
m.Push(field, f.Name()+kit.Select("", ice.PS, f.IsDir())) m.Push(field, f.Name()+kit.Select("", ice.PS, isDir))
case mdb.NAME: case mdb.NAME:
m.Push(field, f.Name()) m.Push(field, f.Name())
case SIZE: case SIZE:
if f.IsDir() { if isDir {
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil { if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
m.Push(field, len(ls)) m.Push(field, len(ls))
} else { } else {
@ -118,7 +119,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
m.Push(field, kit.FmtSize(f.Size())) m.Push(field, kit.FmtSize(f.Size()))
} }
case LINE: case LINE:
if f.IsDir() { if isDir {
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil { if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
m.Push(field, len(ls)) m.Push(field, len(ls))
} else { } else {
@ -136,7 +137,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
} }
case mdb.HASH, "hashs": case mdb.HASH, "hashs":
var h [20]byte var h [20]byte
if f.IsDir() { if isDir {
if d, e := ioutil.ReadDir(p); m.Assert(e) { if d, e := ioutil.ReadDir(p); m.Assert(e) {
meta := []string{} meta := []string{}
for _, v := range d { for _, v := range d {
@ -153,7 +154,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
m.Push(mdb.HASH, kit.Select(kit.Format(h[:6]), kit.Format(h[:]), field == mdb.HASH)) m.Push(mdb.HASH, kit.Select(kit.Format(h[:6]), kit.Format(h[:]), field == mdb.HASH))
case mdb.LINK: case mdb.LINK:
m.PushDownload(mdb.LINK, kit.Select("", f.Name(), !f.IsDir()), path.Join(root, name, f.Name())) m.PushDownload(mdb.LINK, kit.Select("", f.Name(), !isDir), path.Join(root, name, f.Name()))
case mdb.SHOW: case mdb.SHOW:
switch p := m.MergeURL2("/share/local/"+path.Join(name, f.Name()), ice.POD, m.Option(ice.MSG_USERPOD)); kit.Ext(f.Name()) { switch p := m.MergeURL2("/share/local/"+path.Join(name, f.Name()), ice.POD, m.Option(ice.MSG_USERPOD)); kit.Ext(f.Name()) {
case "png", "jpg": case "png", "jpg":
@ -167,7 +168,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
if m.IsCliUA() || m.Option(ice.MSG_USERROLE) == aaa.VOID { if m.IsCliUA() || m.Option(ice.MSG_USERROLE) == aaa.VOID {
break break
} }
m.PushButton(kit.Select("", TRASH, !f.IsDir())) m.PushButton(kit.Select("", TRASH, !isDir))
default: default:
m.Push(field, "") m.Push(field, "")
} }
@ -178,7 +179,8 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
case "node_modules", "pluged", "target", "trash": case "node_modules", "pluged", "target", "trash":
continue continue
} }
if f.IsDir() && deep {
if deep && isDir {
_dir_list(m, root, path.Join(name, f.Name()), level+1, deep, dir_type, dir_reg, fields) _dir_list(m, root, path.Join(name, f.Name()), level+1, deep, dir_type, dir_reg, fields)
} }
} }

View File

@ -152,6 +152,7 @@ const ( // DIR
SRC_RELAY_GO = "src/relay.go" SRC_RELAY_GO = "src/relay.go"
README_MD = "README.md" README_MD = "README.md"
MAKEFILE = "Makefile" MAKEFILE = "Makefile"
LICENSE = "LICENSE"
ICE_BIN = "ice.bin" ICE_BIN = "ice.bin"
GO_SUM = "go.sum" GO_SUM = "go.sum"
GO_MOD = "go.mod" GO_MOD = "go.mod"

View File

@ -61,7 +61,6 @@ func _binpack_can(m *ice.Message, f *os.File, dir string) {
fmt.Fprintln(f) fmt.Fprintln(f)
} }
func _binpack_ctx(m *ice.Message, f *os.File) { func _binpack_ctx(m *ice.Message, f *os.File) {
_binpack_dir(m, f, ice.SRC_HELP)
_binpack_dir(m, f, ice.SRC) _binpack_dir(m, f, ice.SRC)
} }
@ -149,6 +148,7 @@ func init() {
fmt.Fprintln(f, _binpack_file(m, ice.ETC_EXIT_SHY)) fmt.Fprintln(f, _binpack_file(m, ice.ETC_EXIT_SHY))
fmt.Fprintln(f) fmt.Fprintln(f)
fmt.Fprintln(f, _binpack_file(m, ice.LICENSE))
fmt.Fprintln(f, _binpack_file(m, ice.MAKEFILE)) fmt.Fprintln(f, _binpack_file(m, ice.MAKEFILE))
fmt.Fprintln(f, _binpack_file(m, ice.README_MD)) fmt.Fprintln(f, _binpack_file(m, ice.README_MD))
fmt.Fprintln(f) fmt.Fprintln(f)

View File

@ -62,11 +62,21 @@ func (g *Group) Option(group string, key string, arg ...interface{}) string {
} }
func (g *Group) Get(group string) *ice.Message { return g.list[group] } func (g *Group) Get(group string) *ice.Message { return g.list[group] }
func (g *Group) Join(arg ...string) string {
args := []string{}
for i := 0; i < len(arg)-1; i += 2 {
if arg[i] == "" {
continue
}
args = append(args, kit.Format(`%s="%s"`, arg[i], arg[i+1]))
}
return kit.Join(args, ice.SP)
}
func (g *Group) Echo(group string, str string, arg ...interface{}) *ice.Message { func (g *Group) Echo(group string, str string, arg ...interface{}) *ice.Message {
return g.Get(group).Echo(str, arg...) return g.Get(group).Echo(str, arg...)
} }
func (g *Group) EchoRect(group string, height, width, x, y int, arg ...string) *ice.Message { // rx ry func (g *Group) EchoRect(group string, height, width, x, y int, arg ...string) *ice.Message { // rx ry
return g.Echo(group, `<rect height=%d width=%d rx=%s ry=%s x=%d y=%d />`, height, width, kit.Select("4", arg, 0), kit.Select("4", arg, 1), x, y) return g.Echo(group, `<rect height=%d width=%d rx=%s ry=%s x=%d y=%d %s/>`, height, width, kit.Select("4", arg, 0), kit.Select("4", arg, 1), x, y, g.Join(kit.Slice(arg, 2)...))
} }
func (g *Group) EchoLine(group string, x1, y1, x2, y2 int) *ice.Message { func (g *Group) EchoLine(group string, x1, y1, x2, y2 int) *ice.Message {
return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d></line>", x1, y1, x2, y2) return g.Echo(group, "<line x1=%d y1=%d x2=%d y2=%d></line>", x1, y1, x2, y2)
@ -75,7 +85,7 @@ func (g *Group) EchoText(group string, x, y int, text string, arg ...string) *ic
if text == "" { if text == "" {
return g.Get(group) return g.Get(group)
} }
return g.Echo(group, "<text x=%d y=%d>%s</text>", x, y, text) return g.Echo(group, "<text x=%d y=%d %s>%s</text>", x, y, g.Join(arg...), text)
} }
func (g *Group) EchoTexts(group string, x, y int, text string, arg ...string) *ice.Message { func (g *Group) EchoTexts(group string, x, y int, text string, arg ...string) *ice.Message {
m := g.Get(group) m := g.Get(group)

View File

@ -74,9 +74,19 @@ func (l *Label) Draw(m *ice.Message, x, y int) wiki.Chart {
// 输出 // 输出
if m.Option(SHOW_BLOCK) == ice.TRUE { if m.Option(SHOW_BLOCK) == ice.TRUE {
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), left+item.MarginX/2, top+item.MarginY/2) args := []string{"4", "4"}
if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 {
args = append(args, "fill", m.Option("order.bg"))
}
gs.EchoRect(RECT, item.GetHeight(), item.GetWidth(), left+item.MarginX/2, top+item.MarginY/2, args...)
} }
gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2, item.Text)
args := []string{}
if mod := kit.Int(m.Option("order.mod")); mod != 0 && i%mod == 0 {
args = append(args, "stroke", m.Option("order.fg"))
args = append(args, "fill", m.Option("order.fg"))
}
gs.EchoTexts(TEXT, left+item.GetWidths()/2, top+item.GetHeights()/2, item.Text, args...)
left += item.GetWidths() left += item.GetWidths()
} }