Compare commits
No commits in common. "bd5fe465a711bc5f73ce7f20be34f897498cf429" and "e0eba95ff49492eb0e3ee9afff4c73b6004deab3" have entirely different histories.
bd5fe465a7
...
e0eba95ff4
@ -24,7 +24,6 @@ public:
|
|||||||
Pager &operator-=(int number);
|
Pager &operator-=(int number);
|
||||||
|
|
||||||
Page &operator*();
|
Page &operator*();
|
||||||
|
|
||||||
Page *operator->();
|
Page *operator->();
|
||||||
|
|
||||||
void set(int number);
|
void set(int number);
|
||||||
|
31
src/Tui.cpp
31
src/Tui.cpp
@ -50,7 +50,6 @@ void printHelp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Tui::run() {
|
void Tui::run() {
|
||||||
clear_console();
|
|
||||||
std::cout << m_pager->str_pretty() << std::endl;
|
std::cout << m_pager->str_pretty() << std::endl;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
std::cout << "Enter a command: ";
|
std::cout << "Enter a command: ";
|
||||||
@ -63,34 +62,32 @@ void Tui::run() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool should_exit = false;
|
bool should_exit = false;
|
||||||
bool should_output = false;
|
auto visitor = [this, &should_exit]<typename T0>(T0 &&arg) {
|
||||||
auto visitor = [this, &should_exit, &should_output]<typename T0>(T0 &&arg) {
|
|
||||||
using T = std::decay_t<T0>;
|
using T = std::decay_t<T0>;
|
||||||
|
|
||||||
if constexpr (std::is_same_v<T, Command::None>) {
|
if constexpr (std::is_same_v<T, Command::None>) {
|
||||||
std::cout << "Invalid command!" << std::endl;
|
std::cout << "Invalid command!" << std::endl;
|
||||||
} else if constexpr (std::is_same_v<T, Command::Next>) {
|
} else if constexpr (std::is_same_v<T, Command::Next>) {
|
||||||
try {
|
try {
|
||||||
std::cout << "Fetching..." << std::endl;
|
|
||||||
m_pager += 1;
|
m_pager += 1;
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
should_output = true;
|
std::cout << m_pager->str_pretty() << std::endl;
|
||||||
} else if constexpr (std::is_same_v<T, Command::Previous>) {
|
} else if constexpr (std::is_same_v<T, Command::Previous>) {
|
||||||
try {
|
try {
|
||||||
std::cout << "Fetching..." << std::endl;
|
|
||||||
m_pager -= 1;
|
m_pager -= 1;
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
should_output = true;
|
std::cout << m_pager->str_pretty() << std::endl;
|
||||||
} else if constexpr (std::is_same_v<T, Command::Refresh>) {
|
} else if constexpr (std::is_same_v<T, Command::Refresh>) {
|
||||||
m_pager.clear();
|
m_pager.clear();
|
||||||
should_output = true;
|
std::cout << m_pager->str_pretty() << std::endl;
|
||||||
} else if constexpr (std::is_same_v<T, Command::Exit>) {
|
} else if constexpr (std::is_same_v<T, Command::Exit>) {
|
||||||
should_exit = true;
|
should_exit = true;
|
||||||
} else if constexpr (std::is_same_v<T, Command::Help>) {
|
} else if constexpr (std::is_same_v<T, Command::Help>) {
|
||||||
@ -99,32 +96,16 @@ void Tui::run() {
|
|||||||
const Command::Seek &seek = arg;
|
const Command::Seek &seek = arg;
|
||||||
const int number = seek.number;
|
const int number = seek.number;
|
||||||
try {
|
try {
|
||||||
std::cout << "Fetching..." << std::endl;
|
|
||||||
m_pager.seek(number);
|
m_pager.seek(number);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
should_output = true;
|
std::cout << m_pager->str_pretty() << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::visit(visitor, command);
|
std::visit(visitor, command);
|
||||||
if (should_exit)
|
if (should_exit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clear_console();
|
|
||||||
if (should_output)
|
|
||||||
std::cout << m_pager->str_pretty() << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tui::clear_console() {
|
|
||||||
const auto CMD =
|
|
||||||
#ifdef _WIN32 || _WIN64
|
|
||||||
"cls";
|
|
||||||
#else
|
|
||||||
"clear";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
system(CMD);
|
|
||||||
}
|
|
||||||
|
@ -16,10 +16,6 @@ public:
|
|||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:;
|
|
||||||
|
|
||||||
static void clear_console();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pager m_pager;
|
Pager m_pager;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user