Declarations for ColrC cursor controls. More...
#include "colr.h"
Go to the source code of this file.
Macros | |
#define | colr_control(...) |
Like colr_fprint(stdout, ...) except it flushes stdout after it prints. More... | |
#define | COLR_ESC "\x1b[" |
Escape sequence to use when creating escape codes. | |
#define | COLR_ESC_LEN 3 |
Length of COLR_ESC, with NULL -terminator. | |
#define | colr_print_inplace(...) |
Save the cursor position, print exactly like colr_control(), and then restore the cursor position. More... | |
#define | colr_print_overwrite(...) |
Erase the current line, move to column 1 and print exactly like colr_control(). More... | |
#define | EraseMethod_to_str(method) |
Returns a static string representation for an EraseMethod. More... | |
Enumerations | |
enum | EraseMethod { END, START, ALL_MOVE, ALL_ERASE, ALL_MOVE_ERASE, ALL } |
Methods to erase text. More... | |
Functions | |
ColorResult * | Colr_cursor_hide (void) |
Returns an allocated ColorResult that hides the cursor when printed. More... | |
ColorResult * | Colr_cursor_show (void) |
Returns an allocated ColorResult that shows the cursor when printed. More... | |
ColorResult * | Colr_erase_display (EraseMethod method) |
Returns an allocated ColorResult that will erase the display or part of the display when printed. More... | |
ColorResult * | Colr_erase_line (EraseMethod method) |
Returns an allocated ColorResult that will erase line or part of a line when printed. More... | |
ColorResult * | Colr_move_back (unsigned int columns) |
Returns an allocated ColorResult that will move the cursor back a number of columns when printed. More... | |
ColorResult * | Colr_move_column (unsigned int column) |
Returns an allocated ColorResult that will move the cursor to a specific column when printed. More... | |
ColorResult * | Colr_move_down (unsigned int lines) |
Returns an allocated ColorResult that will move the cursor down a number of lines when printed. More... | |
ColorResult * | Colr_move_forward (unsigned int columns) |
Returns an allocated ColorResult that will move the cursor forward a number of columns when printed. More... | |
ColorResult * | Colr_move_next (unsigned int lines) |
Returns an allocated ColorResult that will move the cursor down a number of lines, at the start of the line, when printed. More... | |
ColorResult * | Colr_move_pos (unsigned int line, unsigned int column) |
Returns an allocated ColorResult that will position the cursor on the desired line and column when printed. More... | |
ColorResult * | Colr_move_prev (unsigned int lines) |
Returns an allocated ColorResult that will move the cursor up a number of lines, at the start of the line, when printed. More... | |
ColorResult * | Colr_move_return (void) |
Returns an allocated ColorResult that will move the cursor back to the beginning of the line with a carriage return character when printed. More... | |
ColorResult * | Colr_move_up (unsigned int lines) |
Returns an allocated ColorResult that will move the cursor up a number of lines when printed. More... | |
ColorResult * | Colr_pos_restore (void) |
Returns an allocated ColorResult that restores a previously saved cursor position when printed. More... | |
ColorResult * | Colr_pos_save (void) |
Returns an allocated ColorResult that saves the cursor position when printed. More... | |
ColorResult * | Colr_scroll_down (unsigned int lines) |
Returns an allocated ColorResult that will scroll the cursor down a number of lines when printed. More... | |
ColorResult * | Colr_scroll_up (unsigned int lines) |
Returns an allocated ColorResult that will scroll the cursor up a number of lines when printed. More... | |
Declarations for ColrC cursor controls.
To use ColrC Controls in your project, you will need to include colr.controls.h and compile both colr.c and colr.controls.c with the rest of your files.
Don't forget to compile with colr.c
and -lm
.
#define colr_control | ( | ... | ) |
Like colr_fprint(stdout, ...) except it flushes stdout after it prints.
You may not want to flush stdout after every call. You can use colr_print() with the exact same arguments as colr_control() for those times.
[in] | ... | Arguments for colr_fprintf. |
#define colr_print_inplace | ( | ... | ) |
Save the cursor position, print exactly like colr_control(), and then restore the cursor position.
[in] | ... | Arguments for colr_control() to print. |
#define colr_print_overwrite | ( | ... | ) |
Erase the current line, move to column 1 and print exactly like colr_control().
[in] | ... | Arguments for colr_control() to print. |
#define EraseMethod_to_str | ( | method | ) |
Returns a static string representation for an EraseMethod.
This will be optimized away into a static string, placed in the read-only data section (https://gcc.godbolt.org/z/c3nzTz).
[in] | method | The EraseMethod value to get a string representation for. |
NULL
if the method was unknown. Referenced by Colr_erase_display(), and Colr_erase_line().
enum EraseMethod |
Methods to erase text.
ColorResult* Colr_cursor_hide | ( | void | ) |
Returns an allocated ColorResult that hides the cursor when printed.
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_cursor_show | ( | void | ) |
Returns an allocated ColorResult that shows the cursor when printed.
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_erase_display | ( | EraseMethod | method | ) |
Returns an allocated ColorResult that will erase the display or part of the display when printed.
[in] | method | The erase method. |
An allocated ColorResult, or NULL
if the EraseMethod was invalid.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_erase_line | ( | EraseMethod | method | ) |
Returns an allocated ColorResult that will erase line or part of a line when printed.
[in] | method | The erase method. |
An allocated ColorResult, or NULL
if the EraseMethod was invalid.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_back | ( | unsigned int | columns | ) |
Returns an allocated ColorResult that will move the cursor back a number of columns when printed.
[in] | columns | The number of columns to move. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_column | ( | unsigned int | column | ) |
Returns an allocated ColorResult that will move the cursor to a specific column when printed.
Columns start at 1
.
[in] | column | The column to move to. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_down | ( | unsigned int | lines | ) |
Returns an allocated ColorResult that will move the cursor down a number of lines when printed.
[in] | lines | The number of lines to move. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_forward | ( | unsigned int | columns | ) |
Returns an allocated ColorResult that will move the cursor forward a number of columns when printed.
[in] | columns | The number of columns to move. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_next | ( | unsigned int | lines | ) |
Returns an allocated ColorResult that will move the cursor down a number of lines, at the start of the line, when printed.
[in] | lines | The number of lines to move. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_pos | ( | unsigned int | line, |
unsigned int | column | ||
) |
Returns an allocated ColorResult that will position the cursor on the desired line and column when printed.
Positions start at 1
.
[in] | line | The line to move to. Using 0 is the same as using 1 . |
[in] | column | The column to move to. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_prev | ( | unsigned int | lines | ) |
Returns an allocated ColorResult that will move the cursor up a number of lines, at the start of the line, when printed.
[in] | lines | The number of lines to move. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_return | ( | void | ) |
Returns an allocated ColorResult that will move the cursor back to the beginning of the line with a carriage return character when printed.
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_move_up | ( | unsigned int | lines | ) |
Returns an allocated ColorResult that will move the cursor up a number of lines when printed.
Positions start at 1
.
[in] | lines | The number of lines to move. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_pos_restore | ( | void | ) |
Returns an allocated ColorResult that restores a previously saved cursor position when printed.
This only restores the column position, not the line position.
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_pos_save | ( | void | ) |
Returns an allocated ColorResult that saves the cursor position when printed.
This only saves the column position, not the line position.
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_scroll_down | ( | unsigned int | lines | ) |
Returns an allocated ColorResult that will scroll the cursor down a number of lines when printed.
New lines are added to the top.
[in] | lines | The number of lines to scroll. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.
ColorResult* Colr_scroll_up | ( | unsigned int | lines | ) |
Returns an allocated ColorResult that will scroll the cursor up a number of lines when printed.
New lines are added to the bottom.
[in] | lines | The number of lines to scroll. Using 0 is the same as using 1 . |
An allocated ColorResult.
If allocation fails, NULL
is returned.
If used inside of the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros, or their backing functions, they will free()
the result. Otherwise, you are responsible for calling free()
.