Compare commits

...

4 Commits

Author SHA1 Message Date
ebfda949ea Catch no number exception 2025-01-24 13:00:30 +01:00
984d1f3aed headers 2025-01-24 12:59:22 +01:00
8710c31c1f Use char 2025-01-24 12:57:49 +01:00
f4eeb3d0e1 Don't crash on empty pages 2025-01-24 12:57:27 +01:00
9 changed files with 79 additions and 8 deletions

View File

@ -1,3 +1,11 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
#include "Command.h" #include "Command.h"
#include <iostream> #include <iostream>

View File

@ -1,3 +1,11 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
#pragma once #pragma once
#include <string> #include <string>

View File

@ -50,7 +50,9 @@ void italize_numbers(std::string &content, size_t leave_chars = 0) {
void pretty_format_page(std::string &content) { void pretty_format_page(std::string &content) {
content.insert(0, ansi::BOLD); content.insert(0, ansi::BOLD);
const size_t line_end = content.find("\n"); size_t line_end = content.find('\n');
if (line_end == std::string::npos)
line_end = content.size();
content.insert(line_end, ansi::CLEAR); content.insert(line_end, ansi::CLEAR);
italize_numbers(content, line_end + ansi::CLEAR.size()); italize_numbers(content, line_end + ansi::CLEAR.size());

View File

@ -1,3 +1,11 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
#include "Tui.h" #include "Tui.h"
#include <iostream> #include <iostream>
@ -46,7 +54,14 @@ void Tui::run() {
for (;;) { for (;;) {
std::cout << "Enter a command: "; std::cout << "Enter a command: ";
std::flush(std::cout); std::flush(std::cout);
const Command::Command command = Command::readCommand(); Command::Command command;
try {
command = Command::readCommand();
} catch (const Command::NoNumberException &e) {
std::cout << e.what() << std::endl;
continue;
}
bool should_exit = false; bool should_exit = false;
auto visitor = [this, &should_exit]<typename T0>(T0 &&arg) { auto visitor = [this, &should_exit]<typename T0>(T0 &&arg) {

View File

@ -1,3 +1,11 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
#pragma once #pragma once
#include "Page.hpp" #include "Page.hpp"

View File

@ -1,11 +1,17 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
namespace ansi #pragma once
{
#include <string> #include <string>
constexpr std::string_view BOLD = "\033[1m"; namespace ansi {
constexpr std::string_view ITALIC = "\033[3m"; constexpr std::string_view BOLD = "\033[1m";
constexpr std::string_view CLEAR = "\033[0m"; constexpr std::string_view ITALIC = "\033[3m";
constexpr std::string_view CLEAR = "\033[0m";
} // namespace ansi } // namespace ansi

View File

@ -1,3 +1,11 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
#include "Page.hpp" #include "Page.hpp"
#include "Tui.h" #include "Tui.h"

View File

@ -1,3 +1,11 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
#include "stringutil.hpp" #include "stringutil.hpp"
#include <algorithm> #include <algorithm>

View File

@ -1,3 +1,11 @@
// _____ _ _____
// |_ _|____ _| ||_ _|_ __
// | |/ _ \ \/ / __|| | \ \ / /
// | | __/> <| |_ | | \ V /
// |_|\___/_/\_\\__||_| \_/
// Author: Love Billenius <lovebillenius@disroot.org>
// License: GPL-3
#pragma once #pragma once
#include <string> #include <string>