Bugz Door Project
Classes | Typedefs | Enumerations | Functions | Variables
door Namespace Reference

The BBS door project. This is an attempt at writing a C++ BBS door toolkit. More...

Classes

class  ANSIColor
 Foreground, Background and Attributes. More...
 
struct  box_styles
 
class  Clrscr
 Clear the screen. More...
 
class  ColorOutput
 This holds an ANSIColor and text position + length. More...
 
class  Door
 
class  Goto
 ANSI Goto X, Y position. More...
 
class  IConv
 Converts from one encoding to another. Uses iconv (international conversion) API. More...
 
class  Line
 Text and ANSIColor. More...
 
class  Menu
 
class  NewLine
 CR+LF. More...
 
class  Panel
 
class  Render
 Rendering a string with ANSIColor. More...
 
class  Screen
 

Typedefs

typedef std::function< Render(const std::string &)> renderFunction
 Render output function. More...
 
typedef std::function< std::string(void)> updateFunction
 

Enumerations

enum  COLOR : std::int8_t {
  COLOR::BLACK, COLOR::RED, COLOR::GREEN, COLOR::BROWN,
  COLOR::YELLOW = 3, COLOR::BLUE, COLOR::MAGENTA, COLOR::CYAN,
  COLOR::WHITE
}
 The colors available under ANSI-BBS. More...
 
enum  ATTR : std::int8_t {
  ATTR::RESET, ATTR::BOLD, ATTR::BRIGHT = 1, ATTR::BLINK = 5,
  ATTR::INVERSE = 7
}
 ANSI-BBS text attributes. More...
 
enum  Justify { NONE, LEFT, RIGHT, CENTER }
 
enum  BorderStyle {
  BorderStyle::NONE, BorderStyle::SINGLE, BorderStyle::DOUBLE, BorderStyle::SINGLE_DOUBLE,
  BorderStyle::DOUBLE_SINGLE, BorderStyle::BLANK
}
 

Functions

std::ostream & operator<< (std::ostream &os, const ANSIColor &c)
 
void to_lower (std::string &text)
 convert string to lowercase More...
 
bool replace (std::string &str, const std::string &from, const std::string &to)
 Replaces one string with another once. More...
 
bool replace (std::string &str, const char *from, const char *to)
 Replace all instances of from with to. More...
 
void sig_handler (int signal)
 Signal handler for detecting hangup/broken pipe. More...
 
void cp437toUnicode (std::string input, std::string &out)
 Convert from CP437 to unicode. More...
 
void cp437toUnicode (const char *input, std::string &out)
 Convert from CP437 to unicode. More...
 
std::ostream & operator<< (std::ostream &os, const Clrscr &clr)
 
std::ostream & operator<< (std::ostream &os, const NewLine &nl)
 
std::ostream & operator<< (std::ostream &os, const Goto &g)
 
std::ostream & operator<< (std::ostream &os, const Line &l)
 
std::ostream & operator<< (std::ostream &os, const Panel &p)
 Output panel to stream. More...
 
std::ostream & operator<< (std::ostream &os, const Screen &s)
 Outputs screen to stream. More...
 

Variables

ANSIColor reset (ATTR::RESET)
 reset colors to normal More...
 
std::list< char > pushback
 pushback buffer for keys. More...
 
bool unicode = false
 Was unicode detected?
 
bool full_cp437 = false
 Was full CP437 detected? More...
 
bool debug_capture = false
 Capture the output for debugging. More...
 
Clrscr cls
 
NewLine nl
 
const char SaveCursor [] = "\x1b[s"
 ANSI Save Cursor position command.
 
const char RestoreCursor [] = "\x1b[u"
 ANSI Restore Cursor position command.
 
renderFunction rBlueYellow
 BlueYellow Render example function. More...
 
struct box_styles UBOXES []
 Unicode box characters. More...
 
struct box_styles BOXES []
 CP437 box characters. More...
 
const char * JOIN [2][2][2]
 CP437 box line joining data. More...
 
const char * UJOIN [2][2][2]
 Unicode box line joining data SINGLE 0, DOUBLE 1 Join Border to Line, 0 is Left, 1 is Right. More...
 

Detailed Description

The BBS door project. This is an attempt at writing a C++ BBS door toolkit.

Typedef Documentation

◆ renderFunction

typedef std::function<Render(const std::string &)> door::renderFunction

Render output function.

This defines the render output function. Given the line text, we output the color codes needs to display the line.

door::ANSIColor upperColor, lowerColor;
door::RenderFunction render = [upperColor, lowerColor]
(const std::string &text) -> door::Render {
door::Render r(text);
for (char const &c : text) {
if (std::isupper(c))
r.append(upperColor);
else
r.append(lowerColor);
}
return r;
};

◆ updateFunction

typedef std::function<std::string(void)> door::updateFunction

This defines the update function.

This updates the text.

int score = 0;
door::updateFunction updater = [](void) -> std::string {
std::string text = "Score: ";
text += std::to_string(score);
return text;
};
fancyLine.setUpdater(updater);

Enumeration Type Documentation

◆ ATTR

enum door::ATTR : std::int8_t
strong

ANSI-BBS text attributes.

Enumerator
RESET 

RESET forces all attributes (and Colors) to be sent.

BOLD 

BOLD is the same as BRIGHT.

BRIGHT 

BRIGHT is the same as BOLD.

BLINK 

SLOW BLINK.

INVERSE 

INVERSE is Background on Foreground.

◆ BorderStyle

enum door::BorderStyle
strong

The different Borders supported by Panel.

Enumerator
NONE 

NONE (0)

SINGLE 

SINGLE (1)

DOUBLE 

DOUBLE (2)

SINGLE_DOUBLE 

SINGLE top DOUBLE side (3)

DOUBLE_SINGLE 

DOUBLE top SINGLE side (4)

BLANK 

BLANK (5)

◆ COLOR

enum door::COLOR : std::int8_t
strong

The colors available under ANSI-BBS.

ANSI Color codes

Enumerator
BLACK 

BLACK (0)

RED 

RED (1)

GREEN 

GREEN (2)

BROWN 

BROWN (3)

YELLOW 

YELLOW (3)

BLUE 

BLUE (4)

MAGENTA 

MAGENTA (5)

CYAN 

CYAN (6)

WHITE 

WHITE (7)

◆ Justify

enum door::Justify
strong
Deprecated:
Not used

Function Documentation

◆ cp437toUnicode() [1/2]

void door::cp437toUnicode ( const char *  input,
std::string &  out 
)

Convert from CP437 to unicode.

Parameters
input
out

◆ cp437toUnicode() [2/2]

void door::cp437toUnicode ( std::string  input,
std::string &  out 
)

Convert from CP437 to unicode.

Parameters
input
out

◆ operator<<() [1/7]

std::ostream& door::operator<< ( std::ostream &  os,
const ANSIColor c 
)

This converts ANSI COLOR and ATTR to ANSI codes understood by the Door output class.

◆ operator<<() [2/7]

std::ostream& door::operator<< ( std::ostream &  os,
const Clrscr clr 
)

Clear the screen using ANSI codes.

Not all systems home the cursor after clearing the screen. We automatically home the cursor as well.

Parameters
osstd::ostream&
clrconst Clrscr&
Returns
std::ostream&

◆ operator<<() [3/7]

std::ostream& door::operator<< ( std::ostream &  os,
const Goto g 
)

Output the ANSI codes to position the cursor to the given y,x position.

Todo:

Optimize the ANSI goto string output.

Update the Door object so it know where the cursor is positioned.

Parameters
osstd::ostream
gconst Goto
Returns
std::ostream&

◆ operator<<() [4/7]

std::ostream& door::operator<< ( std::ostream &  os,
const Line l 
)

Output Line

This looks for padding and paddingColor. This uses the render function if set.

Parameters
osstd::ostream
lconst Line &
Returns
std::ostream&

◆ operator<<() [5/7]

std::ostream& door::operator<< ( std::ostream &  os,
const NewLine nl 
)

Output Newline + CarriageReturn

Parameters
osstd::ostream
nlconst NewLine
Returns
std::ostream&

◆ operator<<() [6/7]

std::ostream& door::operator<< ( std::ostream &  os,
const Panel p 
)

Output panel to stream.

This uses the Panel.x, Panel.y to render the panel using ANSI control codes. Border style is considered, and wether or not we are using unicode. Colors of the border, and lines use their color or their renderFunction.

Parameters
os
p
Returns
std::ostream&

◆ operator<<() [7/7]

std::ostream& door::operator<< ( std::ostream &  os,
const Screen s 
)

Outputs screen to stream.

This iterates over panels, and outputs them. See door::Panel

Parameters
[in,out]osStream
[in]sScreen to send
Returns
std::ostream&

◆ replace() [1/2]

bool door::replace ( std::string &  str,
const char *  from,
const char *  to 
)

Replace all instances of from with to.

Parameters
str
from
to
Returns
true
false

◆ replace() [2/2]

bool door::replace ( std::string &  str,
const std::string &  from,
const std::string &  to 
)

Replaces one string with another once.

Returns true if replaced.

Parameters
[in,out]strString to modify
[in]fromString to search for
[in]toString to replace with
Returns
true
false

◆ sig_handler()

void door::sig_handler ( int  signal)

Signal handler for detecting hangup/broken pipe.

Parameters
signal

◆ to_lower()

void door::to_lower ( std::string &  text)

convert string to lowercase

Parameters
text

Variable Documentation

◆ BOXES

struct box_styles door::BOXES[]

CP437 box characters.

top-left, top-right, top, side, bottom-left, bottom-right, middle-left, middle-right See BorderStyle for the order the boxes are in.

◆ cls

Clrscr door::cls

Clear the BBS terminal.

Examples
menu-example.cpp.

◆ debug_capture

bool door::debug_capture = false

Capture the output for debugging.

This is used by the tests.

◆ full_cp437

bool door::full_cp437 = false

Was full CP437 detected?

This is for full CP437 support, meaning it also supports hearts, diamonds, spades, clubs char(3)..char(6). These are sometimes ignored by CP437 translation programs as control codes.

◆ JOIN

const char* door::JOIN[2][2][2]
Initial value:
= {{
{"\xc3", "\xb4"},
{"\xc6", "\xb5"}
},
{
{"\xc7", "\xb6"},
{"\xcc", "\xb9"},
}}

CP437 box line joining data.

SINGLE 0, DOUBLE 1 Join Border to Line, 0 is Left, 1 is Right.

◆ nl

NewLine door::nl

CRLF

Examples
menu-example.cpp.

◆ pushback

std::list< char > door::pushback

pushback buffer for keys.

This allows us to peek ahead and push back characters we're not interested it. It also allows us to test the Door::getkey function.

◆ rBlueYellow

renderFunction door::rBlueYellow
Initial value:
= [](const std::string &txt) -> Render {
Render r(txt);
ANSIColor blue(COLOR::BLUE, ATTR::BOLD);
ANSIColor cyan(COLOR::YELLOW, ATTR::BOLD);
for (char const &c : txt) {
if (isupper(c))
r.append(blue);
else
r.append(cyan);
}
return r;
}

BlueYellow Render example function.

Example BlueYellow renderFunction.

◆ reset

ANSIColor door::reset

reset colors to normal

This resets the colors to normal state.

Examples
menu-example.cpp.

◆ UBOXES

struct box_styles door::UBOXES[]
Initial value:
= {{"\u250c", "\u2510", "\u2500", "\u2502", "\u2514",
"\u2518", "\u251c", "\u2524"},
{"\u2554", "\u2557", "\u2550", "\u2551", "\u255a",
"\u255d", "\u2560", "\u2563"},
{"\u2553", "\u2556", "\u2500", "\u2551", "\u2559",
"\u255c", "\u255f", "\u2562"},
{"\u2552", "\u2555", "\u2550", "\u2502", "\u2558",
"\u255b", "\u255e", "\u2561"}}

Unicode box characters.

use https://en.wikipedia.org/wiki/Code_page_437 for translations between CP437 and unicode symbols.

This holds the characters needed to render the different box styles. tl tr top side bl br ml mr top-left, top-right, top, side, bottom-left, bottom-right, middle-left, middle-right See BorderStyle for the order the boxes are in.

◆ UJOIN

const char* door::UJOIN[2][2][2]
Initial value:
= {{
{"\u251c", "\u2524"},
{"\u255e", "\u2561"}
},
{
{"\u255f", "\u2562"},
{"\u2560", "\u2563"},
}}

Unicode box line joining data SINGLE 0, DOUBLE 1 Join Border to Line, 0 is Left, 1 is Right.

door::ANSIColor
Foreground, Background and Attributes.
Definition: door.h:137
door::updateFunction
std::function< std::string(void)> updateFunction
Definition: door.h:374
door::Render
Rendering a string with ANSIColor.
Definition: door.h:319