forked from mirror/readline
update example
This commit is contained in:
parent
80af385185
commit
a659448259
BIN
example/demo.gif
BIN
example/demo.gif
Binary file not shown.
Before Width: | Height: | Size: 666 KiB After Width: | Height: | Size: 1.0 MiB |
|
@ -18,7 +18,7 @@ bye: quit
|
|||
|
||||
func main() {
|
||||
l, err := readline.NewEx(&readline.Config{
|
||||
Prompt: "home -> ",
|
||||
Prompt: "home » ",
|
||||
HistoryFile: "/tmp/readline.tmp",
|
||||
})
|
||||
if err != nil {
|
||||
|
|
14
runebuf.go
14
runebuf.go
|
@ -8,18 +8,22 @@ import (
|
|||
type RuneBuffer struct {
|
||||
buf []rune
|
||||
idx int
|
||||
prompt []byte
|
||||
prompt []rune
|
||||
w io.Writer
|
||||
}
|
||||
|
||||
func NewRuneBuffer(w io.Writer, prompt string) *RuneBuffer {
|
||||
rb := &RuneBuffer{
|
||||
prompt: []byte(prompt),
|
||||
prompt: []rune(prompt),
|
||||
w: w,
|
||||
}
|
||||
return rb
|
||||
}
|
||||
|
||||
func (r *RuneBuffer) PromptLen() int {
|
||||
return RunesWidth(r.prompt)
|
||||
}
|
||||
|
||||
func (r *RuneBuffer) Runes() []rune {
|
||||
return r.buf
|
||||
}
|
||||
|
@ -189,11 +193,11 @@ func (r *RuneBuffer) MoveToLineEnd() {
|
|||
}
|
||||
|
||||
func (r *RuneBuffer) LineCount() int {
|
||||
return LineCount(RunesWidth(r.buf) + len(r.prompt))
|
||||
return LineCount(RunesWidth(r.buf) + r.PromptLen())
|
||||
}
|
||||
|
||||
func (r *RuneBuffer) IdxLine() int {
|
||||
totalWidth := RunesWidth(r.buf[:r.idx]) + len(r.prompt)
|
||||
totalWidth := RunesWidth(r.buf[:r.idx]) + r.PromptLen()
|
||||
w := getWidth()
|
||||
line := 0
|
||||
for totalWidth >= w {
|
||||
|
@ -214,7 +218,7 @@ func (r *RuneBuffer) Refresh() {
|
|||
func (r *RuneBuffer) Output() []byte {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf.Write(r.CleanOutput())
|
||||
buf.Write(r.prompt)
|
||||
buf.WriteString(string(r.prompt))
|
||||
buf.Write([]byte(string(r.buf)))
|
||||
if len(r.buf) > r.idx {
|
||||
buf.Write(bytes.Repeat([]byte{'\b'}, len(r.buf)-r.idx))
|
||||
|
|
|
@ -121,7 +121,7 @@ func (o *opSearch) SearchRefresh(x int) {
|
|||
if x < 0 {
|
||||
x = o.buf.idx
|
||||
}
|
||||
x += len(o.buf.prompt)
|
||||
x += o.buf.PromptLen()
|
||||
x = x % getWidth()
|
||||
|
||||
if o.markStart > 0 {
|
||||
|
|
Loading…
Reference in New Issue