aboutsummaryrefslogtreecommitdiffstats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-25 21:39:49 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-25 21:41:17 +0200
commit0524bed395cfeb467812854c55673c8dc87a1bde (patch)
tree04d2205e001f26881f51912ab5f05611dc465483 /src/io
parent670e5dd9ae31a6d1bd34df2c7f2af5eabd213b54 (diff)
downloadchawan-0524bed395cfeb467812854c55673c8dc87a1bde.tar.gz
hacks for readline so that it at least kind of works
Proper fix needed later
Diffstat (limited to 'src/io')
-rw-r--r--src/io/lineedit.nim11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/io/lineedit.nim b/src/io/lineedit.nim
index 39ef480c..7b822d1c 100644
--- a/src/io/lineedit.nim
+++ b/src/io/lineedit.nim
@@ -19,6 +19,7 @@ type
lines: seq[string]
LineEdit* = ref object
+ isnew*: bool #TODO hack
news*: seq[Rune]
prompt*: string
promptw: int
@@ -88,6 +89,8 @@ proc begin0(edit: LineEdit) =
proc space(edit: LineEdit, i: int) =
edit.term.write(' '.repeat(i))
+#TODO this is broken (e.g. it doesn't account for shift, but for other
+# reasons too)
proc generateOutput*(edit: LineEdit): FixedGrid =
result = newFixedGrid(edit.promptw + edit.maxwidth)
var x = 0
@@ -134,7 +137,7 @@ proc zeroShiftRedraw(state: LineEdit) =
state.displen = state.news.len
state.redraw()
-proc fullRedraw(state: LineEdit) =
+proc fullRedraw*(state: LineEdit) =
state.displen = state.news.len
if state.cursor > state.shift:
var shiftw = state.news.width(state.shift, state.cursor)
@@ -145,6 +148,9 @@ proc fullRedraw(state: LineEdit) =
state.shift = max(state.cursor - 1, 0)
state.redraw()
+proc drawPrompt*(edit: LineEdit) =
+ edit.term.write(edit.prompt)
+
proc insertCharseq(edit: LineEdit, cs: var seq[Rune]) =
let escNext = edit.escNext
cs.keepIf((r) => (escNext or not r.isControlChar) and not (r.isAscii and char(r) in edit.disallowed))
@@ -340,7 +346,8 @@ proc readLine*(prompt: string, termwidth: int, current = "",
minlen: prompt.width(),
disallowed: disallowed,
hide: hide,
- term: term
+ term: term,
+ isnew: true
)
result.cursor = result.news.width()
result.maxwidth = termwidth - result.promptw