Skip to content

Commit

Permalink
doc: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-go committed Sep 5, 2023
1 parent 30b4c3b commit a2e3f34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 8 additions & 15 deletions examples/simple_prompt.cc
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#include "qupp/prompt/prompt.h"

#include <chrono>
#include <iostream>
#include <thread>

void display_prompt() { std::cout << "Prompt from qupp!" << std::endl; }

void move_cursor_down(int n) { std::cout << "\033[" << n << "B" << std::flush; }

void move_cursor_up(int n) { std::cout << "\033[" << n << "A" << std::flush; }
#include <iostream> // std::cout, std::endl

int main() {

display_prompt();
move_cursor_down(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
move_cursor_up(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
qupp::prompt::Prompt prompt;
auto result = prompt.ask_for_input("This is a question:");
if (result.has_value()) {
std::cout << "You answered: " << result.value() << std::endl;
} else {
std::cout << "You did not answer." << std::endl;
}

return 0;
}
4 changes: 3 additions & 1 deletion src/io/unix/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Terminal &Terminal::get_instance() {
return instance;
}

void Terminal::print(const std::string &message) { std::cout << message; }
void Terminal::print(const std::string &message) {
std::cout << message << std::endl;
}

std::string Terminal::read() {
std::string input;
Expand Down

0 comments on commit a2e3f34

Please sign in to comment.