From bc5c91eb5bc99e662b22bfaa6b84ddc56b70eccc Mon Sep 17 00:00:00 2001 From: chzyer <0@0xdf.com> Date: Sat, 3 Sep 2016 11:26:39 +0800 Subject: [PATCH] remove unused files --- .gitignore | 2 -- char.go | 36 ----------------------------- complete.go | 6 +++++ complete_tag.go | 7 ------ debug.go | 29 ----------------------- doc.go | 20 ---------------- readline.go | 17 ++++++++++++++ utils.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 84 insertions(+), 94 deletions(-) delete mode 100644 .gitignore delete mode 100644 char.go delete mode 100644 complete_tag.go delete mode 100644 debug.go delete mode 100644 doc.go diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d128cc4..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.exe -*.tmp diff --git a/char.go b/char.go deleted file mode 100644 index e269640..0000000 --- a/char.go +++ /dev/null @@ -1,36 +0,0 @@ -package readline - -const ( - CharLineStart = 1 - CharBackward = 2 - CharInterrupt = 3 - CharDelete = 4 - CharLineEnd = 5 - CharForward = 6 - CharBell = 7 - CharCtrlH = 8 - CharTab = 9 - CharCtrlJ = 10 - CharKill = 11 - CharCtrlL = 12 - CharEnter = 13 - CharNext = 14 - CharPrev = 16 - CharBckSearch = 18 - CharFwdSearch = 19 - CharTranspose = 20 - CharCtrlU = 21 - CharCtrlW = 23 - CharCtrlZ = 26 - CharEsc = 27 - CharEscapeEx = 91 - CharBackspace = 127 -) - -const ( - MetaBackward rune = -iota - 1 - MetaForward - MetaDelete - MetaBackspace - MetaTranspose -) diff --git a/complete.go b/complete.go index 75f7f68..75b38af 100644 --- a/complete.go +++ b/complete.go @@ -18,6 +18,12 @@ type AutoCompleter interface { Do(line []rune, pos int) (newLine [][]rune, length int) } +type TabCompleter struct{} + +func (t *TabCompleter) Do([]rune, int) ([][]rune, int) { + return [][]rune{[]rune("\t")}, 0 +} + type opCompleter struct { w io.Writer op *Operation diff --git a/complete_tag.go b/complete_tag.go deleted file mode 100644 index 2039458..0000000 --- a/complete_tag.go +++ /dev/null @@ -1,7 +0,0 @@ -package readline - -type TabCompleter struct{} - -func (t *TabCompleter) Do([]rune, int) ([][]rune, int) { - return [][]rune{[]rune("\t")}, 0 -} diff --git a/debug.go b/debug.go deleted file mode 100644 index 7878500..0000000 --- a/debug.go +++ /dev/null @@ -1,29 +0,0 @@ -package readline - -import ( - "container/list" - "fmt" - "os" - "time" -) - -func sleep(n int) { - Debug(n) - time.Sleep(2000 * time.Millisecond) -} - -// print a linked list to Debug() -func debugList(l *list.List) { - idx := 0 - for e := l.Front(); e != nil; e = e.Next() { - Debug(idx, fmt.Sprintf("%+v", e.Value)) - idx++ - } -} - -// append log info to another file -func Debug(o ...interface{}) { - f, _ := os.OpenFile("debug.tmp", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) - fmt.Fprintln(f, o...) - f.Close() -} diff --git a/doc.go b/doc.go deleted file mode 100644 index 656d6ca..0000000 --- a/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Readline is a pure go implementation for GNU-Readline kind library. -// -// WHY: Readline will support most of features which GNU Readline is supported, and provide a pure go environment and a MIT license. -// -// example: -// rl, err := readline.New("> ") -// if err != nil { -// panic(err) -// } -// defer rl.Close() -// -// for { -// line, err := rl.Readline() -// if err != nil { // io.EOF -// break -// } -// println(line) -// } -// -package readline diff --git a/readline.go b/readline.go index 20a2108..14af1dd 100644 --- a/readline.go +++ b/readline.go @@ -1,3 +1,20 @@ +// Readline is a pure go implementation for GNU-Readline kind library. +// +// example: +// rl, err := readline.New("> ") +// if err != nil { +// panic(err) +// } +// defer rl.Close() +// +// for { +// line, err := rl.Readline() +// if err != nil { // io.EOF +// break +// } +// println(line) +// } +// package readline import "io" diff --git a/utils.go b/utils.go index 6084a7d..96518f1 100644 --- a/utils.go +++ b/utils.go @@ -3,6 +3,9 @@ package readline import ( "bufio" "bytes" + "container/list" + "fmt" + "os" "strconv" "strings" "sync" @@ -14,6 +17,41 @@ var ( isWindows = false ) +const ( + CharLineStart = 1 + CharBackward = 2 + CharInterrupt = 3 + CharDelete = 4 + CharLineEnd = 5 + CharForward = 6 + CharBell = 7 + CharCtrlH = 8 + CharTab = 9 + CharCtrlJ = 10 + CharKill = 11 + CharCtrlL = 12 + CharEnter = 13 + CharNext = 14 + CharPrev = 16 + CharBckSearch = 18 + CharFwdSearch = 19 + CharTranspose = 20 + CharCtrlU = 21 + CharCtrlW = 23 + CharCtrlZ = 26 + CharEsc = 27 + CharEscapeEx = 91 + CharBackspace = 127 +) + +const ( + MetaBackward rune = -iota - 1 + MetaForward + MetaDelete + MetaBackspace + MetaTranspose +) + // WaitForResume need to call before current process got suspend. // It will run a ticker until a long duration is occurs, // which means this process is resumed. @@ -211,3 +249,26 @@ func (r *RawMode) Exit() error { } return Restore(GetStdin(), r.state) } + +// ----------------------------------------------------------------------------- + +func sleep(n int) { + Debug(n) + time.Sleep(2000 * time.Millisecond) +} + +// print a linked list to Debug() +func debugList(l *list.List) { + idx := 0 + for e := l.Front(); e != nil; e = e.Next() { + Debug(idx, fmt.Sprintf("%+v", e.Value)) + idx++ + } +} + +// append log info to another file +func Debug(o ...interface{}) { + f, _ := os.OpenFile("debug.tmp", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + fmt.Fprintln(f, o...) + f.Close() +}