meta: rename to fx
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int z__b_stream_is_tty(FILE *fp)
|
||||
int z__fx_stream_is_tty(FILE *fp)
|
||||
{
|
||||
return isatty(fileno(fp));
|
||||
}
|
||||
|
||||
int z__b_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h)
|
||||
int z__fx_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h)
|
||||
{
|
||||
if (!isatty(fileno(fp))) {
|
||||
return -1;
|
||||
@@ -33,7 +33,7 @@ int z__b_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int z__b_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
|
||||
int z__fx_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
|
||||
{
|
||||
if (!isatty(fileno(in)) || !isatty(fileno(out))) {
|
||||
return -1;
|
||||
@@ -66,7 +66,7 @@ int z__b_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
int z__fx_stream_set_modifier(FILE *fp, enum z__fx_stream_modifier mod)
|
||||
{
|
||||
char buf[128];
|
||||
int buf_i = 0;
|
||||
@@ -75,7 +75,7 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
buf[buf_i++] = '\033';
|
||||
buf[buf_i++] = '[';
|
||||
|
||||
if (mod & Z__B_STREAM_MOD_RESET) {
|
||||
if (mod & Z__FX_STREAM_MOD_RESET) {
|
||||
buf[buf_i++] = '0';
|
||||
buf[buf_i++] = 'm';
|
||||
buf[buf_i++] = '\0';
|
||||
@@ -84,7 +84,7 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mod & Z__B_STREAM_MOD_BOLD) {
|
||||
if (mod & Z__FX_STREAM_MOD_BOLD) {
|
||||
if (nr_codes > 0) {
|
||||
buf[buf_i++] = ';';
|
||||
}
|
||||
@@ -93,7 +93,7 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
nr_codes++;
|
||||
}
|
||||
|
||||
if (mod & Z__B_STREAM_MOD_ITALIC) {
|
||||
if (mod & Z__FX_STREAM_MOD_ITALIC) {
|
||||
if (nr_codes > 0) {
|
||||
buf[buf_i++] = ';';
|
||||
}
|
||||
@@ -102,7 +102,7 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
nr_codes++;
|
||||
}
|
||||
|
||||
if (mod & Z__B_STREAM_MOD_ULINE) {
|
||||
if (mod & Z__FX_STREAM_MOD_ULINE) {
|
||||
if (nr_codes > 0) {
|
||||
buf[buf_i++] = ';';
|
||||
}
|
||||
@@ -111,7 +111,7 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
nr_codes++;
|
||||
}
|
||||
|
||||
if (mod & Z__B_STREAM_MOD_INVERT) {
|
||||
if (mod & Z__FX_STREAM_MOD_INVERT) {
|
||||
if (nr_codes > 0) {
|
||||
buf[buf_i++] = ';';
|
||||
}
|
||||
@@ -120,43 +120,43 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
nr_codes++;
|
||||
}
|
||||
|
||||
if (Z__B_STREAM_MOD_GET_FG_COLOUR(mod) != 0) {
|
||||
if (Z__FX_STREAM_MOD_GET_FG_COLOUR(mod) != 0) {
|
||||
if (nr_codes > 0) {
|
||||
buf[buf_i++] = ';';
|
||||
}
|
||||
|
||||
buf[buf_i++] = mod & Z__B_STREAM_MOD_BRIGHT ? '9' : '3';
|
||||
buf[buf_i++] = mod & Z__FX_STREAM_MOD_BRIGHT ? '9' : '3';
|
||||
}
|
||||
|
||||
switch (Z__B_STREAM_MOD_GET_FG_COLOUR(mod)) {
|
||||
case Z__B_STREAM_MOD_BLACK:
|
||||
switch (Z__FX_STREAM_MOD_GET_FG_COLOUR(mod)) {
|
||||
case Z__FX_STREAM_MOD_BLACK:
|
||||
buf[buf_i++] = '0';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_RED:
|
||||
case Z__FX_STREAM_MOD_RED:
|
||||
buf[buf_i++] = '1';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_GREEN:
|
||||
case Z__FX_STREAM_MOD_GREEN:
|
||||
buf[buf_i++] = '2';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BLUE:
|
||||
case Z__FX_STREAM_MOD_FX:
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_RED | Z__B_STREAM_MOD_GREEN:
|
||||
case Z__FX_STREAM_MOD_RED | Z__FX_STREAM_MOD_GREEN:
|
||||
buf[buf_i++] = '3';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_RED | Z__B_STREAM_MOD_BLUE:
|
||||
case Z__FX_STREAM_MOD_RED | Z__FX_STREAM_MOD_FX:
|
||||
buf[buf_i++] = '5';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_GREEN | Z__B_STREAM_MOD_BLUE:
|
||||
case Z__FX_STREAM_MOD_GREEN | Z__FX_STREAM_MOD_FX:
|
||||
buf[buf_i++] = '6';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_RED | Z__B_STREAM_MOD_GREEN | Z__B_STREAM_MOD_BLUE:
|
||||
case Z__FX_STREAM_MOD_RED | Z__FX_STREAM_MOD_GREEN | Z__FX_STREAM_MOD_FX:
|
||||
buf[buf_i++] = '7';
|
||||
nr_codes++;
|
||||
break;
|
||||
@@ -164,12 +164,12 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
break;
|
||||
}
|
||||
|
||||
if (Z__B_STREAM_MOD_GET_BG_COLOUR(mod) != 0) {
|
||||
if (Z__FX_STREAM_MOD_GET_BG_COLOUR(mod) != 0) {
|
||||
if (nr_codes > 0) {
|
||||
buf[buf_i++] = ';';
|
||||
}
|
||||
|
||||
if (mod & Z__B_STREAM_MOD_BG_BRIGHT) {
|
||||
if (mod & Z__FX_STREAM_MOD_BG_BRIGHT) {
|
||||
buf[buf_i++] = '1';
|
||||
buf[buf_i++] = '0';
|
||||
} else {
|
||||
@@ -177,36 +177,36 @@ int z__b_stream_set_modifier(FILE *fp, enum z__b_stream_modifier mod)
|
||||
}
|
||||
}
|
||||
|
||||
switch (Z__B_STREAM_MOD_GET_BG_COLOUR(mod)) {
|
||||
case Z__B_STREAM_MOD_BG_BLACK:
|
||||
switch (Z__FX_STREAM_MOD_GET_BG_COLOUR(mod)) {
|
||||
case Z__FX_STREAM_MOD_BG_BLACK:
|
||||
buf[buf_i++] = '0';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BG_RED:
|
||||
case Z__FX_STREAM_MOD_BG_RED:
|
||||
buf[buf_i++] = '1';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BG_GREEN:
|
||||
case Z__FX_STREAM_MOD_BG_GREEN:
|
||||
buf[buf_i++] = '2';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BG_BLUE:
|
||||
case Z__FX_STREAM_MOD_BG_FX:
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BG_RED | Z__B_STREAM_MOD_BG_GREEN:
|
||||
case Z__FX_STREAM_MOD_BG_RED | Z__FX_STREAM_MOD_BG_GREEN:
|
||||
buf[buf_i++] = '3';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BG_RED | Z__B_STREAM_MOD_BG_BLUE:
|
||||
case Z__FX_STREAM_MOD_BG_RED | Z__FX_STREAM_MOD_BG_FX:
|
||||
buf[buf_i++] = '5';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BG_GREEN | Z__B_STREAM_MOD_BG_BLUE:
|
||||
case Z__FX_STREAM_MOD_BG_GREEN | Z__FX_STREAM_MOD_BG_FX:
|
||||
buf[buf_i++] = '6';
|
||||
nr_codes++;
|
||||
break;
|
||||
case Z__B_STREAM_MOD_BG_RED | Z__B_STREAM_MOD_BG_GREEN
|
||||
| Z__B_STREAM_MOD_BG_BLUE:
|
||||
case Z__FX_STREAM_MOD_BG_RED | Z__FX_STREAM_MOD_BG_GREEN
|
||||
| Z__FX_STREAM_MOD_BG_FX:
|
||||
buf[buf_i++] = '7';
|
||||
nr_codes++;
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "../../tty.h"
|
||||
|
||||
#include <blue/term/tty.h>
|
||||
#include <fx/term/tty.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -25,61 +25,61 @@
|
||||
#define ANSI_TRUECOLOUR_BG "48;2"
|
||||
|
||||
enum tty_flags {
|
||||
B_TTY_INIT = 0x01u,
|
||||
B_TTY_INTERACTIVE = 0x02u,
|
||||
FX_TTY_INIT = 0x01u,
|
||||
FX_TTY_INTERACTIVE = 0x02u,
|
||||
};
|
||||
|
||||
struct b_tty {
|
||||
struct fx_tty {
|
||||
FILE *t_in, *t_out;
|
||||
enum tty_flags t_flags;
|
||||
struct termios t_ios_raw, t_ios_default;
|
||||
struct b_tty_vmode t_vmode;
|
||||
struct fx_tty_vmode t_vmode;
|
||||
unsigned char t_mcount;
|
||||
struct tty_format_buf t_format_buf;
|
||||
};
|
||||
|
||||
static struct b_tty std = {0};
|
||||
static struct b_tty err = {0};
|
||||
static struct fx_tty std = {0};
|
||||
static struct fx_tty err = {0};
|
||||
|
||||
static const char *ansi_colour16_fg[] = {
|
||||
[B_TTY_COLOUR16_BLACK] = "30",
|
||||
[B_TTY_COLOUR16_RED] = "31",
|
||||
[B_TTY_COLOUR16_GREEN] = "32",
|
||||
[B_TTY_COLOUR16_YELLOW] = "33",
|
||||
[B_TTY_COLOUR16_BLUE] = "34",
|
||||
[B_TTY_COLOUR16_MAGENTA] = "35",
|
||||
[B_TTY_COLOUR16_CYAN] = "36",
|
||||
[B_TTY_COLOUR16_WHITE] = "37",
|
||||
[B_TTY_COLOUR16_BRIGHT_BLACK] = "90",
|
||||
[B_TTY_COLOUR16_BRIGHT_RED] = "91",
|
||||
[B_TTY_COLOUR16_BRIGHT_GREEN] = "92",
|
||||
[B_TTY_COLOUR16_BRIGHT_YELLOW] = "93",
|
||||
[B_TTY_COLOUR16_BRIGHT_BLUE] = "94",
|
||||
[B_TTY_COLOUR16_BRIGHT_MAGENTA] = "95",
|
||||
[B_TTY_COLOUR16_BRIGHT_CYAN] = "96",
|
||||
[B_TTY_COLOUR16_BRIGHT_WHITE] = "97",
|
||||
[FX_TTY_COLOUR16_BLACK] = "30",
|
||||
[FX_TTY_COLOUR16_RED] = "31",
|
||||
[FX_TTY_COLOUR16_GREEN] = "32",
|
||||
[FX_TTY_COLOUR16_YELLOW] = "33",
|
||||
[FX_TTY_COLOUR16_FX] = "34",
|
||||
[FX_TTY_COLOUR16_MAGENTA] = "35",
|
||||
[FX_TTY_COLOUR16_CYAN] = "36",
|
||||
[FX_TTY_COLOUR16_WHITE] = "37",
|
||||
[FX_TTY_COLOUR16_BRIGHT_BLACK] = "90",
|
||||
[FX_TTY_COLOUR16_BRIGHT_RED] = "91",
|
||||
[FX_TTY_COLOUR16_BRIGHT_GREEN] = "92",
|
||||
[FX_TTY_COLOUR16_BRIGHT_YELLOW] = "93",
|
||||
[FX_TTY_COLOUR16_BRIGHT_FX] = "94",
|
||||
[FX_TTY_COLOUR16_BRIGHT_MAGENTA] = "95",
|
||||
[FX_TTY_COLOUR16_BRIGHT_CYAN] = "96",
|
||||
[FX_TTY_COLOUR16_BRIGHT_WHITE] = "97",
|
||||
};
|
||||
|
||||
static const char *ansi_colour16_bg[] = {
|
||||
[B_TTY_COLOUR16_BLACK] = "40",
|
||||
[B_TTY_COLOUR16_RED] = "41",
|
||||
[B_TTY_COLOUR16_GREEN] = "42",
|
||||
[B_TTY_COLOUR16_YELLOW] = "43",
|
||||
[B_TTY_COLOUR16_BLUE] = "44",
|
||||
[B_TTY_COLOUR16_MAGENTA] = "45",
|
||||
[B_TTY_COLOUR16_CYAN] = "46",
|
||||
[B_TTY_COLOUR16_WHITE] = "47",
|
||||
[B_TTY_COLOUR16_BRIGHT_BLACK] = "100",
|
||||
[B_TTY_COLOUR16_BRIGHT_RED] = "101",
|
||||
[B_TTY_COLOUR16_BRIGHT_GREEN] = "102",
|
||||
[B_TTY_COLOUR16_BRIGHT_YELLOW] = "103",
|
||||
[B_TTY_COLOUR16_BRIGHT_BLUE] = "104",
|
||||
[B_TTY_COLOUR16_BRIGHT_MAGENTA] = "105",
|
||||
[B_TTY_COLOUR16_BRIGHT_CYAN] = "106",
|
||||
[B_TTY_COLOUR16_BRIGHT_WHITE] = "107",
|
||||
[FX_TTY_COLOUR16_BLACK] = "40",
|
||||
[FX_TTY_COLOUR16_RED] = "41",
|
||||
[FX_TTY_COLOUR16_GREEN] = "42",
|
||||
[FX_TTY_COLOUR16_YELLOW] = "43",
|
||||
[FX_TTY_COLOUR16_FX] = "44",
|
||||
[FX_TTY_COLOUR16_MAGENTA] = "45",
|
||||
[FX_TTY_COLOUR16_CYAN] = "46",
|
||||
[FX_TTY_COLOUR16_WHITE] = "47",
|
||||
[FX_TTY_COLOUR16_BRIGHT_BLACK] = "100",
|
||||
[FX_TTY_COLOUR16_BRIGHT_RED] = "101",
|
||||
[FX_TTY_COLOUR16_BRIGHT_GREEN] = "102",
|
||||
[FX_TTY_COLOUR16_BRIGHT_YELLOW] = "103",
|
||||
[FX_TTY_COLOUR16_BRIGHT_FX] = "104",
|
||||
[FX_TTY_COLOUR16_BRIGHT_MAGENTA] = "105",
|
||||
[FX_TTY_COLOUR16_BRIGHT_CYAN] = "106",
|
||||
[FX_TTY_COLOUR16_BRIGHT_WHITE] = "107",
|
||||
};
|
||||
|
||||
static void init_tty(struct b_tty *tty, FILE *in, FILE *out)
|
||||
static void init_tty(struct fx_tty *tty, FILE *in, FILE *out)
|
||||
{
|
||||
tty->t_in = in;
|
||||
tty->t_out = out;
|
||||
@@ -96,7 +96,7 @@ static void init_tty(struct b_tty *tty, FILE *in, FILE *out)
|
||||
}
|
||||
|
||||
if (isatty(fd)) {
|
||||
tty->t_flags |= B_TTY_INTERACTIVE;
|
||||
tty->t_flags |= FX_TTY_INTERACTIVE;
|
||||
}
|
||||
|
||||
tcgetattr(fd, &tty->t_ios_default);
|
||||
@@ -106,43 +106,43 @@ static void init_tty(struct b_tty *tty, FILE *in, FILE *out)
|
||||
tty->t_ios_raw.c_oflag &= ~(OPOST);
|
||||
tty->t_ios_raw.c_lflag &= ~(ECHO | ICANON | IEXTEN);
|
||||
|
||||
tty->t_flags |= B_TTY_INIT;
|
||||
tty->t_flags |= FX_TTY_INIT;
|
||||
}
|
||||
|
||||
struct b_tty *z__b_tty_get_std(void)
|
||||
struct fx_tty *z__fx_tty_get_std(void)
|
||||
{
|
||||
if (!(std.t_flags & B_TTY_INIT)) {
|
||||
if (!(std.t_flags & FX_TTY_INIT)) {
|
||||
init_tty(&std, stdin, stdout);
|
||||
}
|
||||
|
||||
return &std;
|
||||
}
|
||||
|
||||
struct b_tty *z__b_tty_get_err(void)
|
||||
struct fx_tty *z__fx_tty_get_err(void)
|
||||
{
|
||||
if (!(err.t_flags & B_TTY_INIT)) {
|
||||
if (!(err.t_flags & FX_TTY_INIT)) {
|
||||
init_tty(&err, NULL, stderr);
|
||||
}
|
||||
|
||||
return &err;
|
||||
}
|
||||
|
||||
struct tty_format_buf *z__b_tty_get_format_buf(struct b_tty *tty)
|
||||
struct tty_format_buf *z__fx_tty_get_format_buf(struct fx_tty *tty)
|
||||
{
|
||||
return &tty->t_format_buf;
|
||||
}
|
||||
|
||||
void z__b_tty_putc(struct b_tty *tty, char c)
|
||||
void z__fx_tty_putc(struct fx_tty *tty, char c)
|
||||
{
|
||||
fputc(c, tty->t_out);
|
||||
}
|
||||
|
||||
bool b_tty_is_interactive(const struct b_tty *tty)
|
||||
bool fx_tty_is_interactive(const struct fx_tty *tty)
|
||||
{
|
||||
return (tty->t_flags & B_TTY_INTERACTIVE) == B_TTY_INTERACTIVE;
|
||||
return (tty->t_flags & FX_TTY_INTERACTIVE) == FX_TTY_INTERACTIVE;
|
||||
}
|
||||
|
||||
static void set_raw(struct b_tty *tty)
|
||||
static void set_raw(struct fx_tty *tty)
|
||||
{
|
||||
int fd = -1;
|
||||
if (tty->t_in) {
|
||||
@@ -158,7 +158,7 @@ static void set_raw(struct b_tty *tty)
|
||||
tcsetattr(fd, TCSAFLUSH, &tty->t_ios_raw);
|
||||
}
|
||||
|
||||
static void set_canon(struct b_tty *tty)
|
||||
static void set_canon(struct fx_tty *tty)
|
||||
{
|
||||
int fd = -1;
|
||||
if (tty->t_in) {
|
||||
@@ -174,13 +174,13 @@ static void set_canon(struct b_tty *tty)
|
||||
tcsetattr(fd, TCSAFLUSH, &tty->t_ios_default);
|
||||
}
|
||||
|
||||
void b_tty_set_mode(struct b_tty *tty, enum b_tty_mode mode)
|
||||
void fx_tty_set_mode(struct fx_tty *tty, enum fx_tty_mode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case B_TTY_CANONICAL:
|
||||
case FX_TTY_CANONICAL:
|
||||
set_canon(tty);
|
||||
break;
|
||||
case B_TTY_RAW:
|
||||
case FX_TTY_RAW:
|
||||
set_raw(tty);
|
||||
break;
|
||||
default:
|
||||
@@ -188,11 +188,11 @@ void b_tty_set_mode(struct b_tty *tty, enum b_tty_mode mode)
|
||||
}
|
||||
}
|
||||
|
||||
void b_tty_reset_vmode(struct b_tty *tty)
|
||||
void fx_tty_reset_vmode(struct fx_tty *tty)
|
||||
{
|
||||
if (tty->t_vmode.v_fg.c_mode == B_TTY_COLOUR_NONE
|
||||
&& tty->t_vmode.v_bg.c_mode == B_TTY_COLOUR_NONE
|
||||
&& tty->t_vmode.v_attrib == B_TTY_ATTRIB_NORMAL) {
|
||||
if (tty->t_vmode.v_fg.c_mode == FX_TTY_COLOUR_NONE
|
||||
&& tty->t_vmode.v_bg.c_mode == FX_TTY_COLOUR_NONE
|
||||
&& tty->t_vmode.v_attrib == FX_TTY_ATTRIB_NORMAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -200,30 +200,30 @@ void b_tty_reset_vmode(struct b_tty *tty)
|
||||
|
||||
memset(&tty->t_vmode, 0x0, sizeof tty->t_vmode);
|
||||
|
||||
tty->t_vmode.v_fg.c_mode = B_TTY_COLOUR_NONE;
|
||||
tty->t_vmode.v_bg.c_mode = B_TTY_COLOUR_NONE;
|
||||
tty->t_vmode.v_attrib = B_TTY_ATTRIB_NORMAL;
|
||||
tty->t_vmode.v_fg.c_mode = FX_TTY_COLOUR_NONE;
|
||||
tty->t_vmode.v_bg.c_mode = FX_TTY_COLOUR_NONE;
|
||||
tty->t_vmode.v_attrib = FX_TTY_ATTRIB_NORMAL;
|
||||
}
|
||||
|
||||
static int compare_colour(
|
||||
const struct b_tty_colour *a, const struct b_tty_colour *b)
|
||||
const struct fx_tty_colour *a, const struct fx_tty_colour *b)
|
||||
{
|
||||
if (a->c_mode != b->c_mode) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (a->c_mode) {
|
||||
case B_TTY_COLOUR_16:
|
||||
case FX_TTY_COLOUR_16:
|
||||
if (a->c_16.value != b->c_16.value) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case B_TTY_COLOUR_256:
|
||||
case FX_TTY_COLOUR_256:
|
||||
if (a->c_256.value != b->c_256.value) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case B_TTY_COLOUR_TRUE:
|
||||
case FX_TTY_COLOUR_TRUE:
|
||||
if (a->c_true.r != b->c_true.r) {
|
||||
return -1;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ static int compare_colour(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compare_vmode(const struct b_tty_vmode *a, const struct b_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;
|
||||
@@ -260,7 +260,7 @@ static int compare_vmode(const struct b_tty_vmode *a, const struct b_tty_vmode *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void put_ansi_attrib(struct b_tty *tty, const char *s)
|
||||
static void put_ansi_attrib(struct fx_tty *tty, const char *s)
|
||||
{
|
||||
if (tty->t_mcount > 0) {
|
||||
fputs(";", tty->t_out);
|
||||
@@ -271,46 +271,46 @@ static void put_ansi_attrib(struct b_tty *tty, const char *s)
|
||||
}
|
||||
|
||||
static void set_attrib(
|
||||
struct b_tty *tty, enum b_tty_attrib old, enum b_tty_attrib new)
|
||||
struct fx_tty *tty, enum fx_tty_attrib old, enum fx_tty_attrib new)
|
||||
{
|
||||
if (old == new) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Bold ON */
|
||||
if (!(old & B_TTY_ATTRIB_BOLD) && new &B_TTY_ATTRIB_BOLD) {
|
||||
if (!(old & FX_TTY_ATTRIB_BOLD) && new &FX_TTY_ATTRIB_BOLD) {
|
||||
put_ansi_attrib(tty, ANSI_BOLD_ON);
|
||||
}
|
||||
|
||||
/* Bold OFF */
|
||||
if (old & B_TTY_ATTRIB_BOLD && !(new &B_TTY_ATTRIB_BOLD)) {
|
||||
if (old & FX_TTY_ATTRIB_BOLD && !(new &FX_TTY_ATTRIB_BOLD)) {
|
||||
put_ansi_attrib(tty, ANSI_BOLD_OFF);
|
||||
}
|
||||
|
||||
/* Underline ON */
|
||||
if (!(old & B_TTY_ATTRIB_UNDERLINE) && new &B_TTY_ATTRIB_UNDERLINE) {
|
||||
if (!(old & FX_TTY_ATTRIB_UNDERLINE) && new &FX_TTY_ATTRIB_UNDERLINE) {
|
||||
put_ansi_attrib(tty, ANSI_UNDERLINE_ON);
|
||||
}
|
||||
|
||||
/* Underline OFF */
|
||||
if (old & B_TTY_ATTRIB_UNDERLINE && !(new &B_TTY_ATTRIB_UNDERLINE)) {
|
||||
if (old & FX_TTY_ATTRIB_UNDERLINE && !(new &FX_TTY_ATTRIB_UNDERLINE)) {
|
||||
put_ansi_attrib(tty, ANSI_UNDERLINE_OFF);
|
||||
}
|
||||
|
||||
/* Italic ON */
|
||||
if (!(old & B_TTY_ATTRIB_ITALIC) && new &B_TTY_ATTRIB_ITALIC) {
|
||||
if (!(old & FX_TTY_ATTRIB_ITALIC) && new &FX_TTY_ATTRIB_ITALIC) {
|
||||
put_ansi_attrib(tty, ANSI_ITALIC_ON);
|
||||
}
|
||||
|
||||
/* Italic OFF */
|
||||
if (old & B_TTY_ATTRIB_ITALIC && !(new &B_TTY_ATTRIB_ITALIC)) {
|
||||
if (old & FX_TTY_ATTRIB_ITALIC && !(new &FX_TTY_ATTRIB_ITALIC)) {
|
||||
put_ansi_attrib(tty, ANSI_ITALIC_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_fg(
|
||||
struct b_tty *tty, const struct b_tty_colour *old,
|
||||
const struct b_tty_colour *new)
|
||||
struct fx_tty *tty, const struct fx_tty_colour *old,
|
||||
const struct fx_tty_colour *new)
|
||||
{
|
||||
if (compare_colour(old, new) == 0) {
|
||||
return;
|
||||
@@ -319,18 +319,18 @@ static void set_fg(
|
||||
char buf[8];
|
||||
|
||||
switch (new->c_mode) {
|
||||
case B_TTY_COLOUR_NONE:
|
||||
case FX_TTY_COLOUR_NONE:
|
||||
put_ansi_attrib(tty, ANSI_DEFAULTCOLOUR_FG);
|
||||
break;
|
||||
case B_TTY_COLOUR_16:
|
||||
case FX_TTY_COLOUR_16:
|
||||
put_ansi_attrib(tty, ansi_colour16_fg[new->c_16.value]);
|
||||
break;
|
||||
case B_TTY_COLOUR_256:
|
||||
case FX_TTY_COLOUR_256:
|
||||
put_ansi_attrib(tty, ANSI_256COLOUR_FG);
|
||||
snprintf(buf, sizeof buf, "%u", new->c_256.value);
|
||||
put_ansi_attrib(tty, buf);
|
||||
break;
|
||||
case B_TTY_COLOUR_TRUE:
|
||||
case FX_TTY_COLOUR_TRUE:
|
||||
put_ansi_attrib(tty, ANSI_TRUECOLOUR_FG);
|
||||
snprintf(buf, sizeof buf, "%u", new->c_true.r);
|
||||
put_ansi_attrib(tty, buf);
|
||||
@@ -345,8 +345,8 @@ static void set_fg(
|
||||
}
|
||||
|
||||
static void set_bg(
|
||||
struct b_tty *tty, const struct b_tty_colour *old,
|
||||
const struct b_tty_colour *new)
|
||||
struct fx_tty *tty, const struct fx_tty_colour *old,
|
||||
const struct fx_tty_colour *new)
|
||||
{
|
||||
if (compare_colour(old, new) == 0) {
|
||||
return;
|
||||
@@ -355,18 +355,18 @@ static void set_bg(
|
||||
char buf[8];
|
||||
|
||||
switch (new->c_mode) {
|
||||
case B_TTY_COLOUR_NONE:
|
||||
case FX_TTY_COLOUR_NONE:
|
||||
put_ansi_attrib(tty, ANSI_DEFAULTCOLOUR_BG);
|
||||
break;
|
||||
case B_TTY_COLOUR_16:
|
||||
case FX_TTY_COLOUR_16:
|
||||
put_ansi_attrib(tty, ansi_colour16_bg[new->c_16.value]);
|
||||
break;
|
||||
case B_TTY_COLOUR_256:
|
||||
case FX_TTY_COLOUR_256:
|
||||
put_ansi_attrib(tty, ANSI_256COLOUR_BG);
|
||||
snprintf(buf, sizeof buf, "%u", new->c_256.value);
|
||||
put_ansi_attrib(tty, buf);
|
||||
break;
|
||||
case B_TTY_COLOUR_TRUE:
|
||||
case FX_TTY_COLOUR_TRUE:
|
||||
put_ansi_attrib(tty, ANSI_TRUECOLOUR_BG);
|
||||
snprintf(buf, sizeof buf, "%u", new->c_true.r);
|
||||
put_ansi_attrib(tty, buf);
|
||||
@@ -380,7 +380,7 @@ static void set_bg(
|
||||
}
|
||||
}
|
||||
|
||||
void b_tty_set_vmode(struct b_tty *tty, const struct b_tty_vmode *vmode)
|
||||
void fx_tty_set_vmode(struct fx_tty *tty, const struct fx_tty_vmode *vmode)
|
||||
{
|
||||
if (compare_vmode(&tty->t_vmode, vmode) == 0) {
|
||||
return;
|
||||
@@ -399,7 +399,7 @@ void b_tty_set_vmode(struct b_tty *tty, const struct b_tty_vmode *vmode)
|
||||
memcpy(&tty->t_vmode, vmode, sizeof *vmode);
|
||||
}
|
||||
|
||||
b_keycode b_tty_read_key(struct b_tty *tty)
|
||||
fx_keycode fx_tty_read_key(struct fx_tty *tty)
|
||||
{
|
||||
char c;
|
||||
int v;
|
||||
@@ -408,19 +408,19 @@ b_keycode b_tty_read_key(struct b_tty *tty)
|
||||
while (1) {
|
||||
v = read(fd, &c, 1);
|
||||
if (v < 1) {
|
||||
return B_KEY_EOF;
|
||||
return FX_KEY_EOF;
|
||||
}
|
||||
|
||||
if (c == '\r' || c == '\n') {
|
||||
return B_KEY_RETURN;
|
||||
return FX_KEY_RETURN;
|
||||
}
|
||||
|
||||
if (c == '\b' || c == 0x7F) {
|
||||
return B_KEY_BACKSPACE;
|
||||
return FX_KEY_BACKSPACE;
|
||||
}
|
||||
|
||||
if (c >= 1 && c <= 26) {
|
||||
return B_TTY_CTRL_KEY(c + 'a' - 1);
|
||||
return FX_TTY_CTRL_KEY(c + 'a' - 1);
|
||||
}
|
||||
|
||||
if (c != 0x1b) {
|
||||
@@ -429,7 +429,7 @@ b_keycode b_tty_read_key(struct b_tty *tty)
|
||||
|
||||
v = read(fd, &c, 1);
|
||||
if (v < 1) {
|
||||
return B_KEY_EOF;
|
||||
return FX_KEY_EOF;
|
||||
}
|
||||
|
||||
if (c != '[') {
|
||||
@@ -438,18 +438,18 @@ b_keycode b_tty_read_key(struct b_tty *tty)
|
||||
|
||||
v = read(fd, &c, 1);
|
||||
if (v < 1) {
|
||||
return B_KEY_EOF;
|
||||
return FX_KEY_EOF;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'A':
|
||||
return B_KEY_ARROW_UP;
|
||||
return FX_KEY_ARROW_UP;
|
||||
case 'B':
|
||||
return B_KEY_ARROW_DOWN;
|
||||
return FX_KEY_ARROW_DOWN;
|
||||
case 'C':
|
||||
return B_KEY_ARROW_RIGHT;
|
||||
return FX_KEY_ARROW_RIGHT;
|
||||
case 'D':
|
||||
return B_KEY_ARROW_LEFT;
|
||||
return FX_KEY_ARROW_LEFT;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
@@ -458,9 +458,9 @@ b_keycode b_tty_read_key(struct b_tty *tty)
|
||||
return c;
|
||||
}
|
||||
|
||||
void b_tty_move_cursor_x(struct b_tty *tty, enum b_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 == B_TTY_POS_CURSOR && pos < 0 && pos >= -4) {
|
||||
if (base == FX_TTY_POS_CURSOR && pos < 0 && pos >= -4) {
|
||||
for (int i = 0; i > pos; i--) {
|
||||
fputc('\b', tty->t_out);
|
||||
}
|
||||
@@ -468,7 +468,7 @@ void b_tty_move_cursor_x(struct b_tty *tty, enum b_tty_position_base base, int p
|
||||
return;
|
||||
}
|
||||
|
||||
if (base == B_TTY_POS_START) {
|
||||
if (base == FX_TTY_POS_START) {
|
||||
if (pos == 0) {
|
||||
fputs("\033[G", tty->t_out);
|
||||
} else {
|
||||
@@ -487,9 +487,9 @@ void b_tty_move_cursor_x(struct b_tty *tty, enum b_tty_position_base base, int p
|
||||
}
|
||||
}
|
||||
|
||||
void b_tty_move_cursor_y(struct b_tty *tty, enum b_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 == B_TTY_POS_START) {
|
||||
if (base == FX_TTY_POS_START) {
|
||||
/* we don't need this functionality right now */
|
||||
abort();
|
||||
}
|
||||
@@ -505,32 +505,32 @@ void b_tty_move_cursor_y(struct b_tty *tty, enum b_tty_position_base base, int p
|
||||
}
|
||||
}
|
||||
|
||||
void b_tty_clear(struct b_tty *tty, enum b_tty_clear_mode mode)
|
||||
void fx_tty_clear(struct fx_tty *tty, enum fx_tty_clear_mode mode)
|
||||
{
|
||||
const char *arg;
|
||||
if (mode & B_TTY_CLEAR_ALL) {
|
||||
if (mode & FX_TTY_CLEAR_ALL) {
|
||||
arg = "2";
|
||||
} else if (mode & B_TTY_CLEAR_TO_CURSOR) {
|
||||
} else if (mode & FX_TTY_CLEAR_TO_CURSOR) {
|
||||
arg = "1";
|
||||
} else if (mode & B_TTY_CLEAR_FROM_CURSOR) {
|
||||
} else if (mode & FX_TTY_CLEAR_FROM_CURSOR) {
|
||||
arg = "";
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
|
||||
if (mode & B_TTY_CLEAR_SCREEN) {
|
||||
if (mode & FX_TTY_CLEAR_SCREEN) {
|
||||
fprintf(tty->t_out, "\033[%sJ", arg);
|
||||
} else if (mode & B_TTY_CLEAR_LINE) {
|
||||
} else if (mode & FX_TTY_CLEAR_LINE) {
|
||||
fprintf(tty->t_out, "\033[%sK", arg);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
enum b_status b_tty_get_dimensions(
|
||||
struct b_tty *tty, unsigned int *w, unsigned int *h)
|
||||
enum fx_status fx_tty_get_dimensions(
|
||||
struct fx_tty *tty, unsigned int *w, unsigned int *h)
|
||||
{
|
||||
if (!(tty->t_flags & B_TTY_INTERACTIVE)) {
|
||||
if (!(tty->t_flags & FX_TTY_INTERACTIVE)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user