Busted.
This commit is contained in:
parent
addb7e6663
commit
635a7c79ec
@ -8,60 +8,20 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
|
#include <term.h>
|
||||||
|
#include <string.h>
|
||||||
#include "interactive.hpp"
|
#include "interactive.hpp"
|
||||||
|
|
||||||
namespace interactive {
|
namespace interactive {
|
||||||
|
|
||||||
int fullscreen_window::ncurses_streambuf::overflow(int c) {
|
int fullscreen_window::ncurses_streambuf::overflow(int c) {
|
||||||
if (c != EOF) {
|
if (c != EOF) {
|
||||||
// Check for ANSI escape sequence
|
buffer += static_cast<char>(c);
|
||||||
if (c == '\033') {
|
if (c == '\n') {
|
||||||
is_escape_sequence = true;
|
// Process buffer with proper escape sequence handling
|
||||||
escape_sequence = "\033";
|
|
||||||
} else if (is_escape_sequence) {
|
|
||||||
escape_sequence += static_cast<char>(c);
|
|
||||||
|
|
||||||
// Check if the escape sequence is complete
|
|
||||||
if (escape_sequence.size() >= 2 && escape_sequence[1] == '[' &&
|
|
||||||
(c == 'm' || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))) {
|
|
||||||
|
|
||||||
// Handle color codes
|
|
||||||
if (escape_sequence.back() == 'm') {
|
|
||||||
// Process color code
|
|
||||||
if (escape_sequence == "\033[0m") {
|
|
||||||
wattrset(win, A_NORMAL); // Reset attributes
|
|
||||||
} else if (escape_sequence == "\033[1;31m") {
|
|
||||||
wattron(win, COLOR_PAIR(1)); // Red
|
|
||||||
} else if (escape_sequence == "\033[1;32m") {
|
|
||||||
wattron(win, COLOR_PAIR(2)); // Green
|
|
||||||
} else if (escape_sequence == "\033[1;33m") {
|
|
||||||
wattron(win, COLOR_PAIR(3)); // Yellow
|
|
||||||
} else if (escape_sequence == "\033[1;34m") {
|
|
||||||
wattron(win, COLOR_PAIR(4)); // Blue
|
|
||||||
} else if (escape_sequence == "\033[1;35m") {
|
|
||||||
wattron(win, COLOR_PAIR(5)); // Magenta
|
|
||||||
} else if (escape_sequence == "\033[1;36m") {
|
|
||||||
wattron(win, COLOR_PAIR(6)); // Cyan
|
|
||||||
} else if (escape_sequence == "\033[1;37m") {
|
|
||||||
wattron(win, COLOR_PAIR(7)); // White
|
|
||||||
} else if (escape_sequence == "\033[90m") {
|
|
||||||
wattron(win, A_DIM | COLOR_PAIR(7)); // Dark grey
|
|
||||||
} else if (escape_sequence == "\033[38;5;142m") {
|
|
||||||
wattron(win, COLOR_PAIR(3) | A_DIM); // Dark yellow
|
|
||||||
} else if (escape_sequence == "\033[38;5;250m") {
|
|
||||||
wattron(win, COLOR_PAIR(7) | A_DIM); // Light grey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is_escape_sequence = false;
|
|
||||||
escape_sequence.clear();
|
|
||||||
}
|
|
||||||
} else if (c == '\n') {
|
|
||||||
wprintw(win, "%s", buffer.c_str());
|
wprintw(win, "%s", buffer.c_str());
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
} else {
|
|
||||||
buffer += static_cast<char>(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
@ -71,7 +31,9 @@ fullscreen_window::fullscreen_window(std::string title) {
|
|||||||
// Set locale for wide character support
|
// Set locale for wide character support
|
||||||
std::setlocale(LC_ALL, "");
|
std::setlocale(LC_ALL, "");
|
||||||
|
|
||||||
// Initialize ncurses
|
// Initialize ncurses with proper terminal capabilities
|
||||||
|
putenv(const_cast<char*>("TERM=xterm-256color"));
|
||||||
|
|
||||||
initscr();
|
initscr();
|
||||||
raw(); // Use raw mode for better control
|
raw(); // Use raw mode for better control
|
||||||
noecho();
|
noecho();
|
||||||
@ -83,15 +45,6 @@ fullscreen_window::fullscreen_window(std::string title) {
|
|||||||
start_color();
|
start_color();
|
||||||
use_default_colors();
|
use_default_colors();
|
||||||
|
|
||||||
// Initialize color pairs for ANSI colors
|
|
||||||
init_pair(1, COLOR_RED, -1); // Red
|
|
||||||
init_pair(2, COLOR_GREEN, -1); // Green
|
|
||||||
init_pair(3, COLOR_YELLOW, -1); // Yellow
|
|
||||||
init_pair(4, COLOR_BLUE, -1); // Blue
|
|
||||||
init_pair(5, COLOR_MAGENTA, -1); // Magenta
|
|
||||||
init_pair(6, COLOR_CYAN, -1); // Cyan
|
|
||||||
init_pair(7, COLOR_WHITE, -1); // White
|
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
// Create display window (takes up all but bottom 4 lines)
|
// Create display window (takes up all but bottom 4 lines)
|
||||||
@ -100,6 +53,10 @@ fullscreen_window::fullscreen_window(std::string title) {
|
|||||||
display_win = newwin(max_y - 4, max_x, 0, 0);
|
display_win = newwin(max_y - 4, max_x, 0, 0);
|
||||||
scrollok(display_win, TRUE);
|
scrollok(display_win, TRUE);
|
||||||
keypad(display_win, TRUE); // Enable keypad for display window
|
keypad(display_win, TRUE); // Enable keypad for display window
|
||||||
|
|
||||||
|
// Important: set terminal capabilities for this window
|
||||||
|
nodelay(display_win, TRUE);
|
||||||
|
|
||||||
wrefresh(display_win);
|
wrefresh(display_win);
|
||||||
|
|
||||||
// Create input window (bottom 4 lines)
|
// Create input window (bottom 4 lines)
|
||||||
|
@ -23,8 +23,6 @@ class fullscreen_window {
|
|||||||
private:
|
private:
|
||||||
WINDOW* win;
|
WINDOW* win;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
bool is_escape_sequence = false;
|
|
||||||
std::string escape_sequence;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int overflow(int c) override;
|
virtual int overflow(int c) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user