mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
mac add nfs.Read.KeyCtrlW
This commit is contained in:
parent
7e0e95c175
commit
cfdcb4aea6
@ -167,7 +167,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
m.Echo(msg.Cap("sessid"))
|
||||
} // }}}
|
||||
}},
|
||||
"md5": &ctx.Command{Name: "md5 [content][file filename]", Help: "散列",
|
||||
"md5": &ctx.Command{Name: "md5 [file filename][content]", Help: "散列",
|
||||
Formats: map[string]int{"file": 1},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if m.Options("file") { // {{{
|
||||
@ -184,13 +184,16 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
}
|
||||
// }}}
|
||||
}},
|
||||
"rsa": &ctx.Command{Name: "rsa gen|encrypt|decrypt|sign|verify [key str][keyfile filename][signs str][signfile filename][file filename][mm str][mmfile filename] content",
|
||||
Help: ` 密钥: rsa gen keyfile key.pem
|
||||
"rsa": &ctx.Command{Name: "rsa gen|encrypt|decrypt|sign|verify [keyfile filename][key str][mmfile filename][mm str][signfile filename][signs str][file filename] content",
|
||||
Help: ` gen生成密钥, encrypt公钥加密, decrypt私钥解密, sgin私钥签名, verify公钥验签,
|
||||
keyfile密钥文件, key密钥字符串,mm加密文件, mm加密字符串, signfile签名文件,signs签名字符串,
|
||||
file数据文件,content数据内容.
|
||||
密钥: rsa gen keyfile key.pem
|
||||
加密: rsa encrypt keyfile pubkey.pem mmfile mm.txt hello
|
||||
解密: rsa decrypt keyfile key.pem mmfile mm.txt
|
||||
签名: rsa sign keyfile key.pem signfile sign.txt hello
|
||||
验签: rsa verify keyfile pubkey.pem signfile sign.txt hello`,
|
||||
Formats: map[string]int{"key": 1, "keyfile": 1, "signs": 1, "signfile": 1, "file": 1, "mm": 1, "mmfile": 1},
|
||||
Formats: map[string]int{"keyfile": 1, "key": 1, "mmfile": 1, "mm": 1, "signfile": 1, "signs": 1, "file": 1},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if arg[0] == "gen" { // {{{
|
||||
keys, e := rsa.GenerateKey(crand.Reader, 1024)
|
||||
@ -309,6 +312,23 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
}
|
||||
// }}}
|
||||
}},
|
||||
"deal": &ctx.Command{Name: "deal init|sell|buy|done [keyfile name][key str]", Help: "散列",
|
||||
Formats: map[string]int{"file": 1},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if m.Options("file") { // {{{
|
||||
f, e := os.Open(m.Option("file"))
|
||||
m.Assert(e)
|
||||
|
||||
h := md5.New()
|
||||
io.Copy(h, f)
|
||||
|
||||
m.Echo(hex.EncodeToString(h.Sum([]byte{})[:]))
|
||||
} else if len(arg) > 0 {
|
||||
h := md5.Sum([]byte(arg[0]))
|
||||
m.Echo(hex.EncodeToString(h[:]))
|
||||
}
|
||||
// }}}
|
||||
}},
|
||||
},
|
||||
Index: map[string]*ctx.Context{
|
||||
"void": &ctx.Context{Name: "void", Commands: map[string]*ctx.Command{"login": &ctx.Command{}}},
|
||||
|
@ -13,6 +13,7 @@ import ( // {{{
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// }}}
|
||||
@ -129,11 +130,11 @@ func (nfs *NFS) print(str string, arg ...interface{}) bool { // {{{
|
||||
}
|
||||
|
||||
// }}}
|
||||
func (nfs *NFS) page(buf []string, pos int) int { // {{{
|
||||
func (nfs *NFS) page(buf []string, pos int, top int, height int) int { // {{{
|
||||
nfs.escape("2J", "H")
|
||||
begin := pos
|
||||
|
||||
for i := 0; i < nfs.height; i++ {
|
||||
for i := 0; i < height; i++ {
|
||||
if pos < len(buf) && pos >= 0 {
|
||||
if len(buf[pos]) > nfs.width {
|
||||
nfs.color(fmt.Sprintf("%s", buf[pos][:nfs.width]))
|
||||
@ -151,13 +152,13 @@ func (nfs *NFS) page(buf []string, pos int) int { // {{{
|
||||
}
|
||||
|
||||
// }}}
|
||||
func (nfs *NFS) View() { // {{{
|
||||
pos := len(nfs.pages) - nfs.height
|
||||
func (nfs *NFS) View(buf []string, top int, height int) { // {{{
|
||||
pos := len(buf) - height
|
||||
if pos < 0 {
|
||||
pos = 0
|
||||
}
|
||||
|
||||
nfs.page(nfs.pages, pos)
|
||||
nfs.page(buf, pos, top, height)
|
||||
for {
|
||||
switch ev := termbox.PollEvent(); ev.Type {
|
||||
case termbox.EventKey:
|
||||
@ -167,15 +168,15 @@ func (nfs *NFS) View() { // {{{
|
||||
default:
|
||||
switch ev.Ch {
|
||||
case 'f':
|
||||
if pos+nfs.height < len(nfs.pages) {
|
||||
pos += nfs.height - 1
|
||||
if pos+height < len(buf) {
|
||||
pos += height - 1
|
||||
}
|
||||
case 'b':
|
||||
if pos -= nfs.height - 1; pos < 0 {
|
||||
if pos -= height - 1; pos < 0 {
|
||||
pos = 0
|
||||
}
|
||||
case 'j':
|
||||
if pos+1 < len(nfs.pages) {
|
||||
if pos+1 < len(buf) {
|
||||
pos += 1
|
||||
}
|
||||
case 'k':
|
||||
@ -185,7 +186,7 @@ func (nfs *NFS) View() { // {{{
|
||||
case 'q':
|
||||
return
|
||||
}
|
||||
nfs.page(nfs.pages, pos)
|
||||
nfs.page(buf, pos, top, height)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,20 +219,18 @@ func (nfs *NFS) Read(p []byte) (n int, err error) { // {{{
|
||||
os.Exit(1)
|
||||
|
||||
case termbox.KeyCtrlV:
|
||||
nfs.View()
|
||||
nfs.page(nfs.pages, len(nfs.pages)-nfs.height)
|
||||
nfs.View(nfs.pages, 0, nfs.height)
|
||||
nfs.page(nfs.pages, len(nfs.pages)-nfs.height, 0, nfs.height)
|
||||
|
||||
case termbox.KeyCtrlL:
|
||||
nfs.escape("2J", "H")
|
||||
|
||||
case termbox.KeyCtrlJ, termbox.KeyCtrlM:
|
||||
tab = tab[:0]
|
||||
|
||||
buf = append(buf, rest...)
|
||||
buf = append(buf, '\n')
|
||||
nfs.print("\n")
|
||||
|
||||
b := []byte(string(buf[:len(buf)]))
|
||||
b := []byte(string(buf))
|
||||
n = len(b)
|
||||
copy(p, b)
|
||||
return
|
||||
@ -284,6 +283,25 @@ func (nfs *NFS) Read(p []byte) (n int, err error) { // {{{
|
||||
buf = append(buf, rest[0])
|
||||
rest = rest[1:]
|
||||
|
||||
case termbox.KeyCtrlW:
|
||||
if len(buf) > 0 {
|
||||
c := buf[len(buf)-1]
|
||||
for len(buf) > 0 && unicode.IsSpace(c) && unicode.IsSpace(buf[len(buf)-1]) {
|
||||
buf = buf[:len(buf)-1]
|
||||
}
|
||||
|
||||
for len(buf) > 0 && unicode.IsPunct(c) && unicode.IsPunct(buf[len(buf)-1]) {
|
||||
buf = buf[:len(buf)-1]
|
||||
}
|
||||
|
||||
for len(buf) > 0 && unicode.IsLetter(c) && unicode.IsLetter(buf[len(buf)-1]) {
|
||||
buf = buf[:len(buf)-1]
|
||||
}
|
||||
|
||||
for len(buf) > 0 && unicode.IsDigit(c) && unicode.IsDigit(buf[len(buf)-1]) {
|
||||
buf = buf[:len(buf)-1]
|
||||
}
|
||||
}
|
||||
case termbox.KeyCtrlH:
|
||||
if len(buf) == 0 {
|
||||
continue
|
||||
@ -316,6 +334,11 @@ func (nfs *NFS) Read(p []byte) (n int, err error) { // {{{
|
||||
case termbox.KeyCtrlY:
|
||||
buf = append(buf, back...)
|
||||
|
||||
case termbox.KeyCtrlT:
|
||||
if l := len(buf); l > 1 {
|
||||
buf[l-1], buf[l-2] = buf[l-2], buf[l-1]
|
||||
}
|
||||
|
||||
case termbox.KeyCtrlI:
|
||||
if len(tab) == 0 {
|
||||
tabi = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user