diff --git a/base/nfs/cat.go b/base/nfs/cat.go index 9aca1fd7..e4fe9887 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -2,6 +2,7 @@ package nfs import ( "bytes" + "encoding/csv" "encoding/json" "io" "io/ioutil" @@ -208,3 +209,26 @@ func ReadFile(m *ice.Message, p string) (b []byte, e error) { func Rewrite(m *ice.Message, p string, cb func(string) string) { m.Cmd(SAVE, p, m.Cmdx(CAT, p, func(s string, i int) string { return cb(s) })) } +func ScanCSV(m *ice.Message, file string, cb func([]string), arg ...string) { + f, e := OpenFile(m, file) + if m.Warn(e) { + return + } + r := csv.NewReader(f) + head, err := r.Read() + if err != nil { + return + } + index := []int{} + kit.If(len(arg) == 0, func() { arg = append(arg, head...) }) + kit.For(arg, func(h string) { index = append(index, kit.IndexOf(head, h)) }) + for { + data, err := r.Read() + if err != nil { + break + } + res := []string{} + kit.For(index, func(i int) { res = append(res, data[i]) }) + cb(res) + } +} diff --git a/core/chat/theme/color.go b/core/chat/theme/color.go new file mode 100644 index 00000000..bfeb8c0c --- /dev/null +++ b/core/chat/theme/color.go @@ -0,0 +1,126 @@ +package theme + +import ( + "strconv" + "strings" + + "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web/html" + kit "shylinux.com/x/toolkits" +) + +type color struct { + ice.Hash + limit string `data:"300"` + short string `data:"type,name,text"` + field string `data:"type,name,text,group,order,hash"` + vendor string `data:"https://www.w3.org/TR/css-color-3/"` + group string `name:"group group*"` + load string `name:"load file*"` +} + +func (s color) Load(m *ice.Message, arg ...string) { + nfs.ScanCSV(m.Message, m.Option(nfs.FILE), func(data []string) { + s.Hash.Create(m, mdb.TYPE, m.Option(nfs.FILE), mdb.NAME, data[0], mdb.TEXT, strings.ToUpper(data[1])) + }, mdb.NAME, mdb.TEXT) +} +func (s color) Matrix(m *ice.Message, arg ...string) { + m.Cmd("").Table(func(value ice.Maps) { + key, info := Group(value[mdb.NAME], value[mdb.TEXT]) + m.Push(key, info) + }) + m.Display("") +} +func (s color) List(m *ice.Message, arg ...string) { + s.Hash.List(m, arg...).PushAction(s.Group, s.UnGroup, s.Remove).Action(s.Create, s.Load, s.Matrix, s.Vendor, html.FILTER) + m.Table(func(value ice.Maps) { + key, info := Group(value[mdb.NAME], value[mdb.TEXT]) + m.Push("color", key).Push("weight", info) + }) + m.Cut("type,name,text,group,order,color,weight,hash,action") + m.Sort("type,group,order,text", ice.STR, []string{"red", "yellow", "green", "cyan", "blue", "purple", "brown", "meet", "gray"}, "int", ice.STR).Display("") +} +func (s color) UnGroup(m *ice.Message, arg ...string) { + s.Hash.Modify(m, mdb.GROUP, "") +} +func (s color) Group(m *ice.Message, arg ...string) { + s.Hash.Modify(m, mdb.GROUP, m.Option(mdb.GROUP)) +} +func init() { ice.ChatCmd(color{}) } + +func Group(name, text string) (string, string) { + if text == "#000000" { + return "gray", "" + } + r, _ := strconv.ParseInt(text[1:3], 16, 32) + g, _ := strconv.ParseInt(text[3:5], 16, 32) + b, _ := strconv.ParseInt(text[5:7], 16, 32) + n := r + g + b + red := float32(r) / float32(n) + green := float32(g) / float32(n) + blue := float32(b) / float32(n) + name = kit.Format( + "%s %0.2f %0.2f %0.2f %s", + text, + float32(r)/float32(n), + float32(g)/float32(n), + float32(b)/float32(n), + name, + ) + if red > 0.33 && green > 0.33 && blue > 0.33 { + return "gray", name + } + if red < 0.01 && green > 0.3 && blue > 0.3 { + return "cyan", name + } else if red > 0.3 && green < 0.01 && blue > 0.3 { + return "purple", name + } else if red > 0.3 && green > 0.3 && blue < 0.01 { + return "yellow", name + } + if red > 0.57 { + return "red", name + } else if green > 0.57 { + return "green", name + } else if blue > 0.57 { + return "blue", name + } + if red < 0.1 && green > 0.3 && blue > 0.3 { + return "cyan", name + } else if red > 0.3 && green < 0.1 && blue > 0.3 { + return "purple", name + } else if red > 0.3 && green > 0.3 && blue < 0.1 { + return "yellow", name + } + if red-blue > 0.3 && green-blue > 0.3 { + return "yellow", name + } else if red-green > 0.3 && blue-green > 0.3 { + return "purple", name + } else if green-red > 0.3 && blue-red > 0.3 { + return "cyan", name + } + if red-green > 0.3 && red-blue > 0.3 { + return "red", name + } else if green-red > 0.3 && green-blue > 0.3 { + return "green", name + } else if blue-red > 0.3 && blue-green > 0.3 { + return "blue", name + } + if red-blue > 0.2 && green-blue > 0.2 { + return "yellow", name + } else if red-green > 0.2 && blue-green > 0.2 { + return "purple", name + } else if green-red > 0.2 && blue-red > 0.2 { + return "cyan", name + } + if red > green && red > blue { + return "red", name + } else if green > red && green > blue { + return "green", name + } else if blue > red && blue > green { + return "blue", name + } else { + return "", name + } +} diff --git a/core/chat/theme/color.js b/core/chat/theme/color.js new file mode 100644 index 00000000..70f530b5 --- /dev/null +++ b/core/chat/theme/color.js @@ -0,0 +1,11 @@ +Volcanos(chat.ONIMPORT, { + _init: function(can, msg) { msg.Dump(can) + msg.append[0] == mdb.TYPE? can.page.Select(can, can._output, html.TR, function(target, index) { + can.page.Select(can, target, html.TD, function(target, index) { + msg.append[index] == mdb.NAME && can.page.style(can, target.parentNode, html.BACKGROUND_COLOR, target.innerText) + }) + }): can.page.Select(can, can._output, html.TD, function(target, index) { + can.page.style(can, target, html.BACKGROUND_COLOR, target.innerText.split(" ")[0]) + }) + }, +}) diff --git a/core/chat/theme/theme.go b/core/chat/theme/theme.go new file mode 100644 index 00000000..1032ca48 --- /dev/null +++ b/core/chat/theme/theme.go @@ -0,0 +1,51 @@ +package theme + +import ( + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/lex" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" + "shylinux.com/x/icebergs/core/chat" + kit "shylinux.com/x/toolkits" +) + +func init() { + const THEME = "theme" + chat.Index.MergeCommands(ice.Commands{ + THEME: {Actions: ice.MergeActions(ice.Actions{ + mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.chat.color").Cut(mdb.NAME, mdb.TEXT, mdb.TYPE) }}, + mdb.CREATE: {Name: "create name* plugin-bg-color@color plugin-fg-color@color output-bg-color@color hover-bg-color@color"}, + mdb.SHOW: {Hand: func(m *ice.Message, arg ...string) { + ctx.ProcessFloat(m, "web.chat.iframe", []string{"/?theme=" + m.Option(mdb.NAME)}, arg...) + }}, + nfs.PS: {Hand: func(m *ice.Message, arg ...string) { + if len(arg) == 0 { + m.Cmdy("web.chat.theme") + } else { + m.Cmdy("web.chat.theme", kit.TrimExt(arg[0], nfs.CSS)).RenderResult() + web.RenderType(m.W, arg[0], "") + } + }}, + }, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, kit.Fields("time,name", + "plugin-bg-color", "plugin-fg-color", + "output-bg-color", "output-fg-color", + "hover-bg-color", "hover-fg-color", + "shadow-color", "border-color", + "notice-color", "danger-color", + ))), Hand: func(m *ice.Message, arg ...string) { + if mdb.HashSelect(m, arg...).PushAction(mdb.SHOW, mdb.REMOVE).Display(""); len(arg) > 0 { + defer m.Echo("body.%s {"+lex.NL, kit.TrimExt(arg[0], nfs.CSS)).Echo("}" + lex.NL) + m.Table(func(value ice.Maps) { + kit.For(value, func(k, v string) { + if v == "" || kit.IsIn(k, mdb.TIME, mdb.NAME, ctx.ACTION) { + return + } + m.Echo(kit.Format("\t--%s: %s;\n", k, v)) + }) + }) + } + }}, + }) +} diff --git a/core/chat/theme/theme.js b/core/chat/theme/theme.js new file mode 100644 index 00000000..c9780bad --- /dev/null +++ b/core/chat/theme/theme.js @@ -0,0 +1,8 @@ +Volcanos(chat.ONIMPORT, { + _init: function(can, msg) { + msg.Dump(can) + can.page.Select(can, can._output, "tr>td:not(:first-child):not(:last-child)", function(target) { + can.page.style(can, target, html.BACKGROUND_COLOR, target.innerText) + }) + }, +}) diff --git a/core/chat/theme/trans.json b/core/chat/theme/trans.json new file mode 100644 index 00000000..684bf553 --- /dev/null +++ b/core/chat/theme/trans.json @@ -0,0 +1,9 @@ +{ + "color": "颜色" + "icons": {}, + "input": { + "group": "分组" + "color": "颜色" + }, + "value": {} +} \ No newline at end of file diff --git a/misc/git/tags.go b/misc/git/tags.go index 40fb412c..0997c8a1 100644 --- a/misc/git/tags.go +++ b/misc/git/tags.go @@ -34,8 +34,20 @@ func init() { } if len(arg) > 1 { m.Cmdy("web.code.doc", arg) + kit.For(kit.SplitLine(m.Result()), func(text string) { + ls := kit.Split(text, " (*)") + if strings.HasPrefix(text, "func (") { + m.Push(mdb.NAME, ls[3]) + m.Push(mdb.TEXT, text) + } else if strings.HasPrefix(text, "func") { + m.Push(mdb.NAME, ls[1]) + m.Push(mdb.TEXT, text) + } + }) + m.Action(html.FILTER) return } + m.Cmdy("web.code.doc", arg) list := map[string]bool{} mdb.HashSelect(m.Spawn()).Table(func(value ice.Maps) { list[kit.Fields(value[nfs.PATH], value[nfs.FILE], value[nfs.LINE])] = true }) kit.For(kit.SplitLine(m.Cmdx(cli.SYSTEM, cli.GOTAGS, "-f", "-", "-R", kit.Path(arg[0]))), func(text string) {