diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-22 20:14:08 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-22 20:14:19 +0100 |
commit | 78ffc938fa7e4baad0a55625026b765d215be1aa (patch) | |
tree | 857db2e963efb13933d1e7954e9d4dc657b6f11d /src/display | |
parent | def15ede4fbd686b0ee9b193f41b2a47190aa43a (diff) | |
download | chawan-78ffc938fa7e4baad0a55625026b765d215be1aa.tar.gz |
Replace Chakasu with Chagashi
The API is horrid :( but at least it copies less. TODO: think of a better API.
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/lineedit.nim | 18 | ||||
-rw-r--r-- | src/display/term.nim | 16 |
2 files changed, 15 insertions, 19 deletions
diff --git a/src/display/lineedit.nim b/src/display/lineedit.nim index 7a5067eb..6969171e 100644 --- a/src/display/lineedit.nim +++ b/src/display/lineedit.nim @@ -1,4 +1,3 @@ -import std/streams import std/strutils import std/unicode @@ -10,9 +9,9 @@ import types/opt import utils/strwidth import utils/twtstr -import chakasu/charset -import chakasu/decoderstream -import chakasu/encoderstream +import chagashi/charset +import chagashi/validator +import chagashi/decoder type LineEditState* = enum @@ -155,15 +154,14 @@ proc backspace(edit: LineEdit) {.jsfunc.} = proc write*(edit: LineEdit, s: string, cs: Charset): bool = if cs == CHARSET_UTF_8: - if s.validateUtf8() != -1: + if s.validateUTF8Surr() != -1: return false edit.insertCharseq(s) else: - let ss = newStringStream(s) - let ds = newDecoderStream(ss, cs, errormode = DECODER_ERROR_MODE_FATAL) - let es = newEncoderStream(ds, CHARSET_UTF_8) - let s = es.readAll() - if ds.failed or es.failed: + let td = newTextDecoder(cs) + var success = false + let s = td.decodeAll(s, success) + if not success: return false edit.insertCharseq(s) return true diff --git a/src/display/term.nim b/src/display/term.nim index fd6271f3..afe84db6 100644 --- a/src/display/term.nim +++ b/src/display/term.nim @@ -16,9 +16,9 @@ import types/opt import utils/strwidth import utils/twtstr -import chakasu/charset -import chakasu/decoderstream -import chakasu/encoderstream +import chagashi/charset +import chagashi/encoder +import chagashi/validator export isatty @@ -384,7 +384,7 @@ proc setTitle*(term: Terminal, title: string) = term.outfile.write(XTERM_TITLE(title)) proc processOutputString*(term: Terminal, str: string, w: var int): string = - if str.validateUtf8() != -1: + if str.validateUTF8Surr() != -1: return "?" # twidth wouldn't work here, the view may start at the nth character. # pager must ensure tabs are converted beforehand. @@ -397,11 +397,9 @@ proc processOutputString*(term: Terminal, str: string, w: var int): string = # The output encoding matches the internal representation. return str else: - # Output is not utf-8, so we must convert back to utf-32 and then encode. - let ss = newStringStream(str) - let ds = newDecoderStream(ss) - let es = newEncoderStream(ds, term.cs, errormode = ENCODER_ERROR_MODE_FATAL) - return es.readAll() + # Output is not utf-8, so we must encode it first. + var success = false + return newTextEncoder(term.cs).encodeAll(str, success) proc generateFullOutput(term: Terminal, grid: FixedGrid): string = var format = Format() |