Reset when given Ctrl+C

This commit is contained in:
c-bata 2017-07-18 01:47:50 +09:00
parent 1911969a1d
commit 66c8d4ca5c
2 changed files with 12 additions and 5 deletions

@ -60,7 +60,11 @@ func (p *Prompt) Run() {
p.renderer.BreakLine(p.buf, res)
p.buf = NewBuffer()
p.selected = -1
} else if ac.Key == ControlC || ac.Key == ControlD {
} else if ac.Key == ControlC {
p.renderer.BreakLine(p.buf, "")
p.buf = NewBuffer()
p.selected = -1
} else if ac.Key == ControlD {
return
} else if ac.Key == BackTab || ac.Key == Up {
p.selected -= 1

@ -149,13 +149,16 @@ func (r *Render) BreakLine(buffer *Buffer, result string) {
r.out.EraseDown()
r.renderPrefix()
// Rendering
// Render Line Break
r.out.SetColor(r.inputTextColor, r.inputBGColor)
r.out.WriteStr(buffer.Document().Text + "\n")
r.out.SetColor(r.outputTextColor, r.outputBGColor)
r.out.WriteStr(result + "\n")
// Render Result
if result != "" {
r.out.SetColor(r.outputTextColor, r.outputBGColor)
r.out.WriteStr(result + "\n")
}
r.out.SetColor(DefaultColor, DefaultColor)
r.renderPrefix()
}
func formatCompletions(words []string, max int, prefix string, suffix string) (new []string, width int) {