diff --git a/evaldo/repl.go b/evaldo/repl.go index 7c9030ba..c2981cb0 100644 --- a/evaldo/repl.go +++ b/evaldo/repl.go @@ -279,6 +279,15 @@ func constructKeyEvent(r rune, k keyboard.Key) util.KeyEvent { case keyboard.KeyCtrlL: ch = "l" ctrl = true + case keyboard.KeyCtrlN: + ch = "n" + ctrl = true + case keyboard.KeyCtrlP: + ch = "p" + ctrl = true + case keyboard.KeyCtrlU: + ch = "u" + ctrl = true case keyboard.KeyEnter: code = 13 diff --git a/util/microliner.go b/util/microliner.go index f026cee0..fa081cf6 100644 --- a/util/microliner.go +++ b/util/microliner.go @@ -498,6 +498,45 @@ startOfHere: s.getColumns() traceTop(strconv.Itoa(s.columns)+"**", 0) + histPrev := func() { + if historyStale { + historyPrefix = s.getHistoryByPrefix(string(line)) + historyPos = len(historyPrefix) + historyStale = false + } + if historyPos > 0 { + if historyPos == len(historyPrefix) { + historyEnd = string(line) + } + historyPos-- + line = []rune(historyPrefix[historyPos]) + pos = len(line) + s.needRefresh = true + } else { + s.doBeep() + } + } + + histNext := func() { + if historyStale { + historyPrefix = s.getHistoryByPrefix(string(line)) + historyPos = len(historyPrefix) + historyStale = false + } + if historyPos < len(historyPrefix) { + historyPos++ + if historyPos == len(historyPrefix) { + line = []rune(historyEnd) + } else { + line = []rune(historyPrefix[historyPos]) + } + pos = len(line) + s.needRefresh = true + } else { + s.doBeep() + } + } + // JM // s_instr := 0 @@ -565,6 +604,18 @@ startOfHere: case "l": s.eraseScreen() s.needRefresh = true + case "u": // delete to beginning of line + if pos == 0 { + s.doBeep() + } else { + line = line[pos:] + pos = 0 + s.needRefresh = true + } + case "n": + histNext() + case "p": + histPrev() } } else if next.Alt { switch strings.ToLower(next.Key) { @@ -710,42 +761,9 @@ startOfHere: s.doBeep() } case 38: // Up - // historyAction = true - if historyStale { - historyPrefix = s.getHistoryByPrefix(string(line)) - historyPos = len(historyPrefix) - historyStale = false - } - if historyPos > 0 { - if historyPos == len(historyPrefix) { - historyEnd = string(line) - } - historyPos-- - line = []rune(historyPrefix[historyPos]) - pos = len(line) - s.needRefresh = true - } else { - s.doBeep() - } + histPrev() case 40: // Down - // historyAction = true - if historyStale { - historyPrefix = s.getHistoryByPrefix(string(line)) - historyPos = len(historyPrefix) - historyStale = false - } - if historyPos < len(historyPrefix) { - historyPos++ - if historyPos == len(historyPrefix) { - line = []rune(historyEnd) - } else { - line = []rune(historyPrefix[historyPos]) - } - pos = len(line) - s.needRefresh = true - } else { - s.doBeep() - } + histNext() case 36: // Home pos = 0 case 35: // End