Major update

- Add an IO system to hijack a bit of the terminal.
- Other minor fixes.
This commit is contained in:
2026-08-22 22:57:18 +01:00
parent 1f3b53753a
commit 3563324a1c
13 changed files with 621 additions and 43 deletions
+16
View File
@@ -7,4 +7,20 @@ enum struct Direction : uint8_t {
Forward,
Backward
};
inline static bool write_all(int fd, const void *data, size_t len) {
const char *p = (const char *)data;
while (len > 0) {
ssize_t n = write(fd, p, len);
if (n > 0) {
p += n;
len -= (size_t)n;
continue;
}
if (n == -1 && errno == EINTR)
continue;
return false;
}
return true;
}
} // namespace bed::internal
+81
View File
@@ -0,0 +1,81 @@
#pragma once
#include "definitions.h"
#include "pch.h"
namespace bed::internal::io {
struct KeyEvent {
enum struct KeyType {
NONE,
CHAR,
SPECIAL,
MOUSE,
PASTE
};
enum struct SpecialKey {
UP,
DOWN,
LEFT,
RIGHT,
DELETE,
UNKNOWN
};
enum struct Modifier {
NONE,
SHIFT,
ALT,
CTRL,
CTRL_ALT
};
enum struct MouseState {
PRESS,
RELEASE
};
KeyType type = KeyType::NONE;
std::string text;
SpecialKey special_key = SpecialKey::UNKNOWN;
Modifier modifier = Modifier::NONE;
MouseState mouse_state = MouseState::PRESS;
uint16_t mouse_x = 0;
uint16_t mouse_y = 0;
};
struct IO {
IO();
~IO();
IO(const IO &) = delete;
IO &operator=(const IO &) = delete;
void enable_mouse();
void disable_mouse();
std::pair<uint16_t, uint16_t> terminal_size();
std::pair<uint16_t, uint16_t> cursor_position();
void move_cursor(uint16_t row, uint16_t col);
std::pair<std::string, bool> get_command(BEd &);
KeyEvent read_key();
private:
static termios orig_termios;
static bool cleaned;
static void cleanup();
std::deque<char> input_queue;
bool get_next_byte(char &out);
void enqueue_bytes(const std::string &bytes);
static int utf8_seq_len(uint8_t byte);
std::string read_next_unit();
bool read_bracketed_paste(std::string &out);
KeyEvent parse_mouse(const std::string &buf);
KeyEvent parse_escape(const std::string &buf);
};
} // namespace bed::internal::io
-13
View File
@@ -5,19 +5,6 @@
#include "pch.h"
namespace bed::internal::theme {
struct Highlight {
enum : uint8_t {
None = 0,
Bold = 1 << 0,
Italic = 1 << 1,
Strikethrough = 1 << 2,
Underline = 1 << 3,
};
uint32_t fg;
uint32_t bg;
uint8_t flags;
};
struct Theme {
std::array<Highlight, internal::syntax::Token::Count> hl;