fx.term: remove redundant printf implementation

This commit is contained in:
2026-05-25 17:31:40 +01:00
parent aea3f99859
commit c5eac75a0b
3 changed files with 67 additions and 964 deletions
+50 -10
View File
@@ -1,5 +1,6 @@
#include "../../tty.h"
#include <fx/encoding.h>
#include <fx/term/tty.h>
#include <stdio.h>
#include <stdlib.h>
@@ -102,9 +103,10 @@ static void init_tty(struct fx_tty *tty, FILE *in, FILE *out)
tcgetattr(fd, &tty->t_ios_default);
memcpy(&tty->t_ios_raw, &tty->t_ios_default, sizeof tty->t_ios_raw);
tty->t_ios_raw.c_iflag &= ~(ICRNL | IXON);
tty->t_ios_raw.c_iflag &= ~(BRKINT | INPCK | ISTRIP | ICRNL | IXON);
tty->t_ios_raw.c_oflag &= ~(OPOST);
tty->t_ios_raw.c_lflag &= ~(ECHO | ICANON | IEXTEN);
tty->t_ios_raw.c_cflag |= (CS8);
tty->t_ios_raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
tty->t_flags |= FX_TTY_INIT;
}
@@ -206,7 +208,8 @@ void fx_tty_reset_vmode(struct fx_tty *tty)
}
static int compare_colour(
const struct fx_tty_colour *a, const struct fx_tty_colour *b)
const struct fx_tty_colour *a,
const struct fx_tty_colour *b)
{
if (a->c_mode != b->c_mode) {
return -1;
@@ -243,7 +246,9 @@ static int compare_colour(
return 0;
}
static int compare_vmode(const struct fx_tty_vmode *a, const struct fx_tty_vmode *b)
static int compare_vmode(
const struct fx_tty_vmode *a,
const struct fx_tty_vmode *b)
{
if (a->v_attrib != b->v_attrib) {
return -1;
@@ -271,7 +276,9 @@ static void put_ansi_attrib(struct fx_tty *tty, const char *s)
}
static void set_attrib(
struct fx_tty *tty, enum fx_tty_attrib old, enum fx_tty_attrib new)
struct fx_tty *tty,
enum fx_tty_attrib old,
enum fx_tty_attrib new)
{
if (old == new) {
return;
@@ -309,7 +316,8 @@ static void set_attrib(
}
static void set_fg(
struct fx_tty *tty, const struct fx_tty_colour *old,
struct fx_tty *tty,
const struct fx_tty_colour *old,
const struct fx_tty_colour *new)
{
if (compare_colour(old, new) == 0) {
@@ -345,7 +353,8 @@ static void set_fg(
}
static void set_bg(
struct fx_tty *tty, const struct fx_tty_colour *old,
struct fx_tty *tty,
const struct fx_tty_colour *old,
const struct fx_tty_colour *new)
{
if (compare_colour(old, new) == 0) {
@@ -399,6 +408,24 @@ void fx_tty_set_vmode(struct fx_tty *tty, const struct fx_tty_vmode *vmode)
memcpy(&tty->t_vmode, vmode, sizeof *vmode);
}
static fx_keycode read_utf8(int fd, char header, int len)
{
char s[4] = {header, 0, 0, 0};
for (int i = 1; i < len; i++) {
char c;
int v = read(fd, &c, 1);
if (v != 1) {
return FX_KEY_EOF;
}
s[i] = c;
}
return fx_wchar_utf8_codepoint_decode(s);
}
fx_keycode fx_tty_read_key(struct fx_tty *tty)
{
char c;
@@ -423,6 +450,11 @@ fx_keycode fx_tty_read_key(struct fx_tty *tty)
return FX_TTY_CTRL_KEY(c + 'a' - 1);
}
int utf8_len = fx_wchar_utf8_header_decode(c);
if (utf8_len > 1) {
return read_utf8(fd, c, utf8_len);
}
if (c != 0x1b) {
return c;
}
@@ -458,7 +490,10 @@ fx_keycode fx_tty_read_key(struct fx_tty *tty)
return c;
}
void fx_tty_move_cursor_x(struct fx_tty *tty, enum fx_tty_position_base base, int pos)
void fx_tty_move_cursor_x(
struct fx_tty *tty,
enum fx_tty_position_base base,
int pos)
{
if (base == FX_TTY_POS_CURSOR && pos < 0 && pos >= -4) {
for (int i = 0; i > pos; i--) {
@@ -487,7 +522,10 @@ void fx_tty_move_cursor_x(struct fx_tty *tty, enum fx_tty_position_base base, in
}
}
void fx_tty_move_cursor_y(struct fx_tty *tty, enum fx_tty_position_base base, int pos)
void fx_tty_move_cursor_y(
struct fx_tty *tty,
enum fx_tty_position_base base,
int pos)
{
if (base == FX_TTY_POS_START) {
/* we don't need this functionality right now */
@@ -528,7 +566,9 @@ void fx_tty_clear(struct fx_tty *tty, enum fx_tty_clear_mode mode)
}
enum fx_status fx_tty_get_dimensions(
struct fx_tty *tty, unsigned int *w, unsigned int *h)
struct fx_tty *tty,
unsigned int *w,
unsigned int *h)
{
if (!(tty->t_flags & FX_TTY_INTERACTIVE)) {
return -1;