mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
add kit.Split
This commit is contained in:
parent
001871003f
commit
e17df876af
@ -1,6 +1,7 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"contexts/ctx"
|
"contexts/ctx"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
@ -143,9 +144,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"action": &ctx.Config{Name: "action", Value: map[string]interface{}{}, Help: "交互任务"},
|
"action": &ctx.Config{Name: "action", Value: map[string]interface{}{}, Help: "交互任务"},
|
||||||
|
|
||||||
"project": &ctx.Config{Name: "project", Value: map[string]interface{}{
|
"project": &ctx.Config{Name: "project", Value: map[string]interface{}{
|
||||||
// vim git golang
|
// vim git golang
|
||||||
"ubuntu": map[string]interface{}{
|
"ubuntu": map[string]interface{}{},
|
||||||
},
|
|
||||||
"github": "https://github.com/shylinux/context",
|
"github": "https://github.com/shylinux/context",
|
||||||
"env": map[string]interface{}{
|
"env": map[string]interface{}{
|
||||||
"GOPATH": "https://github.com/shylinux/context",
|
"GOPATH": "https://github.com/shylinux/context",
|
||||||
@ -517,7 +517,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
read := csv.NewReader(out)
|
read := csv.NewReader(out)
|
||||||
read.Comma = ' '
|
read.Comma = ' '
|
||||||
read.TrimLeadingSpace = true
|
read.TrimLeadingSpace = true
|
||||||
read.FieldsPerRecord = 3
|
read.FieldsPerRecord = 4
|
||||||
data, e := read.ReadAll()
|
data, e := read.ReadAll()
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
for i := 1; i < len(data); i++ {
|
for i := 1; i < len(data); i++ {
|
||||||
@ -527,6 +527,16 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
m.Table()
|
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:
|
default:
|
||||||
m.Echo(out.String())
|
m.Echo(out.String())
|
||||||
}
|
}
|
||||||
@ -587,7 +597,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"proc": &ctx.Command{Name: "proc", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"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
|
return
|
||||||
}},
|
}},
|
||||||
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-07-12 10:59:03", "ZYB-20190522USI", 139,
|
"2019-07-13 00:50:45", "com.mac", 79,
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,25 @@ var STDIO TERM
|
|||||||
|
|
||||||
var EnableDebug = false
|
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 {
|
func Width(str string, mul int) int {
|
||||||
return len([]rune(str)) + (len(str)-len([]rune(str)))/2/mul
|
return len([]rune(str)) + (len(str)-len([]rune(str)))/2/mul
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user