diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/CMakeLists.txt | 2 | ||||
-rw-r--r-- | frontend/cli.cpp | 35 | ||||
-rw-r--r-- | frontend/cli.h | 8 | ||||
-rw-r--r-- | frontend/main.cpp | 20 | ||||
-rw-r--r-- | frontend/strings.cpp | 28 | ||||
-rw-r--r-- | frontend/strings.h | 16 |
6 files changed, 109 insertions, 0 deletions
diff --git a/frontend/CMakeLists.txt b/frontend/CMakeLists.txt index dd74089..eafbe55 100644 --- a/frontend/CMakeLists.txt +++ b/frontend/CMakeLists.txt @@ -1,4 +1,6 @@ target_sources(main PUBLIC main.cpp + cli.cpp + strings.cpp ) diff --git a/frontend/cli.cpp b/frontend/cli.cpp new file mode 100644 index 0000000..352de4a --- /dev/null +++ b/frontend/cli.cpp @@ -0,0 +1,35 @@ +#include <cstdlib> +#include <cstdio> + +#include <readline/readline.h> +#include <readline/history.h> + +#include "cli.h" + +using namespace std; + +static void handle_line(const string & line) { + printf("CMD: %s\n", line.c_str()); +} + +string cli_readline() { + const char * PROMPT = "> "; + + char * input = readline(PROMPT); + // ctrl-d + if (input == NULL) exit(EXIT_SUCCESS); + string out = string(input); + if (out.size() > 0) add_history(input); + free(input); + + return out; +} + +void cli_main() { + while (1) { + string cmd = cli_readline(); + if (cmd.size() == 0) continue; + handle_line(cmd); + } +} + diff --git a/frontend/cli.h b/frontend/cli.h new file mode 100644 index 0000000..a069d7a --- /dev/null +++ b/frontend/cli.h @@ -0,0 +1,8 @@ +#pragma once + +#include <string> + +void cli_main(); + +std::string cli_readline(); + diff --git a/frontend/main.cpp b/frontend/main.cpp index acaf028..90cb1d2 100644 --- a/frontend/main.cpp +++ b/frontend/main.cpp @@ -1,7 +1,27 @@ +#include <memory> #include <cstdlib> #include <cstdio> +#include "backend/Dungeon.h" + +#include "cli.h" +#include "strings.h" + +using namespace std; + int main() { + auto dungeon = make_unique<Dungeon>(); + + print_string(strings::INTRO); + string filename = cli_readline(); + if (filename.size() == 0) { + printf("TODO: generate dungeon\n"); + } else { + printf("TODO: load %s\n", filename.c_str()); + } + + cli_main(); + return EXIT_SUCCESS; } diff --git a/frontend/strings.cpp b/frontend/strings.cpp new file mode 100644 index 0000000..0d4dee0 --- /dev/null +++ b/frontend/strings.cpp @@ -0,0 +1,28 @@ +#include "strings.h" + +using namespace std; + +void print_string(const char * str) { + printf("%s\n", wrap_string(str).c_str()); +} + +string wrap_string(const char * str) { + string out; + + for (; *str != '\0'; str++) { + if (str[0] == '\n') { + if (str[1] == '\n') { + out += "\n\n"; + str++; + } else { + out += " "; + } + continue; + } + + out += *str; + } + + return out; +} + diff --git a/frontend/strings.h b/frontend/strings.h new file mode 100644 index 0000000..910eaa8 --- /dev/null +++ b/frontend/strings.h @@ -0,0 +1,16 @@ +#pragma once + +#include <string> + +namespace strings { + +static constexpr const char * INTRO = R"(Voer de naam van een (.xml) bestand in +om hieruit een kerker te laden, of druk direct op ENTER om een kerker te +genereren.)"; + +} + +void print_string(const char *); + +std::string wrap_string(const char *); + |