tidying
This commit is contained in:
parent
cb76aa1e47
commit
5baccdd8ae
0
.gitmodules
vendored
Normal file
0
.gitmodules
vendored
Normal file
@ -5,15 +5,57 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <algorithm>
|
||||
#include <regex>
|
||||
#include "interactive.hpp"
|
||||
|
||||
namespace interactive {
|
||||
|
||||
// Helper function to convert ANSI color codes to ncurses attributes
|
||||
int ansi_to_ncurses_attr(const std::string& ansi_code) {
|
||||
if (ansi_code == "0") return A_NORMAL;
|
||||
if (ansi_code == "1") return A_BOLD;
|
||||
|
||||
// Handle colors
|
||||
if (ansi_code == "1;31") return A_BOLD | COLOR_PAIR(2); // Red
|
||||
if (ansi_code == "1;32") return A_BOLD | COLOR_PAIR(3); // Green
|
||||
if (ansi_code == "1;33") return A_BOLD | COLOR_PAIR(4); // Yellow
|
||||
if (ansi_code == "1;34") return A_BOLD | COLOR_PAIR(5); // Blue
|
||||
if (ansi_code == "1;35") return A_BOLD | COLOR_PAIR(6); // Magenta
|
||||
if (ansi_code == "1;36") return A_BOLD | COLOR_PAIR(7); // Cyan
|
||||
if (ansi_code == "1;37") return A_BOLD | COLOR_PAIR(8); // White
|
||||
if (ansi_code == "90") return COLOR_PAIR(9); // Dark Grey
|
||||
if (ansi_code == "38;5;142") return COLOR_PAIR(10); // Dark Yellow
|
||||
if (ansi_code == "38;5;250") return COLOR_PAIR(11); // Light Grey
|
||||
|
||||
return A_NORMAL;
|
||||
}
|
||||
|
||||
int fullscreen_window::ncurses_streambuf::overflow(int c) {
|
||||
if (c != EOF) {
|
||||
buffer += static_cast<char>(c);
|
||||
if (c == '\n') {
|
||||
wprintw(win, "%s", buffer.c_str());
|
||||
// Process ANSI escape sequences
|
||||
std::string processed;
|
||||
size_t pos = 0;
|
||||
while (pos < buffer.length()) {
|
||||
if (buffer[pos] == '\033' && pos + 1 < buffer.length() && buffer[pos + 1] == '[') {
|
||||
// Found ANSI escape sequence
|
||||
size_t end = buffer.find('m', pos);
|
||||
if (end != std::string::npos) {
|
||||
std::string ansi_code = buffer.substr(pos + 2, end - pos - 2);
|
||||
int ncurses_attr = ansi_to_ncurses_attr(ansi_code);
|
||||
wattron(win, ncurses_attr);
|
||||
pos = end + 1;
|
||||
} else {
|
||||
// Invalid ANSI sequence, just print it
|
||||
processed += buffer[pos++];
|
||||
}
|
||||
} else {
|
||||
processed += buffer[pos++];
|
||||
}
|
||||
}
|
||||
|
||||
wprintw(win, "%s", processed.c_str());
|
||||
wrefresh(win);
|
||||
buffer.clear();
|
||||
}
|
||||
@ -24,6 +66,22 @@ int fullscreen_window::ncurses_streambuf::overflow(int c) {
|
||||
fullscreen_window::fullscreen_window(std::string title) {
|
||||
// Initialize ncurses
|
||||
initscr();
|
||||
start_color();
|
||||
use_default_colors();
|
||||
|
||||
// Initialize color pairs
|
||||
init_pair(1, COLOR_BLACK, -1); // Black
|
||||
init_pair(2, COLOR_RED, -1); // Red
|
||||
init_pair(3, COLOR_GREEN, -1); // Green
|
||||
init_pair(4, COLOR_YELLOW, -1); // Yellow
|
||||
init_pair(5, COLOR_BLUE, -1); // Blue
|
||||
init_pair(6, COLOR_MAGENTA, -1); // Magenta
|
||||
init_pair(7, COLOR_CYAN, -1); // Cyan
|
||||
init_pair(8, COLOR_WHITE, -1); // White
|
||||
init_pair(9, COLOR_BLACK, -1); // Dark Grey
|
||||
init_pair(10, COLOR_YELLOW, -1); // Dark Yellow
|
||||
init_pair(11, COLOR_WHITE, -1); // Light Grey
|
||||
|
||||
raw(); // Use raw mode for better control
|
||||
noecho();
|
||||
keypad(stdscr, TRUE); // Enable keypad
|
||||
@ -31,6 +89,15 @@ fullscreen_window::fullscreen_window(std::string title) {
|
||||
set_escdelay(25); // Set ESC delay to 25ms
|
||||
refresh();
|
||||
|
||||
// Initialize color pairs
|
||||
init_pair(12, COLOR_RED, -1);
|
||||
init_pair(13, COLOR_GREEN, -1);
|
||||
init_pair(14, COLOR_YELLOW, -1);
|
||||
init_pair(15, COLOR_BLUE, -1);
|
||||
init_pair(16, COLOR_MAGENTA, -1);
|
||||
init_pair(17, COLOR_CYAN, -1);
|
||||
init_pair(18, COLOR_WHITE, -1);
|
||||
|
||||
// Create display window (takes up all but bottom 4 lines)
|
||||
int max_y, max_x;
|
||||
getmaxyx(stdscr, max_y, max_x);
|
||||
|
Loading…
x
Reference in New Issue
Block a user