Xenith/xenith/ui/tui.h
2026-10-01 01:59:58 +07:00

107 lines
3.2 KiB
C++

#ifndef XENITH_TUI_H
#define XENITH_TUI_H
#include <iostream>
#include <sys/ioctl.h>
#include <unistd.h>
namespace ui
{
class Tui
{
public:
enum class Color : int {
DefaultText = 39,
DefaultBg = 49,
Black = 30,
Red = 31,
Green = 32,
Yellow = 33,
Blue = 34,
Magenta = 35,
Cyan = 36,
White = 37
};
Tui();
~Tui();
static void update();
bool is_running() const;
private:
int background = 49;
int foreground = 39;
bool running = true;
struct ConsoleSize {
int width = 80;
int height = 24;
};
struct border_charset
{
std::string_view top_left;
std::string_view top_right;
std::string_view bottom_left;
std::string_view bottom_right;
std::string_view bottom;
std::string_view top;
std::string_view vertical;
std::string_view bg;
};
inline static const border_charset border_clip {
.top_left = "╭",
.top_right = "╮",
.bottom_left = "╰",
.bottom_right = "╯",
.bottom = "─",
.top = "─",
.vertical = "│",
.bg = " ",
};
inline static const border_charset border_bold {
.top_left = "┏",
.top_right = "┓",
.bottom_left = "┗",
.bottom_right = "┛",
.bottom = "━",
.top = "━",
.vertical = "┃",
.bg = " ",
};
inline static const border_charset border_solid {
.top_left = "▟",
.top_right = "▙",
.bottom_left = "▜",
.bottom_right = "▛",
.bottom = "█",
.top = "█",
.vertical = "█",
.bg = " ",
};
inline static const border_charset border_btn {
.top_left = "▟",
.top_right = "▙",
.bottom_left = "▜",
.bottom_right = "▛",
.bottom = "█",
.top = "█",
.vertical = "█",
.bg = "█",
};
static ConsoleSize get_console_size();
void apply_color() const;
static void move_cursor(int x, int y);
static void clear();
static void draw_border(int w, int h, border_charset charset = border_clip, int x = 1, int y = 1);
static void hide_cursor();
static void show_cursor();
void set_background(Color clr);
void set_foreground(Color clr);
static void move_cursor_right(int n);
static void move_cursor_x(int col);
static void move_cursor_y(int row);
static void invert_color();
static void draw_button(int x, int y, int w, int h, std::string_view label, border_charset charset = border_solid);
void invert_color_off();
};
}
#endif