summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorNetsu <52031254+WeebNetsu@users.noreply.github.com>2021-10-26 21:42:22 +0200
committerGitHub <noreply@github.com>2021-10-26 21:42:22 +0200
commitf50bcf82c3e45921961ee4145bac88701fec62b0 (patch)
treeff6b991cd96f06fa1c3af8b478c880f5fd5f2948
parentdde556665aa79626b3477999fa898f7a8b758ca4 (diff)
downloadNim-f50bcf82c3e45921961ee4145bac88701fec62b0.tar.gz
Minor update to terminal docs (#19056)
* 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 <44230978+konsumlamm@users.noreply.github.com>

* Update lib/pure/terminal.nim

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* Added back f: file to cursor movement

* Removed unnecessary comments

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
-rw-r--r--lib/pure/terminal.nim14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim
index 25b1a4cdd..c9aafc037 100644
--- a/lib/pure/terminal.nim
+++ b/lib/pure/terminal.nim
@@ -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),
@@ -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),
@@ -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)
@@ -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)
@@ -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)
@@ -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)