mirror of https://github.com/japl-lang/jale.git
History progress, but current behavior is broken
See history.nim for future behavior of history Also started testing.md, since after history it's time to start testing
This commit is contained in:
parent
b6cc31d19e
commit
ad508cd9f3
|
@ -42,4 +42,8 @@ proc populateDefaults*(editor: LineEditor) =
|
|||
if editor.content.getContent() == "":
|
||||
editor.finish()
|
||||
editor.events.call(jeQuit)
|
||||
editor.bindKey("shiftup"):
|
||||
editor.historyMove(-1)
|
||||
editor.bindKey("shiftdown"):
|
||||
editor.historyMove(1)
|
||||
|
||||
|
|
43
editor.nim
43
editor.nim
|
@ -11,12 +11,12 @@ import renderer
|
|||
|
||||
type
|
||||
JaleEvent* = enum
|
||||
jeKeypress, jeQuit, jeFinish
|
||||
jeKeypress, jeQuit, jeFinish, jeHistoryChange
|
||||
|
||||
LineEditor* = ref object
|
||||
content*: Multiline
|
||||
historyIndex*: int
|
||||
history: seq[Multiline]
|
||||
historyIndex*: int # TODO to be private
|
||||
history*: seq[Multiline] # TODO to be private
|
||||
keystrokes*: Event[int]
|
||||
events*: Event[JaleEvent]
|
||||
prompt*: string
|
||||
|
@ -49,10 +49,34 @@ proc newLineEditor*: LineEditor =
|
|||
|
||||
# priv/pub methods
|
||||
|
||||
proc historyMove*(editor: LineEditor, delta: int) =
|
||||
# broken behaviour: history should not be modified, it should clone
|
||||
# the modified one that is eventually submitted and add it to the end
|
||||
# TODO
|
||||
if editor.historyIndex + delta < 0:
|
||||
editor.content = editor.history[0]
|
||||
editor.historyIndex = 0
|
||||
elif editor.historyIndex + delta >= editor.history.high():
|
||||
editor.content = editor.history[editor.history.high()]
|
||||
editor.historyIndex = editor.history.high()
|
||||
else:
|
||||
editor.content = editor.history[editor.historyIndex + delta]
|
||||
editor.historyIndex += delta
|
||||
editor.events.call(jeHistoryChange)
|
||||
|
||||
|
||||
proc reset(editor: LineEditor) =
|
||||
editor.unfinish()
|
||||
editor.rendered = 0
|
||||
|
||||
proc flush*(editor: LineEditor) =
|
||||
# kinda like reset, it moves the current element one down in history
|
||||
# and adds a new one
|
||||
editor.reset()
|
||||
editor.content = newMultiline()
|
||||
editor.history.add(editor.content)
|
||||
editor.historyIndex = editor.history.high()
|
||||
|
||||
proc render(editor: LineEditor, line: int = -1, hscroll: bool = true) =
|
||||
var y = line
|
||||
if y == -1:
|
||||
|
@ -98,10 +122,19 @@ proc moveCursorToEnd(editor: LineEditor) =
|
|||
cursorDown(editor.content.high() - editor.content.Y)
|
||||
write stdout, "\n"
|
||||
|
||||
# TODO don't use globals, but allow for event removal
|
||||
var histchange = false
|
||||
proc changeHistory =
|
||||
histchange = true
|
||||
|
||||
proc read*(editor: LineEditor): string =
|
||||
# starts at the top, full render moves it into the right y
|
||||
editor.fullRender()
|
||||
|
||||
# TODO: must remove event at end
|
||||
# otherwise there'll be more instances of the same
|
||||
editor.events.add(jeHistoryChange, changeHistory)
|
||||
|
||||
while not editor.finished:
|
||||
|
||||
# refresh current line every time
|
||||
|
@ -116,12 +149,14 @@ proc read*(editor: LineEditor): string =
|
|||
editor.keystrokes.call(key)
|
||||
editor.events.call(jeKeypress)
|
||||
# redraw everything if y changed
|
||||
if preY != editor.content.Y:
|
||||
if histchange or preY != editor.content.Y:
|
||||
# move to the top
|
||||
if preY > 0:
|
||||
cursorUp(preY)
|
||||
# move to the right y
|
||||
editor.fullRender()
|
||||
if histchange:
|
||||
histchange = false
|
||||
|
||||
# move cursor to end
|
||||
editor.moveCursorToEnd()
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# history.nim
|
||||
|
||||
import multiline
|
||||
|
||||
type HistoryElement* = ref object
|
||||
original*: Multiline
|
||||
current*: Multiline
|
||||
|
||||
type History* = ref object
|
||||
elements: seq[HistoryElement]
|
||||
index: int
|
||||
lowestTouchedIndex: int
|
||||
|
||||
proc newHistoryElement*(og: Multiline): HistoryElement =
|
||||
new(result)
|
||||
result.original = og
|
||||
new(result.current) # TODO deepcopy
|
||||
|
||||
proc delta*(h: History, amt: int): Multiline =
|
||||
discard # move up/down in history and return reference to current
|
||||
# also update lowest touched index
|
||||
|
||||
proc clean*(h: History) =
|
||||
discard # restore originals to current
|
||||
# from lowest touched index to the top
|
||||
|
||||
proc save*(h: History, path: string) =
|
||||
discard # convert it to string, save
|
||||
|
||||
proc loadHistory*(path: string): History =
|
||||
discard # create new history from file
|
||||
|
3
main.nim
3
main.nim
|
@ -14,5 +14,8 @@ e.prompt = "> "
|
|||
e.populateDefaults()
|
||||
while keep:
|
||||
let input = e.read()
|
||||
echo "history index: " & $e.historyIndex
|
||||
e.flush()
|
||||
echo "history len: " & $e.history.len()
|
||||
echo "output:<" & input.replace("\n", "\\n") & ">"
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
This short document describes the testing strategy and status for jale.
|
||||
Jale should be tested on different active versions of different
|
||||
terminal emulators. Also on different OSes. This document describes which
|
||||
platforms are being/planned on being tested and a testing procedure.
|
||||
|
||||
Note: this is a wip document, await updates once the bug hunt starts
|
||||
|
||||
# Platforms
|
||||
|
||||
Unless otherwise specified, everything falls back to Arch linux, x86_64, nim 1.4.2.
|
||||
|
||||
|
||||
| Terminal | Last tested |
|
||||
| :-------- | :------------ |
|
||||
| gnome terminal | never |
|
||||
| xfce terminal | passed on 16.2.2021 |
|
||||
| xterm | never |
|
||||
| urxvt | never |
|
||||
| cmd.exe | never |
|
||||
| powershell | never |
|
||||
| windows terminal | never |
|
||||
| gnome terminal + ssh | never |
|
||||
| gnome terminal + tmux | never |
|
||||
|
||||
# Testing procedure
|
||||
|
||||
- [ ] Jale compiles?
|
||||
- [ ] Entering single line input, backspace, delete
|
||||
- [ ] entering new lines, deleting lines with backspace
|
||||
- [ ] home/end/page up/page down
|
||||
- [ ] Submitting output
|
||||
|
Loading…
Reference in New Issue