rogueutil
Cross-platform C/C++ utility for creating text-based user interfaces.
|
Cross-platform C/C++ utility for creating text-based user interfaces. More...
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <termios.h>
#include <unistd.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
Go to the source code of this file.
Macros | |
#define | RUTIL_USE_ANSI |
Define to use ANSI escape sequences instead of WinAPI on Windows. | |
#define | RUTIL_STRING char* |
Define to override rogueutil's string type. More... | |
Typedefs | |
typedef enum color_code | color_code |
Provides easy color codes with similar numbers to QBasic. | |
typedef enum key_code | key_code |
Provides keycodes for special keys. | |
Enumerations | |
enum | color_code { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, GREY, DARKGREY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE } |
Provides easy color codes with similar numbers to QBasic. | |
enum | key_code { KEY_ESCAPE = 0, KEY_ENTER = 1, KEY_SPACE = 32, KEY_INSERT = 2, KEY_HOME = 3, KEY_PGUP = 4, KEY_DELETE = 5, KEY_END = 6, KEY_PGDOWN = 7, KEY_UP = 14, KEY_DOWN = 15, KEY_LEFT = 16, KEY_RIGHT = 17, KEY_F1 = 18, KEY_F2 = 19, KEY_F3 = 20, KEY_F4 = 21, KEY_F5 = 22, KEY_F6 = 23, KEY_F7 = 24, KEY_F8 = 25, KEY_F9 = 26, KEY_F10 = 27, KEY_F11 = 28, KEY_F12 = 29, KEY_NUMDEL = 30, KEY_NUMPAD0 = 31, KEY_NUMPAD1 = 127, KEY_NUMPAD2 = 128, KEY_NUMPAD3 = 129, KEY_NUMPAD4 = 130, KEY_NUMPAD5 = 131, KEY_NUMPAD6 = 132, KEY_NUMPAD7 = 133, KEY_NUMPAD8 = 134, KEY_NUMPAD9 = 135 } |
Provides keycodes for special keys. | |
Functions | |
void | locate (int x, int y) |
Sets the cursor position to one defined by x and y. | |
int | getch (void) |
Get a charater without waiting on a Return. More... | |
int | kbhit (void) |
Determines if a button was pressed. More... | |
void | gotoxy (int x, int y) |
Sets the cursor to the specified x and y position. More... | |
static void | rutil_print (char *st) |
Printing wrapper independent of C/C++. More... | |
int | getkey (void) |
Reads a key press (blocking) More... | |
int | nb_getch (void) |
Non-blocking version of getch() More... | |
char * | getANSIColor (const int c) |
Returns ANSI color escape sequence for specified number. More... | |
char * | getANSIBgColor (const int c) |
Returns the ANSI background color escape sequence. More... | |
void | setColor (int c) |
Changes color as specified by a number. More... | |
void | setBackgroundColor (int c) |
Changes the background color as specified by a number. More... | |
int | saveDefaultColor (void) |
Saves the color to use in resetColor() on Windows @detail Returns -1 if not on Windows or if RUTIL_USE_ANSI is defined. | |
void | resetColor (void) |
Resets the color to one set by saveDefaultColor() More... | |
void | cls (void) |
Clears screen, resets all attributes and moves cursor home. | |
void | setString (char *str) |
Prints the supplied string without advancing the cursor. | |
void | setChar (char ch) |
Sets the character at the cursor without advancing the cursor. | |
void | setCursorVisibility (char visible) |
Shows/hides the cursor. More... | |
void | hidecursor (void) |
Hides the cursor. More... | |
void | showcursor (void) |
Shows the cursor. More... | |
void | msleep (unsigned int ms) |
Pauses the program for a given number of milliseconds. | |
int | trows (void) |
Returns the number of rows in the terminal window or -1 on error. | |
int | tcols (void) |
Returns the number of columns in the terminal or -1 on error. | |
void | anykey (char *msg) |
Waits until a key is pressed. More... | |
void | setConsoleTitle (char *title) |
Sets the console title given a string. | |
void | colorPrint (color_code color, color_code bgcolor, const char *fmt,...) |
Prints a message in a given color. More... | |
char * | getUsername (void) |
Returns the username of the user running the program. | |
void | printXY (int x, int y, char *msg) |
Print a message at a position given by x and y. More... | |
Cross-platform C/C++ utility for creating text-based user interfaces.
Copyright 2020 Sergei Akhmatdinov
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied *. See the License for the specific language governing permissions and limitations under the License.
Rogueutil provides some useful functions for creating TUIs and console-based games, such as color printing and clearing the console. It can be used both as a C or C++ header file and it aims at being cross-platform between Windows and *nix.
#define RUTIL_STRING char* |
Define to override rogueutil's string type.
Defaults to std::string in C++ and char* in C.
void anykey | ( | char * | msg | ) |
Waits until a key is pressed.
msg | The message to display or NULL. Optional in C++. |
void colorPrint | ( | color_code | color, |
color_code | bgcolor, | ||
const char * | fmt, | ||
... | |||
) |
Prints a message in a given color.
fmt | printf-style formatted string to print in C or a list of objects in C++ |
color | Foreground color to be used, use -1 to use the currently set foreground color |
bgcolor | Background color to be used, use -1 to use the currently set background color |
char* getANSIBgColor | ( | const int | c | ) |
Returns the ANSI background color escape sequence.
c | Number 0-15 corresponding to the color code |
char* getANSIColor | ( | const int | c | ) |
Returns ANSI color escape sequence for specified number.
c | Number 0-15 corresponding to the color code |
int getch | ( | void | ) |
Get a charater without waiting on a Return.
Windows has this functionality in conio.h
int getkey | ( | void | ) |
Reads a key press (blocking)
At the moment, only Arrows, ESC, Enter and Space are working
void gotoxy | ( | int | x, |
int | y | ||
) |
Sets the cursor to the specified x and y position.
Windows has this functionality in conio.h
void hidecursor | ( | void | ) |
Hides the cursor.
int kbhit | ( | void | ) |
Determines if a button was pressed.
Windows has this in conio.h
int nb_getch | ( | void | ) |
void printXY | ( | int | x, |
int | y, | ||
char * | msg | ||
) |
Print a message at a position given by x and y.
void resetColor | ( | void | ) |
Resets the color to one set by saveDefaultColor()
|
static |
Printing wrapper independent of C/C++.
st | String to print |
void setBackgroundColor | ( | int | c | ) |
Changes the background color as specified by a number.
c | Number 0-15 corresponding to a color code |
void setColor | ( | int | c | ) |
Changes color as specified by a number.
c | Number 0-15 corresponding to a color code |
void setCursorVisibility | ( | char | visible | ) |
Shows/hides the cursor.
visible | 0 to hide the cursor, anything else to show the cursor |
void showcursor | ( | void | ) |
Shows the cursor.