Skip to content

Commit

Permalink
handle out of range value for COLUMNS / LINES (#21968)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
etan-status committed May 31, 2023
1 parent 0e5c18a commit b880cdf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pure/terminal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b880cdf

Please sign in to comment.