Skip to content

Commit

Permalink
Add default commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kshxtij committed Oct 26, 2023
1 parent 3c8784e commit 9c5711d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- `eigen3`
- `boost`
- `rapidjson`
- `ncurses`

## Usage

Expand Down
19 changes: 17 additions & 2 deletions lib/debug/repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace hyped::debug {

Repl::Repl(core::ILogger &logger, Terminal &terminal) : logger_(logger), terminal_(terminal)
{
logger_.log(core::LogLevel::kDebug, "Repl::Repl()");
addHelpCommand();
addQuitCommand();
}

void Repl::run()
Expand Down Expand Up @@ -81,7 +82,6 @@ void Repl::addCommand(std::unique_ptr<ICommand> command)

void Repl::printHelp()
{
logger_.log(core::LogLevel::kDebug, "Repl::printHelp()");
for (auto &command : commands_) {
logger_.log(core::LogLevel::kDebug,
"%s: %s",
Expand All @@ -90,4 +90,19 @@ void Repl::printHelp()
}
}

void Repl::addHelpCommand(){
addCommand(std::make_unique<ICommand>("help", "Print this help message", [this]() -> core::Result {
printHelp();
return core::Result::kSuccess;
}));
}

void Repl::addQuitCommand(){
addCommand(std::make_unique<ICommand>("quit", "Quit the program", [this]() -> core::Result {
terminal_.quit();
exit(0);
return core::Result::kSuccess;
}));
}

} // namespace hyped::debug
3 changes: 3 additions & 0 deletions lib/debug/repl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Repl {
void addCommand(std::unique_ptr<ICommand> command);
void printHelp();

void addHelpCommand();
void addQuitCommand();

private:
core::ILogger &logger_;
Terminal terminal_;
Expand Down
21 changes: 13 additions & 8 deletions lib/debug/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ class Terminal {
public:
void initialize_window()
{
initscr();
initscr(); // initialize ncurses
cbreak(); // break with ctrl + c
noecho(); // dont echo inputs

int height, width, start_y, start_x;
getmaxyx(stdscr, height, width);
getmaxyx(stdscr, height, width); // get terminal size

start_y = 0;
start_x = 0;

WINDOW *window = newwin(height, width, start_y, start_x);
WINDOW *window = newwin(height, width, start_y, start_x); // create window

keypad(window, true); // Use keypad
nodelay(window, true);
nodelay(window, true); // Non-blocking getch
scrollok(window, TRUE); // Enable scroll

set_escdelay(25);
set_escdelay(25); // Set escape delay to 25ms

wclrtobot(window);
wrefresh(window);
window_ = window;
wclrtobot(window); // Clear window
wrefresh(window); // Refresh window
window_ = window;
};

~Terminal() {}
Expand Down Expand Up @@ -110,6 +110,11 @@ class Terminal {
}
return std::make_pair(KeyPress::kNone, ' ');
}

void quit()
{
endwin();
}

private:
WINDOW *window_;
Expand Down

0 comments on commit 9c5711d

Please sign in to comment.