diff options
author | bptato <nincsnevem662@gmail.com> | 2024-12-01 18:44:11 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-12-01 18:44:11 +0100 |
commit | bdc98d93f6bc472be664eac2bd146bb5fb128086 (patch) | |
tree | 8c48b0b66a8df3e8cd98e32fa7ecb4fbbf53cb8e | |
parent | ac40f54eed9d248913b155adf51a755b2fd18d7e (diff) | |
download | chawan-bdc98d93f6bc472be664eac2bd146bb5fb128086.tar.gz |
term: respect LINES, COLUMNS; do not crash without vi/ve
-rw-r--r-- | doc/cha.1 | 4 | ||||
-rw-r--r-- | src/local/term.nim | 18 |
2 files changed, 16 insertions, 6 deletions
diff --git a/doc/cha.1 b/doc/cha.1 index 435482b2..141d45ee 100644 --- a/doc/cha.1 +++ b/doc/cha.1 @@ -129,6 +129,10 @@ defaults to \fIdosansi\fR. \fBEDITOR\fR Used to determine the editor to use when the \fIexternal.editor\fR configuration option is not set. +.TP +\fBLINES, COLUMNS\fR +When set, these are used as fallback values if window size detection +fails. .SH CONFIGURATION Configuration options are described in \fBcha-config\fR(5). diff --git a/src/local/term.nim b/src/local/term.nim index 948d0f24..bc9919b8 100644 --- a/src/local/term.nim +++ b/src/local/term.nim @@ -597,14 +597,14 @@ proc generateSwapOutput(term: Terminal): string = proc hideCursor*(term: Terminal) = when TermcapFound: - if term.tc != nil: + if term.tc != nil and term.hascap vi: term.write(term.ccap vi) return term.write(CIVIS) proc showCursor*(term: Terminal) = when TermcapFound: - if term.tc != nil: + if term.tc != nil and term.hascap ve: term.write(term.ccap ve) return term.write(CNORM) @@ -1277,10 +1277,16 @@ proc detectTermAttributes(term: Terminal; windowOnly: bool): TermStartResult = term.tname = "dosansi" var win: IOctl_WinSize if ioctl(term.istream.fd, TIOCGWINSZ, addr win) != -1: - term.attrs.width = int(win.ws_col) - term.attrs.height = int(win.ws_row) - term.attrs.ppc = int(win.ws_xpixel) div term.attrs.width - term.attrs.ppl = int(win.ws_ypixel) div term.attrs.height + if win.ws_col > 0: + term.attrs.width = int(win.ws_col) + term.attrs.ppc = int(win.ws_xpixel) div term.attrs.width + if win.ws_row > 0: + term.attrs.height = int(win.ws_row) + term.attrs.ppl = int(win.ws_ypixel) div term.attrs.height + if term.attrs.width == 0: + term.attrs.width = int(parseInt32(getEnv("COLUMNS")).get(0)) + if term.attrs.height == 0: + term.attrs.height = int(parseInt32(getEnv("LINES")).get(0)) if term.config.display.query_da1: let r = term.queryAttrs(windowOnly) if r.success: # DA1 success |