package spin
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=4ca1b0cf7fccdbef2e2e8cba47a66333b2ec1535d45792f5d6ddb8d62824a9eb
sha512=fbb209d50f89f9d924626ba1d12b18f22acd7e3e457a5d371668d0bba3ef8e03fb3d0cac55f3e915f030ce77ecd1a48c471f7c83820f95b996b57cee6ff72e92
doc/spin.ansi/Ansi/index.html
Module Ansi
Source
This module offers basic control of ANSI compliant terminals and the windows shell.
The functions below do not send ANSI codes (i.e., do nothing or only print the output) when then output is not connected to a TTY. Functions providing information (such as pos_cursor
) fail when in that situation. TTY detection is configurable by changing the value of isatty
.
This library is not thread safe.
Colors and style
Available colors.
Various styles for the text. Blink
and Hidden
may not work on every terminal.
Shortcut for Hidden
Turns the autoreset feature on and off. It defaults to on.
print_string attr txt
prints the string txt
with the attibutes attr
. After printing, the attributes are automatically reseted to the defaults, unless autoreset is turned off.
Like print_string
but prints on the standard error.
printf attr format arg1 ... argN
prints the arguments arg1
,...,argN
according to format
with the attibutes attr
. After printing, the attributes are automatically reseted to the defaults, unless autoreset is turned off.
Same as printf
but prints the result on stderr
.
Same as printf
but returns the result in a string. This only works on ANSI compliant terminals — for which escape sequences are used — and not under Windows — where system calls are required. On Windows, it is identical to the standard sprintf
.
Erasing
erase Eol
clear from the cursor position to the end of the line without moving the cursor. erase Above
erases everything before the position of the cursor. erase Below
erases everything after the position of the cursor. erase Screen
erases the whole screen.
This function does not modify the position of the cursor.
Cursor
set_cursor x y
puts the cursor at position (x,y)
, x
indicating the column (the leftmost one being 1) and y
being the line (the topmost one being 1). If x <= 0
, the x
coordinate is unchanged; if y <= 0
, the y
coordinate is unchanged.
move_cursor x y
moves the cursor by x
columns (to the right if x > 0
, to the left if x < 0
) and by y
lines (downwards if y > 0
and upwards if y < 0
).
move_bol ()
moves the cursor to the beginning of the current line. This is useful for progress bars for example.
pos_cursor ()
returns a couple (x,y)
giving the current position of the cursor, x >= 1
being the column and y >= 1
the row.
save_cursor ()
saves the current position of the cursor.
show_cursor ()
show the cursor.
Not implemented on Windows.
show_cursor ()
hidex the cursor.
Not implemented on Windows.
restore_cursor ()
replaces the cursor to the position saved with save_cursor ()
.
Size
resize width height
resize the current terminal to the given width
and height
.
size ()
returns a pair (width, height)
giving the size of the terminal in character cells.
Scrolling
scroll n
scrolls the terminal by n
lines, up (creating new lines at the bottom) if n > 0
and down if n < 0
.
TTY
Function used to detect whether the current output is connected to a TTY. Defaults to Unix.isatty
.