aboutsummaryrefslogtreecommitdiffstats
path: root/src/local
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-06-13 23:04:21 +0200
committerbptato <nincsnevem662@gmail.com>2024-06-13 23:24:53 +0200
commitd90e456b80ee11a84eb2a29ce01794fa662eb7b9 (patch)
tree30d358ef3a5c50c6a0272a25f6aff9d150480c4a /src/local
parent17bf0e843084712d9a914868ec44896f48d9d13a (diff)
downloadchawan-d90e456b80ee11a84eb2a29ce01794fa662eb7b9.tar.gz
Update Chame, Chagashi
Diffstat (limited to 'src/local')
-rw-r--r--src/local/lineedit.nim31
-rw-r--r--src/local/term.nim2
2 files changed, 18 insertions, 15 deletions
diff --git a/src/local/lineedit.nim b/src/local/lineedit.nim
index 22fd3988..ba02e2ae 100644
--- a/src/local/lineedit.nim
+++ b/src/local/lineedit.nim
@@ -12,7 +12,6 @@ import utils/twtstr
import utils/wordbreak
import chagashi/charset
-import chagashi/validator
import chagashi/decoder
type
@@ -153,7 +152,7 @@ proc backspace(edit: LineEdit) {.jsfunc.} =
edit.cursori -= len
edit.cursorx -= r.width()
edit.invalid = true
-
+
proc write*(edit: LineEdit; s: string; cs: Charset): bool =
if cs == CHARSET_UTF_8:
if s.validateUTF8Surr() != -1:
@@ -169,7 +168,10 @@ proc write*(edit: LineEdit; s: string; cs: Charset): bool =
return true
proc write(edit: LineEdit; s: string): bool {.jsfunc.} =
- edit.write(s, CHARSET_UTF_8)
+ if s.validateUTF8Surr() != -1:
+ return false
+ edit.insertCharseq(s)
+ return true
proc delete(edit: LineEdit) {.jsfunc.} =
if edit.cursori < edit.news.len:
@@ -311,22 +313,23 @@ proc nextHist(edit: LineEdit) {.jsfunc.} =
proc windowChange*(edit: LineEdit; attrs: WindowAttributes) =
edit.maxwidth = attrs.width - edit.promptw - 1
-proc readLine*(prompt, current: string; termwidth: int;
- disallowed: set[char]; hide: bool; hist: LineHistory): LineEdit =
- result = LineEdit(
+proc readLine*(prompt, current: string; termwidth: int; disallowed: set[char];
+ hide: bool; hist: LineHistory): LineEdit =
+ let promptw = prompt.width()
+ return LineEdit(
prompt: prompt,
- promptw: prompt.width(),
+ promptw: promptw,
news: current,
disallowed: disallowed,
hide: hide,
- invalid: true
+ invalid: true,
+ cursori: current.len,
+ cursorx: current.notwidth(),
+ # - 1, so that the cursor always has place
+ maxwidth: termwidth - promptw - 1,
+ hist: hist,
+ histindex: hist.lines.len
)
- result.cursori = result.news.len
- result.cursorx = result.news.notwidth()
- # - 1, so that the cursor always has place
- result.maxwidth = termwidth - result.promptw - 1
- result.hist = hist
- result.histindex = result.hist.lines.len
proc addLineEditModule*(ctx: JSContext) =
ctx.registerType(LineEdit)
diff --git a/src/local/term.nim b/src/local/term.nim
index 38368515..7dd6d951 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -19,8 +19,8 @@ import utils/strwidth
import utils/twtstr
import chagashi/charset
+import chagashi/decoder
import chagashi/encoder
-import chagashi/validator
#TODO switch away from termcap...