Bugz Door Project
|
#include <door.h>
Public Member Functions | |
Door (std::string dname, int argc, char *argv[]) | |
Construct a new Door:: Door object. More... | |
Door (Door &)=delete | |
ofstream & | log (void) |
Give ofstream handle for logging. More... | |
signed int | getkey (void) |
Get a key routine. More... | |
bool | haskey (void) |
Are there any keys in STDIN? More... | |
signed int | sleep_key (int secs) |
Waits secs seconds for a keypress. More... | |
signed int | sleep_ms_key (int msecs) |
Waits miliseconds for a keypress. More... | |
std::string | input_string (int max) |
Input a string of requested max length. More... | |
int | get_one_of (const char *keys) |
Get one of these keys. More... | |
Public Attributes | |
AnyOption | opt |
std::string | debug_buffer |
ANSIColor | previous |
bool | track |
int | cx |
int | cy |
int | width |
int | height |
int | inactivity |
Number of seconds before timing out. More... | |
std::string | username |
std::string | handle |
std::string | location |
std::string | sysop |
int | node |
atomic< int > | time_left |
atomic< int > | time_used |
Private Member Functions | |
std::streamsize | xsputn (const char *s, std::streamsize n) override |
int | overflow (int c) override |
void | parse_dropfile (const char *filepath) |
Load dropfile into dropfilelines and parse. More... | |
void | init (void) |
signed int | getch (void) |
low level read key. More... | |
signed int | getkey_or_pushback (void) |
void | detect_unicode_and_screen (void) |
Detect unicode/CP437, and screen size. More... | |
void | time_thread_run (std::future< void > future) |
Private Attributes | |
std::string | doorname |
std::time_t | startup |
struct termios | tio_default |
bool | has_dropfile |
bool | debugging |
std::string | dropfilename |
vector< std::string > | dropfilelines |
ofstream | logf |
std::promise< void > | stop_thread |
int | seconds_elapsed |
std::thread | time_thread |
This handles output to the caller, via ostream.
door::Door::Door | ( | std::string | dname, |
int | argc, | ||
char * | argv[] | ||
) |
|
private |
Detect unicode/CP437, and screen size.
This sets unicode and full_cp437 flags, width and height.
This works by clearing the screen and homing the cursor. We then output some CP437 symbols and ask for the cursor position. We send a newline, output a unicode symbol, and query cursor position.
The CP437 symbols we use are specific. They are the hearts and diamonds symbols, which are commonly mistaken for control codes. If unicode == false and full_cp437 == true, then we do fully support CP437 on this terminal.
For the screensize, we move the cursor down 999 and move cursor right 999 and query position.
On failure to detect screensize, width and height are set to 0.
int door::Door::get_one_of | ( | const char * | keys | ) |
Get one of these keys.
returns char, or < 0 if timeout.
keys |
|
private |
low level read key.
Returns key, or -1 no key available/timeout -2 read error/hang up -3 out of time
signed int door::Door::getkey | ( | void | ) |
Get a key routine.
This returns the key received, or XKEY_* values for function keys, etc. If return < 0: -1 timeout/no key -2 hangup -3 out of time
|
private |
Call low level getch if the pushback buffer is empty.
This allows testing of the Door::getkey function.
bool door::Door::haskey | ( | void | ) |
Are there any keys in STDIN?
This uses select to check if we have received any keys. This does not use pushback.
If HANGUP, OUTOFTIME, return true
std::string door::Door::input_string | ( | int | max | ) |
Input a string of requested max length.
This first sends out max number of spaces, and max number of backspaces. This will setup the input area. (If you set a background color of blue, this would allow that to be seen by the user.)
It handles input, backspaces / deleting the characters / enter input and timeout/hangup/out of time.
max |
ofstream & door::Door::log | ( | void | ) |
Give ofstream handle for logging.
This appends the current date/time stamp into the logfile, and returns a reference.
Example:
door.log() << "Something bad just happened." << std::endl;
|
overrideprivate |
Stores a character into the buffer. This does still use the buffer.
c | char |
|
private |
Load dropfile into dropfilelines and parse.
Load dropfile and parse door.sys and door32.sys.
[in] | filepath | Dropfile path and filename |
signed int door::Door::sleep_key | ( | int | secs | ) |
Waits secs seconds for a keypress.
returns key, or -1 on timeout (seconds passed). -2 hangup -3 out of time
secs |
signed int door::Door::sleep_ms_key | ( | int | msecs | ) |
Waits miliseconds for a keypress.
returns key, or -1 on timeout (seconds passed). -2 hangup -3 out of time
msecs |
|
overrideprivate |
Take given buffer and output it.
If debug_capture is enabled, we save everything to debug_buffer. This is used by the tests.
s | const char * |
n | std::streamsize |
int door::Door::cx |
int door::Door::cy |
std::string door::Door::debug_buffer |
Buffer that holds the output for testing.
|
private |
The name used for logfile
|
private |
Contents of the dropfile.
|
private |
Name of the dropfile.
std::string door::Door::handle |
BBS Dropfile handle
|
private |
Did we read a dropfile?
int door::Door::height |
Detected screen height.
int door::Door::inactivity |
Number of seconds before timing out.
When prompting for user input, this is the number of seconds they have to respond before we give up and timeout on them. (Default 120/2 minutes)
std::string door::Door::location |
BBS Dropfile location
|
private |
Logfile
int door::Door::node |
BBS Dropfile node number
AnyOption door::Door::opt |
Commandline options parser.
ANSIColor door::Door::previous |
Previous ANSI-BBS colors and attributes sent. This is used to optimize ANSI Color output.
|
private |
Used by time_thread to know when a minute has passed.
|
private |
Allow us to stop the time_thread.
std::string door::Door::sysop |
BBS Dropfile sysop name
atomic<int> door::Door::time_left |
time left in minutes
|
private |
Thread used to update time_left and time_used.
atomic<int> door::Door::time_used |
time used in minutes
|
private |
Initial terminal defaults.
bool door::Door::track |
std::string door::Door::username |
BBS Dropfile username
int door::Door::width |
Detected screen width. Door::detect_unicode_and_screen