1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

add kit.Split

This commit is contained in:
shaoying 2019-07-13 09:33:45 +08:00
parent 001871003f
commit e17df876af
3 changed files with 35 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package cli
import (
"bufio"
"bytes"
"contexts/ctx"
"encoding/csv"
@ -143,9 +144,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"action": &ctx.Config{Name: "action", Value: map[string]interface{}{}, Help: "交互任务"},
"project": &ctx.Config{Name: "project", Value: map[string]interface{}{
// vim git golang
"ubuntu": map[string]interface{}{
},
// vim git golang
"ubuntu": map[string]interface{}{},
"github": "https://github.com/shylinux/context",
"env": map[string]interface{}{
"GOPATH": "https://github.com/shylinux/context",
@ -517,7 +517,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
read := csv.NewReader(out)
read.Comma = ' '
read.TrimLeadingSpace = true
read.FieldsPerRecord = 3
read.FieldsPerRecord = 4
data, e := read.ReadAll()
m.Assert(e)
for i := 1; i < len(data); i++ {
@ -527,6 +527,16 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}
m.Table()
case "cut":
bio := bufio.NewScanner(out)
bio.Scan()
for heads := kit.Split(bio.Text(), -1); bio.Scan(); {
for i, v := range kit.Split(bio.Text(), len(heads)) {
m.Add("append", heads[i], v)
}
}
m.Table()
default:
m.Echo(out.String())
}
@ -587,7 +597,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
return
}},
"proc": &ctx.Command{Name: "proc", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Cmdy("cli.system", "ps", kit.Select("ax", arg, 0))
m.Cmdy("cli.system", "cmd_parse", "cut", "ps", kit.Select("ax", arg, 0))
return
}},
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-07-12 10:59:03", "ZYB-20190522USI", 139,
"2019-07-13 00:50:45", "com.mac", 79,
}

View File

@ -20,6 +20,25 @@ var STDIO TERM
var EnableDebug = false
func Split(str string, n int) []string {
res := []string{}
for i, j := 0, 0; i < len(str); i++ {
if str[i] == ' ' {
continue
}
for j = i; j < len(str); j++ {
if str[j] == ' ' {
break
}
}
if n == len(res)+1 {
j = len(str)
}
res, i = append(res, str[i:j]), j
}
return res
}
func Width(str string, mul int) int {
return len([]rune(str)) + (len(str)-len([]rune(str)))/2/mul
}