summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorEtan Kissling <etan@status.im>2023-05-31 19:10:58 +0200
committerGitHub <noreply@github.com>2023-05-31 19:10:58 +0200
commitb880cdff49576c0eb83a043cbae595d3587c95b4 (patch)
treecd8046b06e193c4a182d5272e3e7daf22df888f7
parent0e5c18a73a2d72067ba18211fa20e4782175fd40 (diff)
downloadNim-b880cdff49576c0eb83a043cbae595d3587c95b4.tar.gz
handle out of range value for `COLUMNS` / `LINES` (#21968)
* handle out of range value for `COLUMNS` / `LINES`

Querying terminal size may fail with a `ValueError` if size is too big.
Return highest possible value instead. Note that `ValueError` is also
reported on underflow (negative size) but that is out of POSIX specs.

* `parseSaturatedNatural`
-rw-r--r--lib/pure/terminal.nim4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim
index de96293f8..4177eb002 100644
--- a/lib/pure/terminal.nim
+++ b/lib/pure/terminal.nim
@@ -305,7 +305,7 @@ else:
 
     var w: int
     var s = getEnv("COLUMNS") # Try standard env var
-    if len(s) > 0 and parseInt(s, w) > 0 and w > 0:
+    if len(s) > 0 and parseSaturatedNatural(s, w) > 0 and w > 0:
       return w
     w = terminalWidthIoctl([0, 1, 2]) # Try standard file descriptors
     if w > 0: return w
@@ -339,7 +339,7 @@ else:
 
     var h: int
     var s = getEnv("LINES") # Try standard env var
-    if len(s) > 0 and parseInt(s, h) > 0 and h > 0:
+    if len(s) > 0 and parseSaturatedNatural(s, h) > 0 and h > 0:
       return h
     h = terminalHeightIoctl([0, 1, 2]) # Try standard file descriptors
     if h > 0: return h