diff options
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/buffer.nim | 11 | ||||
-rw-r--r-- | src/io/term.nim | 21 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 7bc181a5..5652e84c 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -93,7 +93,7 @@ func generateFullOutput(buffer: Buffer): string = for cell in buffer.display: if x >= buffer.width: result &= EL() - result &= '\n' + result &= "\r\n" x = 0 w = 0 @@ -104,7 +104,7 @@ func generateFullOutput(buffer: Buffer): string = inc x result &= EL() - result &= '\n' + result &= "\r\n" # generate a sequence of instructions to replace the previous frame with the # current one. ideally should be used when small changes are made (e.g. hover @@ -1178,13 +1178,14 @@ proc drawBuffer*(buffer: Buffer) = var format = newFormat() for line in buffer.lines: if line.formats.len == 0: - print(line.str & '\n') + print(line.str & "\r\n") else: var x = 0 var i = 0 for f in line.formats: var outstr = "" - assert f.pos < line.str.width(), "fpos " & $f.pos & "\nstr" & line.str & "\n" + #TODO TODO TODO renderhtml has broken format outputting + #assert f.pos < line.str.width(), "fpos " & $f.pos & "\nstr" & line.str & "\n" while x < f.pos: var r: Rune fastRuneAt(line.str, i, r) @@ -1194,7 +1195,7 @@ proc drawBuffer*(buffer: Buffer) = print(format.processFormat(f.format)) print(line.str.substr(i)) print(format.processFormat(newFormat())) - print('\n') + print("\r\n") proc refreshBuffer*(buffer: Buffer, peek = false) = buffer.title = buffer.getTitle() diff --git a/src/io/term.nim b/src/io/term.nim index 8424ee10..914b5398 100644 --- a/src/io/term.nim +++ b/src/io/term.nim @@ -1,4 +1,5 @@ import terminal +import std/exitprocs when defined(posix): import termios @@ -12,6 +13,26 @@ type width_px*: int height_px*: int +when defined(posix): + # see https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html + let stdin_fileno = stdin.getFileHandle() + var orig_termios: Termios + proc disableRawMode*() {.noconv.} = + discard tcSetAttr(stdin_fileno, TCSAFLUSH, addr orig_termios) + + proc enableRawMode*() = + addExitProc(disableRawMode) + discard tcGetAttr(stdin_fileno, addr orig_termios) + var raw = orig_termios + raw.c_iflag = raw.c_iflag and not (BRKINT or ICRNL or INPCK or ISTRIP or IXON) + raw.c_oflag = raw.c_oflag and not (OPOST) + raw.c_cflag = raw.c_cflag or CS8 + # we do not currently set ISIG, so that ctrl+c can be used to + # immediately return to the input loop. + #TODO set it once we have separated i/o from layout + raw.c_lflag = raw.c_lflag and not (ECHO or ICANON or IEXTEN) + discard tcSetAttr(stdin_fileno, TCSAFLUSH, addr raw) + proc getTermAttributes*(): TermAttributes = if stdin.isatty(): when defined(posix): |