diff options
Diffstat (limited to 'kern/inc/console.h')
| -rw-r--r-- | kern/inc/console.h | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/kern/inc/console.h b/kern/inc/console.h new file mode 100644 index 0000000..a3649de --- /dev/null +++ b/kern/inc/console.h @@ -0,0 +1,162 @@ +/* + * + * # # + * ## # #### ##### # #### ###### + * # # # # # # # # # # + * # # # # # # # # ##### + * # # # # # # # # # + * # ## # # # # # # # + * # # #### # # #### ###### + * + * Now that it's P3 instead of P1 you are allowed + * to edit this file if it suits you. + * + * Please delete this notice. + * + */ + +/** @file console.h + * + * @brief console functions. + * + * @author Hanjie Wu (hanjiew) + * @bug No functional bugs + */ + +#ifndef _CONSOLE_H +#define _CONSOLE_H + +#include <video_defines.h> + +#include <sync.h> + +/** mutex for console operations */ +extern mutex_t console_lock; + +/** @brief Prints character ch at the current location + * of the cursor. + * + * If the character is a newline ('\n'), the cursor is + * be moved to the beginning of the next line (scrolling if necessary). If + * the character is a carriage return ('\r'), the cursor + * is immediately reset to the beginning of the current + * line, causing any future output to overwrite any existing + * output on the line. If backsapce ('\b') is encountered, + * the previous character is erased. See the main console.c description + * for more backspace behavior. + * + * @param ch the character to print + * @return The input character + */ +int putbyte(char ch); + +/** @brief Prints the string s, starting at the current + * location of the cursor. + * + * If the string is longer than the current line, the + * string fills up the current line and then + * continues on the next line. If the string exceeds + * available space on the entire console, the screen + * scrolls up one line, and then the string + * continues on the new line. If '\n', '\r', and '\b' are + * encountered within the string, they are handled + * as per putbyte. If len is not a positive integer or s + * is null, the function has no effect. + * + * @param s The string to be printed. + * @param len The length of the string s. + * @return Void. + */ +void putbytes(const char* s, int len); + +/** @brief Changes the foreground and background color + * of future characters printed on the console. + * + * If the color code is invalid, the function has no effect. + * + * @param color The new color code. + * @return 0 on success or integer error code less than 0 if + * color code is invalid. + */ +int set_term_color(int color); + +/** @brief Writes the current foreground and background + * color of characters printed on the console + * into the argument color. + * @param color The address to which the current color + * information will be written. + * @return Void. + */ +void get_term_color(int* color); + +/** @brief Sets the position of the cursor to the + * position (row, col). + * + * Subsequent calls to putbytes should cause the console + * output to begin at the new position. If the cursor is + * currently hidden, a call to set_cursor() does not show + * the cursor. + * + * @param row The new row for the cursor. + * @param col The new column for the cursor. + * @return 0 on success or integer error code less than 0 if + * cursor location is invalid. + */ +int set_cursor(int row, int col); + +/** @brief Writes the current position of the cursor + * into the arguments row and col. + * @param row The address to which the current cursor + * row will be written. + * @param col The address to which the current cursor + * column will be written. + * @return Void. + */ +void get_cursor(int* row, int* col); + +/** @brief Hides the cursor. + * + * Subsequent calls to putbytes do not cause the + * cursor to show again. + * + * @return Void. + */ +void hide_cursor(void); + +/** @brief Shows the cursor. + * + * If the cursor is already shown, the function has no effect. + * + * @return Void. + */ +void show_cursor(void); + +/** @brief Clears the entire console. + * + * The cursor is reset to the first row and column + * + * @return Void. + */ +void clear_console(void); + +/** @brief Prints character ch with the specified color + * at position (row, col). + * + * If any argument is invalid, the function has no effect. + * + * @param row The row in which to display the character. + * @param col The column in which to display the character. + * @param ch The character to display. + * @param color The color to use to display the character. + * @return Void. + */ +void draw_char(int row, int col, int ch, int color); + +/** @brief Returns the character displayed at position (row, col). + * @param row Row of the character. + * @param col Column of the character. + * @return The character at (row, col). + */ +char get_char(int row, int col); + +#endif /* _CONSOLE_H */ |
