Skip to content

Commit

Permalink
Minor update to terminal docs (nim-lang#19056)
Browse files Browse the repository at this point in the history
* Update terminal.nim

- Added some extra docs to cursorUp/Down/Forward/Backward
- I was able to use hideCursor and showCursor without adding stdout, removed the parameter
- Added docs to terminalHeight()* and terminalWidth()*

* Update lib/pure/terminal.nim

Co-authored-by: konsumlamm <[email protected]>

* Update lib/pure/terminal.nim

Co-authored-by: konsumlamm <[email protected]>

* Added back f: file to cursor movement

* Removed unnecessary comments

Co-authored-by: konsumlamm <[email protected]>
  • Loading branch information
2 people authored and PMunch committed Mar 28, 2022
1 parent f864c35 commit 3452546
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/pure/terminal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ when defined(windows):
return 0

proc terminalWidth*(): int =
## Returns the terminal width in columns.
var w: int = 0
w = terminalWidthIoctl([getStdHandle(STD_INPUT_HANDLE),
getStdHandle(STD_OUTPUT_HANDLE),
Expand All @@ -178,6 +179,7 @@ when defined(windows):
return 80

proc terminalHeight*(): int =
## Returns the terminal height in rows.
var h: int = 0
h = terminalHeightIoctl([getStdHandle(STD_INPUT_HANDLE),
getStdHandle(STD_OUTPUT_HANDLE),
Expand Down Expand Up @@ -389,6 +391,9 @@ when defined(windows):

proc cursorUp*(f: File, count = 1) =
## Moves the cursor up by `count` rows.
runnableExamples("-r:off"):
stdout.cursorUp(2)
write(stdout, "Hello World!") # anything written at that location will be erased/replaced with this
when defined(windows):
let h = conHandle(f)
var p = getCursorPos(h)
Expand All @@ -399,6 +404,9 @@ proc cursorUp*(f: File, count = 1) =

proc cursorDown*(f: File, count = 1) =
## Moves the cursor down by `count` rows.
runnableExamples("-r:off"):
stdout.cursorDown(2)
write(stdout, "Hello World!") # anything written at that location will be erased/replaced with this
when defined(windows):
let h = conHandle(f)
var p = getCursorPos(h)
Expand All @@ -409,6 +417,9 @@ proc cursorDown*(f: File, count = 1) =

proc cursorForward*(f: File, count = 1) =
## Moves the cursor forward by `count` columns.
runnableExamples("-r:off"):
stdout.cursorForward(2)
write(stdout, "Hello World!") # anything written at that location will be erased/replaced with this
when defined(windows):
let h = conHandle(f)
var p = getCursorPos(h)
Expand All @@ -419,6 +430,9 @@ proc cursorForward*(f: File, count = 1) =

proc cursorBackward*(f: File, count = 1) =
## Moves the cursor backward by `count` columns.
runnableExamples("-r:off"):
stdout.cursorBackward(2)
write(stdout, "Hello World!") # anything written at that location will be erased/replaced with this
when defined(windows):
let h = conHandle(f)
var p = getCursorPos(h)
Expand Down

0 comments on commit 3452546

Please sign in to comment.