Tidak Ada Deskripsi

Steve Thielemann db8c05d6c9 Added ANSIColor constexpr ctor. 2 tahun lalu
examples b7fe690d8b Better working docs, example menu. 3 tahun lalu
utf8 b3078b0478 Updated: Fixed issues with unicode characters. 3 tahun lalu
.gitignore b7fe690d8b Better working docs, example menu. 3 tahun lalu
CMakeLists.txt 97af717b00 Added progress Bar. 3 tahun lalu
LICENSE d6f2177d45 Added MIT License 3 tahun lalu
LICENSE_anyoption e250135c45 Initial commit. 3 tahun lalu
README.md d090086933 Fixed markdown code fence for cpp highlighting. 3 tahun lalu
ansicolor.cpp db8c05d6c9 Added ANSIColor constexpr ctor. 2 tahun lalu
anyoption.cpp e250135c45 Initial commit. 3 tahun lalu
anyoption.h e250135c45 Initial commit. 3 tahun lalu
bar.cpp e555be1e34 Working BarLine watch routines. 3 tahun lalu
door.cpp 7a1f195397 Add error handlying when file not found. 3 tahun lalu
door.h db8c05d6c9 Added ANSIColor constexpr ctor. 2 tahun lalu
doxy.config df4f375144 Updating documentation. 3 tahun lalu
lines.cpp b7fe690d8b Better working docs, example menu. 3 tahun lalu
make_docs.sh 23f71ba696 Updated door_example. Build the example. 3 tahun lalu
panel.cpp d860f42d83 Set color to black, when displaying menu. 3 tahun lalu
test-door.cpp db8c05d6c9 Added ANSIColor constexpr ctor. 2 tahun lalu
utf8.h b3078b0478 Updated: Fixed issues with unicode characters. 3 tahun lalu
utf8cpp.html b3078b0478 Updated: Fixed issues with unicode characters. 3 tahun lalu

README.md

Door++

Wecome to Door++, a modern BBS Door development kit written in C++

Getting Started

Clone the door++ project into a sub-directory of your project. In your project CmakeLists.txt file, add add_subdirectory(door++). Under the add_executable(your-door your-door.cpp) line, add target_link_libraries(your-door door++ pthread)`.

In main, create the door instance:

#include "door.h"

int main( int argc, char * argv[] ) {
    door::Door door("your-door", argc, argv);

    door << "Welcome to Door++" << door::nl;
}

Advanced Features of Door++

  • door::Line

A line is text that can be updated, and can be colorized by the use of a rendering function.

If you want all uppercase letters one color, and lowercase another. That can be done.

/*
 * Custom line rendering fuction.
 * This allows for the status to be one color, and the value to be another.
 * "Score: 500"  
 * "Score:" would be status color, "500" would be value color.
 */
door::renderFunction statusValue(door::ANSIColor status,
                                 door::ANSIColor value) {
  door::renderFunction rf = [status,
                             value](const std::string &txt) -> door::Render {
    door::Render r(txt);
    size_t pos = txt.find(':');
    if (pos == std::string::npos) {
      for (char const &c : txt) {
        if (std::isdigit(c))
          r.append(value);
        else
          r.append(status);
      }
    } else {
      pos++;
      r.append(status, pos);
      r.append(value, txt.length() - pos);
    }
    return r;
  };
  return rf;
}

door::ANSIColor statusColor(door::COLOR::WHITE, door::COLOR::BLUE,
                            door::ATTR::BOLD);
door::ANSIColor valueColor(door::COLOR::YELLOW, door::COLOR::BLUE,
                            door::ATTR::BOLD);
door::renderFunction svRender = statusValue(statusColor, valueColor);

// build the actual line here
std::unique_ptr<door::Line> scoreLine = std::make_unique<door::Line>("Score: 0", 50);
scoreLine->setRender(svRender);

// Make the scoreLine automatically update when score changes.
door::updateFunction scoreUpdate = [score](void) -> std::string {
    std::string text = "Score: ";
    text.append(std::to_string(score));
    return text;
};

scoreLine->setUpdater(scoreUpdate);
  • door::Panel

A Panel is a group of lines with a known position.

std::unique_ptr<door::Panel> panel = std::make_unique<door::Panel>(50);
panel->setStyle(door::BorderStyle::NONE);
// add lines to the panel
panel->addLines(std::move(scoreLine));

panel->set(5, 5);
panel->update();
door << panel;
  • door::Menu

A Panel that displays options for the user to select

// Define a menu starting at 5, 5 with width 25
door::Menu menu(5, 5, 25);

// Set border color
door::ANSIColor border_color(door::COLOR::CYAN, door::COLOR::BLUE);
m.setColor(border_color);

// Set the Menu Title
door::Line mtitle("Main Menu");
door::ANSIColor title_color(door::COLOR::CYAN, door::COLOR::BLUE, door::ATTR::BOLD);
mtitle.setColor(title_color);
mtitle.setPadding(" ", title_color);
m.setTitle(std::make_unique<door::Line>(mtitle), 1);

// Define colors for the menu
// menu line selected
m.setRender(true, door::Menu::makeRender(
                  door::ANSIColor(door::COLOR::CYAN, door::ATTR::BOLD),
                  door::ANSIColor(door::COLOR::BLUE, door::ATTR::BOLD),
                  door::ANSIColor(door::COLOR::CYAN, door::ATTR::BOLD),
                  door::ANSIColor(door::COLOR::BLUE, door::ATTR::BOLD)));

// menu line unselected
m.setRender(false, door::Menu::makeRender(
                   door::ANSIColor(door::COLOR::YELLOW, door::COLOR::BLUE,
                   door::ATTR::BOLD),
                   door::ANSIColor(door::COLOR::WHITE, door::COLOR::BLUE,
                   door::ATTR::BOLD),
                   door::ANSIColor(door::COLOR::YELLOW, door::COLOR::BLUE,
                   door::ATTR::BOLD),
                   door::ANSIColor(door::COLOR::CYAN, door::COLOR::BLUE,
                   door::ATTR::BOLD)));

// Build the menu
// First char is [ char ], followed by the text.
// The arrow keys can be used to select the menu option, or
// hitting the character.

m.addSelection('P', "Play Cards");
m.addSelection('S', "View Scores");
m.addSelection('C', "Configure");
m.addSelection('H', "Help");
m.addSelection('A', "About this game");
m.addSelection('Q', "Quit");

int r;

// Render the menu and prompt for input
r = m.choose(door);

if (r < 0) {
    // timeout or out of time
}

if ( r == 1 ) {
    // Play Cards
}
...