1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
shaoying 2021-06-14 00:29:53 +08:00
parent b3950d3e2a
commit 419a1d09f5
11 changed files with 63 additions and 77 deletions

View File

@ -23,6 +23,9 @@ func _sess_check(m *ice.Message, sessid string) {
})
}
func _sess_create(m *ice.Message, username string) string {
if username == "" {
return ""
}
if m.Richs(USER, nil, username, nil) == nil {
_user_create(m, username, kit.Hashs())
}
@ -41,9 +44,6 @@ func SessCheck(m *ice.Message, sessid string) {
_sess_check(m, sessid)
}
func SessCreate(m *ice.Message, username string) string {
if username == "" {
return ""
}
return m.Option(ice.MSG_SESSID, _sess_create(m, username))
}
func SessIsCli(m *ice.Message) bool {

View File

@ -12,8 +12,12 @@ import (
)
func _cli_init(m *ice.Message) {
// 版本信息
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Make)), func(key string, value interface{}) {
m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(key)), value)
})
// 启动配置
// 环境变量
for _, k := range []string{CTX_SELF, CTX_DEV, CTX_SHY, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER} {
m.Conf(RUNTIME, kit.Keys(CONF, k), os.Getenv(k))
}
@ -44,9 +48,6 @@ func _cli_init(m *ice.Message) {
ice.Info.PathName = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))
ice.Info.UserName = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
ice.Info.CtxShare = m.Conf(RUNTIME, kit.Keys(CONF, CTX_SHARE))
ice.Info.CtxRiver = m.Conf(RUNTIME, kit.Keys(CONF, CTX_RIVER))
// 启动次数
count := kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, kit.MDB_COUNT))) + 1
m.Conf(RUNTIME, kit.Keys(BOOT, kit.MDB_COUNT), count)
@ -59,11 +60,6 @@ func _cli_init(m *ice.Message) {
n := kit.Int(kit.Select("1", m.Conf(RUNTIME, kit.Keys(HOST, "GOMAXPROCS"))))
m.Logs(HOST, "GOMAXPROCS", n)
runtime.GOMAXPROCS(n)
// 版本信息
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Build)), func(key string, value interface{}) {
m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(key)), value)
})
}
func NodeInfo(m *ice.Message, kind, name string) {
name = strings.ReplaceAll(name, ".", "_")

View File

@ -49,8 +49,7 @@ func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
kit.MDB_STATUS, ERROR, kit.MDB_ERROR, e)
} else {
m.Cost("args", cmd.Args, "code", cmd.ProcessState.ExitCode())
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h,
kit.MDB_STATUS, STOP)
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h, kit.MDB_STATUS, STOP)
}
if w, ok := m.Optionv(CMD_OUTPUT).(io.Closer); ok {
@ -86,7 +85,6 @@ func init() {
DAEMON: {Name: DAEMON, Help: "守护进程", Value: kit.Data(kit.MDB_PATH, path.Join(ice.USR_LOCAL, DAEMON))},
},
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(mdb.PRUNES, DAEMON, "", mdb.HASH, mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
}},

View File

@ -17,11 +17,11 @@ import (
var _trans_web = map[string]color.Color{
BLACK: color.RGBA{0, 0, 0, DARK},
RED: color.RGBA{DARK, 0, 0, DARK},
YELLOW: color.RGBA{DARK, DARK, 0, DARK},
GREEN: color.RGBA{0, DARK, 0, DARK},
CYAN: color.RGBA{0, DARK, DARK, DARK},
YELLOW: color.RGBA{DARK, DARK, 0, DARK},
BLUE: color.RGBA{0, 0, DARK, DARK},
MAGENTA: color.RGBA{DARK, 0, DARK, DARK},
CYAN: color.RGBA{0, DARK, DARK, DARK},
WHITE: color.RGBA{DARK, DARK, DARK, DARK},
}
@ -63,7 +63,7 @@ func _trans_cli(str string) string {
return kit.Format(res)
}
func _qrcode_cli(m *ice.Message, text string, arg ...string) {
func _qrcode_cli(m *ice.Message, text string) {
qr, _ := qrcode.New(text, qrcode.Medium)
fg := _trans_cli(m.Option(FG))
bg := _trans_cli(m.Option(BG))
@ -82,8 +82,9 @@ func _qrcode_cli(m *ice.Message, text string, arg ...string) {
}
m.Echo("\n")
}
m.Echo(text)
}
func _qrcode_web(m *ice.Message, text string, arg ...string) {
func _qrcode_web(m *ice.Message, text string) {
qr, _ := qrcode.New(text, qrcode.Medium)
qr.ForegroundColor = _parse_color(m.Option(FG))
qr.BackgroundColor = _parse_color(m.Option(BG))
@ -96,12 +97,7 @@ func _qrcode_web(m *ice.Message, text string, arg ...string) {
func Color(m *ice.Message, c string, str string) string {
wrap, color := `<span style="color:%s">%s</span>`, c
if aaa.SessIsCli(m) {
wrap, color = "\033[3%sm%s\033[0m", map[string]string{
BLACK: "0",
RED: "1", GREEN: "2", YELLOW: "3",
BLUE: "4", MAGENTA: "5", CYAN: "6",
WHITE: "7",
}[c]
wrap, color = "\033[3%sm%s\033[0m", _trans_cli(c)
}
return fmt.Sprintf(wrap, color, str)
}
@ -119,11 +115,11 @@ const (
const (
BLACK = "black"
RED = "red"
YELLOW = "yellow"
GREEN = "green"
CYAN = "cyan"
YELLOW = "yellow"
BLUE = "blue"
MAGENTA = "magenta"
CYAN = "cyan"
WHITE = "white"
RANDOM = "random"
)

View File

@ -11,6 +11,28 @@ import (
kit "github.com/shylinux/toolkits"
)
func _runtime_hostinfo(m *ice.Message) {
if f, e := os.Open("/proc/cpuinfo"); e == nil {
defer f.Close()
if b, e := ioutil.ReadAll(f); e == nil {
m.Push("nCPU", bytes.Count(b, []byte("processor")))
}
}
if f, e := os.Open("/proc/meminfo"); e == nil {
defer f.Close()
if b, e := ioutil.ReadAll(f); e == nil {
for i, ls := range strings.Split(string(b), "\n") {
vs := kit.Split(ls, ": ")
m.Push(strings.TrimSpace(vs[0]), kit.FmtSize(kit.Int64(strings.TrimSpace(vs[1]))*1024))
if i > 1 {
break
}
}
}
}
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), ",")[0])
}
const (
DISKINFO = "diskinfo"
IFCONFIG = "ifconfig"
@ -47,25 +69,7 @@ func init() {
m.Echo(ice.Info.HostName)
}},
HOSTINFO: {Name: "hostinfo", Help: "主机信息", Hand: func(m *ice.Message, arg ...string) {
if f, e := os.Open("/proc/cpuinfo"); e == nil {
defer f.Close()
if b, e := ioutil.ReadAll(f); e == nil {
m.Push("nCPU", bytes.Count(b, []byte("processor")))
}
}
if f, e := os.Open("/proc/meminfo"); e == nil {
defer f.Close()
if b, e := ioutil.ReadAll(f); e == nil {
for i, ls := range strings.Split(string(b), "\n") {
vs := kit.Split(ls, ": ")
m.Push(strings.TrimSpace(vs[0]), kit.FmtSize(kit.Int64(strings.TrimSpace(vs[1]))*1024))
if i > 1 {
break
}
}
}
}
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), ",")[0])
_runtime_hostinfo(m)
}},
USERINFO: {Name: "userinfo", Help: "用户信息", Hand: func(m *ice.Message, arg ...string) {
m.Split(m.Cmdx(SYSTEM, "who"), "user term time", " ", "\n")

View File

@ -30,8 +30,8 @@ func _system_show(m *ice.Message, cmd *exec.Cmd) {
out := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
err := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
defer func() {
m.Push(CMD_ERR, err.String())
m.Push(CMD_OUT, out.String())
m.Push(CMD_ERR, err.String())
m.Echo(kit.Select(out.String(), err.String()))
}()

View File

@ -10,7 +10,6 @@ const LEX = "lex"
var Index = &ice.Context{Name: LEX, Help: "词法模块",
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
return
m.Load()
m.Richs(m.Prefix(MATRIX), "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
value = kit.GetMeta(value)
@ -23,7 +22,6 @@ var Index = &ice.Context{Name: LEX, Help: "词法模块",
})
}},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
return
m.Save()
}},
},

View File

@ -10,11 +10,6 @@ import (
kit "github.com/shylinux/toolkits"
)
type Seed struct {
page int
hash int
word string
}
type Point struct {
s int
c byte
@ -33,7 +28,7 @@ type Matrix struct {
hash map[string]int
word map[int]string
trans map[byte]string
trans map[byte][]byte
state map[State]*State
mat []map[byte]*State
}
@ -45,9 +40,12 @@ func NewMatrix(m *ice.Message, nlang, ncell int) *Matrix {
mat.hash = map[string]int{}
mat.word = map[int]string{}
mat.trans = map[byte]string{
mat.trans = map[byte][]byte{}
for k, v := range map[byte]string{
't': "\t", 'n': "\n", 'b': "\t ", 's': "\t \n",
'd': "0123456789", 'x': "0123456789ABCDEFabcdef",
} {
mat.trans[k] = []byte(v)
}
mat.state = make(map[State]*State)
@ -56,7 +54,7 @@ func NewMatrix(m *ice.Message, nlang, ncell int) *Matrix {
}
func (mat *Matrix) char(c byte) []byte {
if cs, ok := mat.trans[c]; ok {
return []byte(cs)
return cs
}
return []byte{c}
}
@ -254,7 +252,6 @@ func (mat *Matrix) Parse(m *ice.Message, npage string, line []byte) (hash int, w
pos := 0
for star, s := 0, page; s != 0 && pos < len(line); pos++ {
c := line[pos]
if c == '\\' && pos < len(line)-1 { //跳过转义
pos++
@ -283,9 +280,7 @@ func (mat *Matrix) Parse(m *ice.Message, npage string, line []byte) (hash int, w
}
}
if pos == len(line) {
// hash, pos, word = -1, 0, word[:0]
} else if hash == 0 {
if hash == 0 {
pos, word = 0, word[:0]
}
rest = line[pos:]
@ -316,9 +311,9 @@ func (mat *Matrix) show(m *ice.Message) {
key := kit.Format("%c", j)
if node := mat.mat[i][byte(j)]; node != nil {
if node.hash == 0 {
m.Push(key, kit.Select(kit.Format("%02d", node.next), cli.ColorRed(m, mat.hand[node.next])))
m.Push(key, kit.Select(kit.Format("%02d", node.next), cli.ColorGreen(m, kit.Select(kit.Format("%d", node.next), mat.hand[node.next]))))
} else {
m.Push(key, kit.Select(kit.Format("w%02d", node.hash), cli.ColorGreen(m, mat.word[node.hash])))
m.Push(key, kit.Select(kit.Format("w%02d", node.hash), cli.ColorRed(m, mat.word[node.hash])))
}
} else {
m.Push(key, "")
@ -330,8 +325,8 @@ func (mat *Matrix) show(m *ice.Message) {
const (
NLANG = "nlang"
NCELL = "ncell"
NSEED = "nseed"
)
const (
NPAGE = "npage"
NHASH = "nhash"
)
@ -351,7 +346,7 @@ func init() {
mdb.CREATE: {Name: "create nlang=32 ncell=256", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
mat := NewMatrix(m, kit.Int(kit.Select("32", m.Option(NLANG))), kit.Int(kit.Select("256", m.Option(NCELL))))
h := m.Rich(m.Prefix(MATRIX), "", kit.Data(kit.MDB_TIME, m.Time(), MATRIX, mat, NLANG, mat.nlang, NCELL, mat.ncell))
switch cb := m.Optionv("matrix.cb").(type) {
switch cb := m.Optionv(kit.Keycb(MATRIX)).(type) {
case func(string, *Matrix):
cb(h, mat)
}
@ -377,8 +372,7 @@ func init() {
"show": {Name: "show", Help: "矩阵", Hand: func(m *ice.Message, arg ...string) {
m.Richs(m.Prefix(MATRIX), "", m.Option(kit.MDB_HASH), func(key string, value map[string]interface{}) {
value = kit.GetMeta(value)
mat, _ := value[MATRIX].(*Matrix)
mat.show(m)
value[MATRIX].(*Matrix).show(m)
})
m.ProcessInner()
}},

View File

@ -73,13 +73,13 @@ import (
)
func init() {
ice.Info.Build.Time = "%s"
ice.Info.Build.Hash = "%s"
ice.Info.Build.Remote = "%s"
ice.Info.Build.Branch = "%s"
ice.Info.Build.Version = "%s"
ice.Info.Build.HostName = "%s"
ice.Info.Build.UserName = "%s"
ice.Info.Make.Time = "%s"
ice.Info.Make.Hash = "%s"
ice.Info.Make.Remote = "%s"
ice.Info.Make.Branch = "%s"
ice.Info.Make.Version = "%s"
ice.Info.Make.HostName = "%s"
ice.Info.Make.UserName = "%s"
}
`,
m.Time(),

View File

@ -23,7 +23,7 @@ var Info = struct {
CtxShare string
CtxRiver string
Build struct {
Make struct {
Time string
Hash string
Remote string

View File

@ -74,7 +74,7 @@ var Index = &ice.Context{Name: VIM, Help: "编辑器",
},
Configs: map[string]*ice.Config{
VIM: {Name: "vim", Help: "编辑器", Value: kit.Data(
"source", "ftp://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2",
"source", "http://ftp.vim.org/pub/vim/unix/vim-8.1.tar.bz2",
"build", []interface{}{
"--enable-multibyte=yes",
"--enable-pythoninterp=yes",