Add ClearScreen operation on Ctrl+L (#56)

* Add ClearScreen operation on Ctrl+L

* Remove TODO from clear screen in readme

* Don't use external command for ClearScreen

* Remove duplicate ClearScreen function
This commit is contained in:
Steven Oud 2016-05-16 11:59:35 +02:00 committed by chzyer
parent 64a71f22be
commit 92c174e5fb
5 changed files with 20 additions and 2 deletions

View File

@ -158,7 +158,7 @@ Notice: `Meta`+`B` is equals with `Alt`+`B` in windows.
| `Ctrl`+`I` / `Tab` | Command line completion | | `Ctrl`+`I` / `Tab` | Command line completion |
| `Ctrl`+`J` | Line feed | | `Ctrl`+`J` | Line feed |
| `Ctrl`+`K` | Cut text to the end of line | | `Ctrl`+`K` | Cut text to the end of line |
| `Ctrl`+`L` | Clean screen (TODO) | | `Ctrl`+`L` | Clear screen |
| `Ctrl`+`M` | Same as Enter key | | `Ctrl`+`M` | Same as Enter key |
| `Ctrl`+`N` / `↓` | Next line (in history) | | `Ctrl`+`N` / `↓` | Next line (in history) |
| `Ctrl`+`P` / `↑` | Prev line (in history) | | `Ctrl`+`P` / `↑` | Prev line (in history) |

View File

@ -12,6 +12,7 @@ const (
CharTab = 9 CharTab = 9
CharCtrlJ = 10 CharCtrlJ = 10
CharKill = 11 CharKill = 11
CharCtrlL = 12
CharEnter = 13 CharEnter = 13
CharNext = 14 CharNext = 14
CharPrev = 16 CharPrev = 16

View File

@ -190,6 +190,9 @@ func (o *Operation) ioloop() {
o.buf.Clean() o.buf.Clean()
o.t.SleepToResume() o.t.SleepToResume()
o.Refresh() o.Refresh()
case CharCtrlL:
ClearScreen(o.w)
o.Refresh()
case MetaBackspace, CharCtrlW: case MetaBackspace, CharCtrlW:
o.buf.BackEscapeWord() o.buf.BackEscapeWord()
case CharEnter, CharCtrlJ: case CharEnter, CharCtrlJ:

View File

@ -3,6 +3,7 @@
package readline package readline
import ( import (
"io"
"os" "os"
"os/signal" "os/signal"
"sync" "sync"
@ -46,6 +47,11 @@ func GetScreenWidth() int {
return getWidth(syscall.Stdout) return getWidth(syscall.Stdout)
} }
// ClearScreen clears the console screen
func ClearScreen(w io.Writer) (int, error) {
return w.Write([]byte("\033[H"))
}
func DefaultIsTerminal() bool { func DefaultIsTerminal() bool {
return IsTerminal(syscall.Stdin) && IsTerminal(syscall.Stdout) return IsTerminal(syscall.Stdin) && IsTerminal(syscall.Stdout)
} }

View File

@ -2,7 +2,10 @@
package readline package readline
import "syscall" import (
"io"
"syscall"
)
func SuspendMe() { func SuspendMe() {
} }
@ -24,6 +27,11 @@ func GetScreenWidth() int {
return int(info.dwSize.x) return int(info.dwSize.x)
} }
// ClearScreen clears the console screen
func ClearScreen(_ io.Writer) error {
return SetConsoleCursorPosition(&_COORD{0, 0})
}
func DefaultIsTerminal() bool { func DefaultIsTerminal() bool {
return true return true
} }