Skip to content

Commit

Permalink
修复自动补全不转义部分空白符
Browse files Browse the repository at this point in the history
  • Loading branch information
iikira committed Jul 27, 2018
1 parent b7b6404 commit 217defb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ func main() {
Description: "清空控制台屏幕",
Category: "其他",
Action: func(c *cli.Context) error {
pcsliner.ClearScreen(line.State)
line.ClearScreen()
return nil
},
},
Expand Down
12 changes: 5 additions & 7 deletions pcsliner/clear.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// +build !windows

package pcsliner

import (
"github.com/peterh/liner"
_ "unsafe" // for go:linkname
"fmt"
)

//go:linkname eraseScreen github.com/iikira/BaiduPCS-Go/vendor/github.com/peterh/liner.(*State).eraseScreen
func eraseScreen(s *liner.State)

// ClearScreen 清空屏幕
func ClearScreen(s *liner.State) {
eraseScreen(s)
func (pl *PCSLiner) ClearScreen() {
fmt.Print("\x1b[H\x1b[2J")
}
14 changes: 14 additions & 0 deletions pcsliner/clear_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pcsliner

import (
"github.com/peterh/liner"
_ "unsafe" // for go:linkname
)

//go:linkname eraseScreen github.com/iikira/BaiduPCS-Go/vendor/github.com/peterh/liner.(*State).eraseScreen
func eraseScreen(s *liner.State)

// ClearScreen 清空屏幕
func (pl *PCSLiner) ClearScreen() {
eraseScreen(pl.State)
}
17 changes: 14 additions & 3 deletions pcspath/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pcspath
import (
"path"
"strings"
"unicode"
)

// EscapeBracketOne 转义中括号, 加一个反斜杠
Expand Down Expand Up @@ -68,9 +69,17 @@ func SplitAll(pcspath string) (elem []string) {
return
}

// Escape 转义字符串的空格, 小括号, 中括号
func isSpace(r rune) rune {
if unicode.IsSpace(r) {
return r
}
return -1
}

// Escape 转义字符串的空白符号, 小括号, 中括号
func Escape(pcspath string) string {
if !strings.ContainsAny(pcspath, " []()") {
// 没有空格
if !strings.ContainsAny(pcspath, "[]()") && strings.IndexFunc(pcspath, unicode.IsSpace) == -1 {
return pcspath
}

Expand All @@ -86,7 +95,9 @@ func Escape(pcspath string) string {
builder.WriteRune('\\')
}
continue
case ' ', '[', ']', '(', ')':
case isSpace(s):
fallthrough
case '[', ']', '(', ')':
builder.WriteString("\\")
builder.WriteRune(s)
isSlash = false
Expand Down

0 comments on commit 217defb

Please sign in to comment.