meta: rename to fx

This commit is contained in:
2026-03-16 10:35:43 +00:00
parent 84df46489a
commit e9d0e323f0
233 changed files with 12875 additions and 12869 deletions

View File

@@ -1,3 +1,3 @@
include(../cmake/Templates.cmake)
add_bluelib_module(NAME term DEPENDENCIES core ds)
add_fx_module(NAME term DEPENDENCIES core ds)

View File

@@ -1,47 +1,47 @@
#include <blue/core/error.h>
#include <blue/core/stringstream.h>
#include <blue/term/tty.h>
#include <fx/core/error.h>
#include <fx/core/stringstream.h>
#include <fx/term/tty.h>
#include <inttypes.h>
static void get_error_id(
const struct b_error_vendor *vendor, const struct b_error *error,
const struct fx_error_vendor *vendor, const struct fx_error *error,
char *out, size_t max)
{
const char *vendor_name = NULL;
const char *error_name = NULL;
b_error_status_code code = b_error_get_status_code(error);
fx_error_status_code code = fx_error_get_status_code(error);
if (vendor) {
vendor_name = vendor->v_name;
error_name = b_error_vendor_get_status_code_name(vendor, code);
error_name = fx_error_vendor_get_status_code_name(vendor, code);
}
b_stringstream *id = b_stringstream_create_with_buffer(out, max);
fx_stringstream *id = fx_stringstream_create_with_buffer(out, max);
if (vendor_name) {
b_stream_write_string(id, vendor_name, NULL);
fx_stream_write_string(id, vendor_name, NULL);
}
if (error_name) {
if (vendor_name) {
b_stream_write_string(id, ".", NULL);
fx_stream_write_string(id, ".", NULL);
}
b_stream_write_string(id, error_name, NULL);
fx_stream_write_string(id, error_name, NULL);
} else {
if (vendor_name) {
b_stream_write_string(id, "#", NULL);
fx_stream_write_string(id, "#", NULL);
}
b_stream_write_fmt(id, NULL, "%ld", code);
fx_stream_write_fmt(id, NULL, "%ld", code);
}
}
static void print_template_parameter(
const struct b_error_template_parameter *params, size_t nr_params,
const struct fx_error_template_parameter *params, size_t nr_params,
const char *param_name)
{
const struct b_error_template_parameter *param = NULL;
const struct fx_error_template_parameter *param = NULL;
for (size_t i = 0; i < nr_params; i++) {
if (!params[i].param_name) {
@@ -61,59 +61,59 @@ static void print_template_parameter(
const char *format = param->__param_def->param_format;
switch (param->__param_def->param_type) {
case B_ERROR_TEMPLATE_PARAM_STRING: {
case FX_ERROR_TEMPLATE_PARAM_STRING: {
const char *s = (const char *)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, s);
fx_tty_printf(fx_stdtty_err, 0, format, s);
break;
}
case B_ERROR_TEMPLATE_PARAM_CHAR: {
case FX_ERROR_TEMPLATE_PARAM_CHAR: {
char v = (char)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_INT: {
case FX_ERROR_TEMPLATE_PARAM_INT: {
int v = (int)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_UINT: {
case FX_ERROR_TEMPLATE_PARAM_UINT: {
unsigned int v = (unsigned int)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_LONG: {
case FX_ERROR_TEMPLATE_PARAM_LONG: {
long v = (long)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_ULONG: {
case FX_ERROR_TEMPLATE_PARAM_ULONG: {
unsigned long v = (unsigned long)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_LONGLONG: {
case FX_ERROR_TEMPLATE_PARAM_LONGLONG: {
long long v = (long long)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_ULONGLONG: {
case FX_ERROR_TEMPLATE_PARAM_ULONGLONG: {
unsigned long long v = (unsigned long long)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_PTR: {
case FX_ERROR_TEMPLATE_PARAM_PTR: {
const void *p = (const void *)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, p);
fx_tty_printf(fx_stdtty_err, 0, format, p);
break;
}
case B_ERROR_TEMPLATE_PARAM_INTPTR: {
case FX_ERROR_TEMPLATE_PARAM_INTPTR: {
intptr_t v = (intptr_t)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
case B_ERROR_TEMPLATE_PARAM_UINTPTR: {
case FX_ERROR_TEMPLATE_PARAM_UINTPTR: {
uintptr_t v = (uintptr_t)param->param_value;
b_tty_printf(b_stdtty_err, 0, format, v);
fx_tty_printf(fx_stdtty_err, 0, format, v);
break;
}
default:
@@ -122,7 +122,7 @@ static void print_template_parameter(
}
static void print_content(
const struct b_error_template_parameter *params, size_t nr_params,
const struct fx_error_template_parameter *params, size_t nr_params,
const char *s)
{
char modifier = 0;
@@ -134,7 +134,7 @@ static void print_content(
char c = s[i];
if (c != '@') {
b_tty_putc(b_stdtty_err, 0, c);
fx_tty_putc(fx_stdtty_err, 0, c);
i++;
continue;
}
@@ -151,7 +151,7 @@ static void print_content(
}
if (s[i] == '@') {
b_tty_putc(b_stdtty_err, 0, c);
fx_tty_putc(fx_stdtty_err, 0, c);
break;
}
@@ -173,13 +173,13 @@ static void print_content(
switch (modifier) {
case 'i':
b_tty_printf(b_stdtty_err, 0, "[cyan]");
fx_tty_printf(fx_stdtty_err, 0, "[cyan]");
break;
case 'w':
b_tty_printf(b_stdtty_err, 0, "[yellow]");
fx_tty_printf(fx_stdtty_err, 0, "[yellow]");
break;
case 'e':
b_tty_printf(b_stdtty_err, 0, "[red]");
fx_tty_printf(fx_stdtty_err, 0, "[red]");
break;
default:
break;
@@ -197,10 +197,10 @@ static void print_content(
if (template_param) {
print_template_parameter(params, nr_params, buf);
} else {
b_tty_printf(b_stdtty_err, 0, "%s", buf);
fx_tty_printf(fx_stdtty_err, 0, "%s", buf);
}
b_tty_printf(b_stdtty_err, 0, "[reset]");
fx_tty_printf(fx_stdtty_err, 0, "[reset]");
if (s[i] != 0) {
i++;
@@ -208,33 +208,33 @@ static void print_content(
}
}
static void print_submsg(const struct b_error *error)
static void print_submsg(const struct fx_error *error)
{
const struct b_error_definition *error_def = b_error_get_definition(error);
const struct b_error_submsg *submsg = b_error_get_first_submsg(error);
const struct fx_error_definition *error_def = fx_error_get_definition(error);
const struct fx_error_submsg *submsg = fx_error_get_first_submsg(error);
while (submsg) {
enum b_error_submsg_type type = b_error_submsg_get_type(submsg);
const char *content = b_error_submsg_get_content(submsg);
const struct b_error_msg *msg = b_error_submsg_get_msg(submsg);
const struct b_error_template_parameter *params
= b_error_submsg_get_template_parameters(submsg);
enum fx_error_submsg_type type = fx_error_submsg_get_type(submsg);
const char *content = fx_error_submsg_get_content(submsg);
const struct fx_error_msg *msg = fx_error_submsg_get_msg(submsg);
const struct fx_error_template_parameter *params
= fx_error_submsg_get_template_parameters(submsg);
b_tty_printf(b_stdtty_err, 0, " ");
fx_tty_printf(fx_stdtty_err, 0, " ");
switch (type) {
case B_ERROR_SUBMSG_ERROR:
b_tty_printf(
b_stdtty_err, 0, "[bright_red,bold]>[reset] ");
case FX_ERROR_SUBMSG_ERROR:
fx_tty_printf(
fx_stdtty_err, 0, "[bright_red,bold]>[reset] ");
break;
case B_ERROR_SUBMSG_WARNING:
b_tty_printf(
b_stdtty_err, 0,
case FX_ERROR_SUBMSG_WARNING:
fx_tty_printf(
fx_stdtty_err, 0,
"[bright_yellow,bold]>[reset] ");
break;
case B_ERROR_SUBMSG_INFO:
b_tty_printf(
b_stdtty_err, 0, "[bright_cyan,bold]>[reset] ");
case FX_ERROR_SUBMSG_INFO:
fx_tty_printf(
fx_stdtty_err, 0, "[bright_cyan,bold]>[reset] ");
break;
default:
break;
@@ -242,16 +242,16 @@ static void print_submsg(const struct b_error *error)
if (msg) {
print_content(
params, B_ERROR_TEMPLATE_PARAMETER_MAX,
b_error_msg_get_content(msg));
params, FX_ERROR_TEMPLATE_PARAMETER_MAX,
fx_error_msg_get_content(msg));
} else if (content) {
print_content(
params, B_ERROR_TEMPLATE_PARAMETER_MAX, content);
params, FX_ERROR_TEMPLATE_PARAMETER_MAX, content);
}
b_tty_printf(b_stdtty_err, 0, "\n");
fx_tty_printf(fx_stdtty_err, 0, "\n");
submsg = b_error_get_next_submsg(error, submsg);
submsg = fx_error_get_next_submsg(error, submsg);
}
}
@@ -274,95 +274,95 @@ const char *get_short_filepath(const char *path)
return path;
}
static void print_stack_trace(const struct b_error *error)
static void print_stack_trace(const struct fx_error *error)
{
const struct b_error_stack_frame *frame
= b_error_get_first_stack_frame(error);
const struct fx_error_stack_frame *frame
= fx_error_get_first_stack_frame(error);
while (frame) {
const char *file, *func;
unsigned int line;
file = b_error_stack_frame_get_filepath(frame);
line = b_error_stack_frame_get_line_number(frame);
func = b_error_stack_frame_get_function_name(frame);
file = fx_error_stack_frame_get_filepath(frame);
line = fx_error_stack_frame_get_line_number(frame);
func = fx_error_stack_frame_get_function_name(frame);
file = get_short_filepath(file);
b_tty_printf(
b_stdtty_err, 0,
fx_tty_printf(
fx_stdtty_err, 0,
" [dark_grey]at %s() (%s:%u)[reset]\n", func, file,
line);
frame = b_error_get_next_stack_frame(error, frame);
frame = fx_error_get_next_stack_frame(error, frame);
}
}
static void report_error(
const b_error *error, b_error_report_flags flags, bool caused_by)
const fx_error *error, fx_error_report_flags flags, bool caused_by)
{
const b_error_vendor *vendor = b_error_get_vendor(error);
const fx_error_vendor *vendor = fx_error_get_vendor(error);
char error_id[128];
get_error_id(vendor, error, error_id, sizeof error_id);
const struct b_error_definition *error_def = b_error_get_definition(error);
b_error_status_code code = b_error_get_status_code(error);
const char *description = b_error_get_description(error);
const struct b_error_template_parameter *params
= b_error_get_template_parameters(error);
const struct fx_error_definition *error_def = fx_error_get_definition(error);
fx_error_status_code code = fx_error_get_status_code(error);
const char *description = fx_error_get_description(error);
const struct fx_error_template_parameter *params
= fx_error_get_template_parameters(error);
if (!description && vendor) {
description = b_error_vendor_get_status_code_description(
description = fx_error_vendor_get_status_code_description(
vendor, code);
}
if (caused_by) {
b_tty_printf(
b_stdtty_err, 0,
fx_tty_printf(
fx_stdtty_err, 0,
" [green]->[reset] caused by [bright_red,bold]ERROR ");
} else {
b_tty_printf(b_stdtty_err, 0, "[bright_red,bold]==> ERROR ");
fx_tty_printf(fx_stdtty_err, 0, "[bright_red,bold]==> ERROR ");
}
if (flags & B_ERROR_REPORT_STATUS) {
b_tty_printf(b_stdtty_err, 0, "%s", error_id);
if (flags & FX_ERROR_REPORT_STATUS) {
fx_tty_printf(fx_stdtty_err, 0, "%s", error_id);
}
b_tty_printf(b_stdtty_err, 0, "[reset]");
fx_tty_printf(fx_stdtty_err, 0, "[reset]");
if (flags & B_ERROR_REPORT_DESCRIPTION) {
const struct b_error_msg *msg = b_error_get_msg(error);
if (flags & FX_ERROR_REPORT_DESCRIPTION) {
const struct fx_error_msg *msg = fx_error_get_msg(error);
if (msg) {
b_tty_printf(b_stdtty_err, 0, ": ");
fx_tty_printf(fx_stdtty_err, 0, ": ");
print_content(
params, B_ERROR_TEMPLATE_PARAMETER_MAX,
b_error_msg_get_content(msg));
params, FX_ERROR_TEMPLATE_PARAMETER_MAX,
fx_error_msg_get_content(msg));
} else if (description) {
b_tty_printf(b_stdtty_err, 0, ": ");
fx_tty_printf(fx_stdtty_err, 0, ": ");
print_content(
params, B_ERROR_TEMPLATE_PARAMETER_MAX,
params, FX_ERROR_TEMPLATE_PARAMETER_MAX,
description);
}
}
b_tty_printf(b_stdtty_err, 0, "\n");
fx_tty_printf(fx_stdtty_err, 0, "\n");
if (flags & B_ERROR_REPORT_SUBMSG) {
if (flags & FX_ERROR_REPORT_SUBMSG) {
print_submsg(error);
}
if (flags & B_ERROR_REPORT_STACK_TRACE) {
if (flags & FX_ERROR_REPORT_STACK_TRACE) {
print_stack_trace(error);
}
const struct b_error *cause = b_error_get_caused_by(error);
if (cause && (flags & B_ERROR_REPORT_CAUSE)) {
const struct fx_error *cause = fx_error_get_caused_by(error);
if (cause && (flags & FX_ERROR_REPORT_CAUSE)) {
report_error(cause, flags, true);
}
}
void b_enhanced_error_reporter(
const struct b_error *error, b_error_report_flags flags)
void fx_enhanced_error_reporter(
const struct fx_error *error, fx_error_report_flags flags)
{
report_error(error, flags, false);
}

View File

@@ -1,10 +0,0 @@
#ifndef BLUELIB_TERM_H_
#define BLUELIB_TERM_H_
#include <blue/core/status.h>
#include <stdio.h>
#include <blue/term/tty.h>
#include <blue/term/print.h>
#endif

View File

@@ -1,52 +0,0 @@
#ifndef BLUELIB_TERM_PRINT_H_
#define BLUELIB_TERM_PRINT_H_
#include <blue/core/misc.h>
#include <blue/core/status.h>
#include <blue/term/tty.h>
#include <stdarg.h>
#define b_i(...) b_print(B_PRINT_I, __VA_ARGS__)
#define b_warn(...) b_print(B_PRINT_WARN, __VA_ARGS__)
#define b_err(...) b_print(B_PRINT_ERR, __VA_ARGS__)
struct b_tty;
struct b_error;
struct b_error_vendor;
enum b_error_report_flags;
typedef enum b_paragraph_format_flags {
B_PARAGRAPH_DONT_INDENT_FIRST_LINE = 0x01u,
B_PARAGRAPH_HYPHENATE = 0x02u,
B_PARAGRAPH_DOUBLE_LINE_BREAK = 0x04u,
B_PARAGRAPH_MULTI_LINE_BREAK = 0x08u,
} b_paragraph_format_flags;
typedef struct b_paragraph_format {
b_paragraph_format_flags p_flags;
unsigned int p_left_margin;
unsigned int p_right_margin;
unsigned int p_line_length;
} b_paragraph_format;
typedef enum b_print_format {
B_PRINT_NORMAL = 0,
B_PRINT_I,
B_PRINT_WARN,
B_PRINT_ERR,
} b_print_format;
BLUE_API b_status b_print(b_print_format format, const char *str, ...);
BLUE_API b_status b_print_paragraph(
const char *str, struct b_tty *tty, b_paragraph_format *format);
BLUE_API int b_putc(char c);
BLUE_API int b_puts(const char *s);
BLUE_API int b_printf(const char *format, ...);
BLUE_API void b_enhanced_error_reporter(
const struct b_error *, enum b_error_report_flags flags);
#endif

View File

@@ -1,180 +0,0 @@
#ifndef BLUELIB_TERM_TTY_H_
#define BLUELIB_TERM_TTY_H_
#include <blue/core/misc.h>
#include <blue/core/status.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#define b_stdtty (z__b_tty_get_std())
#define b_stdtty_err (z__b_tty_get_err())
#define B_TTY_CTRL_KEY(c) ((c) | B_MOD_CTRL)
#define B_MAKE_VMODE(fg, bg, a) \
{ \
.v_fg = fg, .v_bg = bg, .v_attrib = (a) \
}
#define B_MAKE_COLOUR_DEFAULT(v) \
{ \
.c_mode = TTY_COLOUR_NONE, \
}
#define B_MAKE_COLOUR_16(v) \
{ \
.c_mode = TTY_COLOUR_16, .c_16 = {.value = (v) } \
}
#define B_MAKE_COLOUR_256(v) \
{ \
.c_mode = TTY_COLOUR_256, .c_256 = {.value = (v) } \
}
#define B_MAKE_COLOUR_TRUE(cr, cg, cb) \
{ \
.c_mode = TTY_COLOUR_TRUE, .c_true \
= {.r = (cr), \
.g = (cg), \
.b = (cb) } \
}
typedef struct b_tty b_tty;
typedef uint32_t b_keycode;
/* codepoints U+F0000 to U+FFFFD are reserved areas in Unicode, free for
* application use. store special keycodes here */
enum {
B_KEY_ARROW_LEFT = 0xF0000,
B_KEY_ARROW_RIGHT,
B_KEY_ARROW_UP,
B_KEY_ARROW_DOWN,
B_KEY_BACKSPACE,
B_KEY_RETURN,
B_MOD_CTRL = 0x10000000,
B_KEY_EOF = 0xFFFFFFFF,
};
typedef enum b_tty_colour16 {
B_TTY_COLOUR16_BLACK = 0,
B_TTY_COLOUR16_RED,
B_TTY_COLOUR16_GREEN,
B_TTY_COLOUR16_YELLOW,
B_TTY_COLOUR16_BLUE,
B_TTY_COLOUR16_MAGENTA,
B_TTY_COLOUR16_CYAN,
B_TTY_COLOUR16_WHITE,
B_TTY_COLOUR16_BRIGHT_BLACK,
B_TTY_COLOUR16_BRIGHT_RED,
B_TTY_COLOUR16_BRIGHT_GREEN,
B_TTY_COLOUR16_BRIGHT_YELLOW,
B_TTY_COLOUR16_BRIGHT_BLUE,
B_TTY_COLOUR16_BRIGHT_MAGENTA,
B_TTY_COLOUR16_BRIGHT_CYAN,
B_TTY_COLOUR16_BRIGHT_WHITE,
} b_tty_colour16;
typedef enum b_tty_colour_mode {
B_TTY_COLOUR_NONE = 0,
B_TTY_COLOUR_16,
B_TTY_COLOUR_256,
B_TTY_COLOUR_TRUE,
} b_tty_colour_mode;
typedef enum b_tty_position_base {
B_TTY_POS_START,
B_TTY_POS_CURSOR,
} b_tty_position_base;
typedef enum b_tty_attrib {
B_TTY_ATTRIB_NORMAL = 0x00u,
B_TTY_ATTRIB_BOLD = 0x01u,
B_TTY_ATTRIB_UNDERLINE = 0x02u,
B_TTY_ATTRIB_ITALIC = 0x04u,
B_TTY_ATTRIB_INVERT = 0x08u,
} b_tty_attrib;
typedef enum b_tty_clear_mode {
B_TTY_CLEAR_LINE = 0x01u,
B_TTY_CLEAR_SCREEN = 0x02,
B_TTY_CLEAR_TO_CURSOR = 0x0100u,
B_TTY_CLEAR_FROM_CURSOR = 0x0200u,
B_TTY_CLEAR_ALL = 0x0400u,
} b_tty_clear_mode;
typedef enum b_tty_mode {
B_TTY_CANONICAL = 0x00u,
B_TTY_RAW = 0x01u,
} b_tty_mode;
typedef enum b_tty_print_flags {
B_TTY_DISABLE_FORMATTING = 0x01u,
B_TTY_DISABLE_INTERPOLATED_FORMATTING = 0x02u,
} b_tty_print_flags;
typedef struct b_tty_colour {
enum b_tty_colour_mode c_mode;
union {
struct {
uint8_t value;
} c_16;
struct {
uint8_t value;
} c_256;
struct {
uint8_t r;
uint8_t g;
uint8_t b;
} c_true;
};
} b_tty_colour;
typedef struct b_tty_vmode {
enum b_tty_attrib v_attrib;
struct b_tty_colour v_fg;
struct b_tty_colour v_bg;
} b_tty_vmode;
BLUE_API b_tty *z__b_tty_get_std(void);
BLUE_API b_tty *z__b_tty_get_err(void);
static inline unsigned int b_keycode_get_key(b_keycode v)
{
return v & 0x0FFFFFFF;
}
BLUE_API bool b_tty_is_interactive(const struct b_tty *tty);
BLUE_API void b_tty_set_mode(struct b_tty *tty, enum b_tty_mode mode);
BLUE_API void b_tty_set_vmode(struct b_tty *tty, const struct b_tty_vmode *vmode);
BLUE_API void b_tty_reset_vmode(struct b_tty *tty);
BLUE_API enum b_status b_tty_get_dimensions(
struct b_tty *tty, unsigned int *w, unsigned int *h);
BLUE_API enum b_status b_tty_get_cursor_position(
struct b_tty *tty, unsigned int *x, unsigned int *y);
BLUE_API b_keycode b_tty_read_key(struct b_tty *tty);
BLUE_API void b_tty_move_cursor_x(
struct b_tty *tty, enum b_tty_position_base base, int pos);
BLUE_API void b_tty_move_cursor_y(
struct b_tty *tty, enum b_tty_position_base base, int pos);
BLUE_API void b_tty_clear(struct b_tty *tty, enum b_tty_clear_mode mode);
BLUE_API int b_tty_putc(struct b_tty *tty, enum b_tty_print_flags flags, char c);
BLUE_API int b_tty_puts(
struct b_tty *tty, enum b_tty_print_flags flags, const char *s);
BLUE_API int b_tty_printf(
struct b_tty *tty, enum b_tty_print_flags flags, const char *s, ...);
BLUE_API int b_tty_vprintf(
struct b_tty *tty, enum b_tty_print_flags flags, const char *s,
va_list args);
#endif

10
term/include/fx/term.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef FX_TERM_H_
#define FX_TERM_H_
#include <fx/core/status.h>
#include <stdio.h>
#include <fx/term/tty.h>
#include <fx/term/print.h>
#endif

View File

@@ -0,0 +1,52 @@
#ifndef FX_TERM_PRINT_H_
#define FX_TERM_PRINT_H_
#include <fx/core/misc.h>
#include <fx/core/status.h>
#include <fx/term/tty.h>
#include <stdarg.h>
#define fx_i(...) fx_print(FX_PRINT_I, __VA_ARGS__)
#define fx_warn(...) fx_print(FX_PRINT_WARN, __VA_ARGS__)
#define fx_err(...) fx_print(FX_PRINT_ERR, __VA_ARGS__)
struct fx_tty;
struct fx_error;
struct fx_error_vendor;
enum fx_error_report_flags;
typedef enum fx_paragraph_format_flags {
FX_PARAGRAPH_DONT_INDENT_FIRST_LINE = 0x01u,
FX_PARAGRAPH_HYPHENATE = 0x02u,
FX_PARAGRAPH_DOUBLE_LINE_BREAK = 0x04u,
FX_PARAGRAPH_MULTI_LINE_BREAK = 0x08u,
} fx_paragraph_format_flags;
typedef struct fx_paragraph_format {
fx_paragraph_format_flags p_flags;
unsigned int p_left_margin;
unsigned int p_right_margin;
unsigned int p_line_length;
} fx_paragraph_format;
typedef enum fx_print_format {
FX_PRINT_NORMAL = 0,
FX_PRINT_I,
FX_PRINT_WARN,
FX_PRINT_ERR,
} fx_print_format;
FX_API fx_status fx_print(fx_print_format format, const char *str, ...);
FX_API fx_status fx_print_paragraph(
const char *str, struct fx_tty *tty, fx_paragraph_format *format);
FX_API int fx_putc(char c);
FX_API int fx_puts(const char *s);
FX_API int fx_printf(const char *format, ...);
FX_API void fx_enhanced_error_reporter(
const struct fx_error *, enum fx_error_report_flags flags);
#endif

180
term/include/fx/term/tty.h Normal file
View File

@@ -0,0 +1,180 @@
#ifndef FX_TERM_TTY_H_
#define FX_TERM_TTY_H_
#include <fx/core/misc.h>
#include <fx/core/status.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#define fx_stdtty (z__fx_tty_get_std())
#define fx_stdtty_err (z__fx_tty_get_err())
#define FX_TTY_CTRL_KEY(c) ((c) | FX_MOD_CTRL)
#define FX_MAKE_VMODE(fg, bg, a) \
{ \
.v_fg = fg, .v_bg = bg, .v_attrib = (a) \
}
#define FX_MAKE_COLOUR_DEFAULT(v) \
{ \
.c_mode = TTY_COLOUR_NONE, \
}
#define FX_MAKE_COLOUR_16(v) \
{ \
.c_mode = TTY_COLOUR_16, .c_16 = {.value = (v) } \
}
#define FX_MAKE_COLOUR_256(v) \
{ \
.c_mode = TTY_COLOUR_256, .c_256 = {.value = (v) } \
}
#define FX_MAKE_COLOUR_TRUE(cr, cg, cb) \
{ \
.c_mode = TTY_COLOUR_TRUE, .c_true \
= {.r = (cr), \
.g = (cg), \
.b = (cb) } \
}
typedef struct fx_tty fx_tty;
typedef uint32_t fx_keycode;
/* codepoints U+F0000 to U+FFFFD are reserved areas in Unicode, free for
* application use. store special keycodes here */
enum {
FX_KEY_ARROW_LEFT = 0xF0000,
FX_KEY_ARROW_RIGHT,
FX_KEY_ARROW_UP,
FX_KEY_ARROW_DOWN,
FX_KEY_BACKSPACE,
FX_KEY_RETURN,
FX_MOD_CTRL = 0x10000000,
FX_KEY_EOF = 0xFFFFFFFF,
};
typedef enum fx_tty_colour16 {
FX_TTY_COLOUR16_BLACK = 0,
FX_TTY_COLOUR16_RED,
FX_TTY_COLOUR16_GREEN,
FX_TTY_COLOUR16_YELLOW,
FX_TTY_COLOUR16_FX,
FX_TTY_COLOUR16_MAGENTA,
FX_TTY_COLOUR16_CYAN,
FX_TTY_COLOUR16_WHITE,
FX_TTY_COLOUR16_BRIGHT_BLACK,
FX_TTY_COLOUR16_BRIGHT_RED,
FX_TTY_COLOUR16_BRIGHT_GREEN,
FX_TTY_COLOUR16_BRIGHT_YELLOW,
FX_TTY_COLOUR16_BRIGHT_FX,
FX_TTY_COLOUR16_BRIGHT_MAGENTA,
FX_TTY_COLOUR16_BRIGHT_CYAN,
FX_TTY_COLOUR16_BRIGHT_WHITE,
} fx_tty_colour16;
typedef enum fx_tty_colour_mode {
FX_TTY_COLOUR_NONE = 0,
FX_TTY_COLOUR_16,
FX_TTY_COLOUR_256,
FX_TTY_COLOUR_TRUE,
} fx_tty_colour_mode;
typedef enum fx_tty_position_base {
FX_TTY_POS_START,
FX_TTY_POS_CURSOR,
} fx_tty_position_base;
typedef enum fx_tty_attrib {
FX_TTY_ATTRIB_NORMAL = 0x00u,
FX_TTY_ATTRIB_BOLD = 0x01u,
FX_TTY_ATTRIB_UNDERLINE = 0x02u,
FX_TTY_ATTRIB_ITALIC = 0x04u,
FX_TTY_ATTRIB_INVERT = 0x08u,
} fx_tty_attrib;
typedef enum fx_tty_clear_mode {
FX_TTY_CLEAR_LINE = 0x01u,
FX_TTY_CLEAR_SCREEN = 0x02,
FX_TTY_CLEAR_TO_CURSOR = 0x0100u,
FX_TTY_CLEAR_FROM_CURSOR = 0x0200u,
FX_TTY_CLEAR_ALL = 0x0400u,
} fx_tty_clear_mode;
typedef enum fx_tty_mode {
FX_TTY_CANONICAL = 0x00u,
FX_TTY_RAW = 0x01u,
} fx_tty_mode;
typedef enum fx_tty_print_flags {
FX_TTY_DISABLE_FORMATTING = 0x01u,
FX_TTY_DISABLE_INTERPOLATED_FORMATTING = 0x02u,
} fx_tty_print_flags;
typedef struct fx_tty_colour {
enum fx_tty_colour_mode c_mode;
union {
struct {
uint8_t value;
} c_16;
struct {
uint8_t value;
} c_256;
struct {
uint8_t r;
uint8_t g;
uint8_t b;
} c_true;
};
} fx_tty_colour;
typedef struct fx_tty_vmode {
enum fx_tty_attrib v_attrib;
struct fx_tty_colour v_fg;
struct fx_tty_colour v_bg;
} fx_tty_vmode;
FX_API fx_tty *z__fx_tty_get_std(void);
FX_API fx_tty *z__fx_tty_get_err(void);
static inline unsigned int fx_keycode_get_key(fx_keycode v)
{
return v & 0x0FFFFFFF;
}
FX_API bool fx_tty_is_interactive(const struct fx_tty *tty);
FX_API void fx_tty_set_mode(struct fx_tty *tty, enum fx_tty_mode mode);
FX_API void fx_tty_set_vmode(struct fx_tty *tty, const struct fx_tty_vmode *vmode);
FX_API void fx_tty_reset_vmode(struct fx_tty *tty);
FX_API enum fx_status fx_tty_get_dimensions(
struct fx_tty *tty, unsigned int *w, unsigned int *h);
FX_API enum fx_status fx_tty_get_cursor_position(
struct fx_tty *tty, unsigned int *x, unsigned int *y);
FX_API fx_keycode fx_tty_read_key(struct fx_tty *tty);
FX_API void fx_tty_move_cursor_x(
struct fx_tty *tty, enum fx_tty_position_base base, int pos);
FX_API void fx_tty_move_cursor_y(
struct fx_tty *tty, enum fx_tty_position_base base, int pos);
FX_API void fx_tty_clear(struct fx_tty *tty, enum fx_tty_clear_mode mode);
FX_API int fx_tty_putc(struct fx_tty *tty, enum fx_tty_print_flags flags, char c);
FX_API int fx_tty_puts(
struct fx_tty *tty, enum fx_tty_print_flags flags, const char *s);
FX_API int fx_tty_printf(
struct fx_tty *tty, enum fx_tty_print_flags flags, const char *s, ...);
FX_API int fx_tty_vprintf(
struct fx_tty *tty, enum fx_tty_print_flags flags, const char *s,
va_list args);
#endif

View File

@@ -1,5 +1,5 @@
#include <blue/ds/string.h>
#include <blue/term/print.h>
#include <fx/ds/string.h>
#include <fx/term/print.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
@@ -9,18 +9,18 @@
#define DEFAULT_PARAGRAPH_WIDTH 160
static void indent(
struct b_paragraph_format *format, struct b_tty *tty, unsigned int margin)
struct fx_paragraph_format *format, struct fx_tty *tty, unsigned int margin)
{
unsigned int x = 0;
while (x < margin) {
b_tty_puts(tty, 0, " ");
fx_tty_puts(tty, 0, " ");
x++;
}
}
static unsigned int extract_line(
const char **sp, unsigned int line_length, b_string *out,
struct b_paragraph_format *format)
const char **sp, unsigned int line_length, fx_string *out,
struct fx_paragraph_format *format)
{
const char *start = *sp;
while (isspace(*start) || *start == '\n') {
@@ -87,18 +87,18 @@ static unsigned int extract_line(
len = strlen(start);
}
b_string_insert_cstrn(out, start, len, B_NPOS);
fx_string_insert_cstrn(out, start, len, FX_NPOS);
*sp = end;
return len;
}
static b_status print_paragraph_tty(
const char *str, struct b_tty *tty, struct b_paragraph_format *format)
static fx_status print_paragraph_tty(
const char *str, struct fx_tty *tty, struct fx_paragraph_format *format)
{
unsigned int w = 0, h = 0;
b_tty_get_dimensions(tty, &w, &h);
fx_tty_get_dimensions(tty, &w, &h);
if (!w) {
w = DEFAULT_PARAGRAPH_WIDTH;
@@ -108,7 +108,7 @@ static b_status print_paragraph_tty(
unsigned int line_length = format->p_line_length;
if (format->p_left_margin + format->p_right_margin >= w) {
return B_SUCCESS;
return FX_SUCCESS;
}
unsigned int page_width
@@ -117,32 +117,32 @@ static b_status print_paragraph_tty(
line_length = page_width;
}
if (!(format->p_flags & B_PARAGRAPH_DONT_INDENT_FIRST_LINE)) {
if (!(format->p_flags & FX_PARAGRAPH_DONT_INDENT_FIRST_LINE)) {
indent(format, tty, left_margin);
}
b_string *line = b_string_create();
fx_string *line = fx_string_create();
bool need_indent = false;
while (str) {
if (*str == '\n') {
if (format->p_flags & B_PARAGRAPH_DOUBLE_LINE_BREAK) {
b_tty_putc(tty, 0, '\n');
if (format->p_flags & FX_PARAGRAPH_DOUBLE_LINE_BREAK) {
fx_tty_putc(tty, 0, '\n');
}
str++;
need_indent = true;
while (*str == '\n') {
if (format->p_flags & B_PARAGRAPH_MULTI_LINE_BREAK) {
b_tty_putc(tty, 0, '\n');
if (format->p_flags & FX_PARAGRAPH_MULTI_LINE_BREAK) {
fx_tty_putc(tty, 0, '\n');
}
str++;
}
}
b_string_clear(line);
fx_string_clear(line);
unsigned int this_line
= extract_line(&str, line_length, line, format);
if (this_line == 0) {
@@ -153,24 +153,24 @@ static b_status print_paragraph_tty(
indent(format, tty, left_margin);
}
b_tty_puts(tty, 0, b_string_ptr(line));
b_tty_putc(tty, 0, '\n');
fx_tty_puts(tty, 0, fx_string_ptr(line));
fx_tty_putc(tty, 0, '\n');
need_indent = true;
}
b_string_unref(line);
fx_string_unref(line);
return B_SUCCESS;
return FX_SUCCESS;
}
static b_status print_paragraph_file(
const char *str, FILE *fp, struct b_paragraph_format *format)
static fx_status print_paragraph_file(
const char *str, FILE *fp, struct fx_paragraph_format *format)
{
return B_SUCCESS;
return FX_SUCCESS;
}
b_status b_print_paragraph(
const char *str, struct b_tty *fp, struct b_paragraph_format *format)
fx_status fx_print_paragraph(
const char *str, struct fx_tty *fp, struct fx_paragraph_format *format)
{
return print_paragraph_tty(str, fp, format);
}

View File

@@ -1,7 +1,7 @@
#include "print.h"
#include <blue/core/hash.h>
#include <blue/term/print.h>
#include <fx/core/hash.h>
#include <fx/term/print.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
@@ -25,7 +25,7 @@
#define F_RESET "[reset]"
typedef b_status (*print_function)(struct b_tty *tty, const char *s);
typedef fx_status (*print_function)(struct fx_tty *tty, const char *s);
static int print_no_ansi(FILE *fp, const char *str)
{
@@ -46,66 +46,66 @@ static int print_no_ansi(FILE *fp, const char *str)
return out;
}
static b_status print_normal(struct b_tty *tty, const char *s)
static fx_status print_normal(struct fx_tty *tty, const char *s)
{
return B_SUCCESS;
return FX_SUCCESS;
}
static b_status print_i(struct b_tty *tty, const char *s)
static fx_status print_i(struct fx_tty *tty, const char *s)
{
struct b_paragraph_format format = {0};
struct fx_paragraph_format format = {0};
format.p_left_margin = 5;
format.p_right_margin = 5;
format.p_flags = B_PARAGRAPH_DONT_INDENT_FIRST_LINE
| B_PARAGRAPH_MULTI_LINE_BREAK;
format.p_flags = FX_PARAGRAPH_DONT_INDENT_FIRST_LINE
| FX_PARAGRAPH_MULTI_LINE_BREAK;
// printf(F_CYN_BG F_BLACK " i " F_RESET " ");
b_tty_puts(tty, 0, F_CYN_BOLD " i:" F_RESET " ");
b_print_paragraph(s, tty, &format);
fx_tty_puts(tty, 0, F_CYN_BOLD " i:" F_RESET " ");
fx_print_paragraph(s, tty, &format);
return B_SUCCESS;
return FX_SUCCESS;
}
static b_status print_warn(struct b_tty *tty, const char *s)
static fx_status print_warn(struct fx_tty *tty, const char *s)
{
struct b_paragraph_format format = {0};
struct fx_paragraph_format format = {0};
format.p_left_margin = 5;
format.p_right_margin = 5;
format.p_flags = B_PARAGRAPH_DONT_INDENT_FIRST_LINE
| B_PARAGRAPH_MULTI_LINE_BREAK;
format.p_flags = FX_PARAGRAPH_DONT_INDENT_FIRST_LINE
| FX_PARAGRAPH_MULTI_LINE_BREAK;
// printf(F_YEL_BG F_BLACK " Warn " F_RESET " ");
b_tty_puts(tty, 0, F_YEL_BOLD " !!" F_RESET " ");
b_print_paragraph(s, tty, &format);
fx_tty_puts(tty, 0, F_YEL_BOLD " !!" F_RESET " ");
fx_print_paragraph(s, tty, &format);
return B_SUCCESS;
return FX_SUCCESS;
}
static b_status print_err(struct b_tty *tty, const char *s)
static fx_status print_err(struct fx_tty *tty, const char *s)
{
struct b_paragraph_format format = {0};
struct fx_paragraph_format format = {0};
format.p_left_margin = 5;
format.p_right_margin = 5;
format.p_flags = B_PARAGRAPH_DONT_INDENT_FIRST_LINE
| B_PARAGRAPH_MULTI_LINE_BREAK;
format.p_flags = FX_PARAGRAPH_DONT_INDENT_FIRST_LINE
| FX_PARAGRAPH_MULTI_LINE_BREAK;
// printf(F_RED_BG F_BLACK " Err " F_RESET " ");
b_tty_puts(tty, 0, F_RED_BOLD "Err:" F_RESET " ");
b_print_paragraph(s, tty, &format);
fx_tty_puts(tty, 0, F_RED_BOLD "Err:" F_RESET " ");
fx_print_paragraph(s, tty, &format);
return B_SUCCESS;
return FX_SUCCESS;
}
static print_function format_printers[] = {
[B_PRINT_NORMAL] = print_normal,
[B_PRINT_I] = print_i,
[B_PRINT_WARN] = print_warn,
[B_PRINT_ERR] = print_err,
[FX_PRINT_NORMAL] = print_normal,
[FX_PRINT_I] = print_i,
[FX_PRINT_WARN] = print_warn,
[FX_PRINT_ERR] = print_err,
};
static size_t nr_format_printers
= sizeof format_printers / sizeof format_printers[B_PRINT_NORMAL];
= sizeof format_printers / sizeof format_printers[FX_PRINT_NORMAL];
b_status b_print(b_print_format format, const char *str, ...)
fx_status fx_print(fx_print_format format, const char *str, ...)
{
char buf[1024];
@@ -115,33 +115,33 @@ b_status b_print(b_print_format format, const char *str, ...)
va_end(arg);
if (format >= nr_format_printers) {
return B_ERR_INVALID_ARGUMENT;
return FX_ERR_INVALID_ARGUMENT;
}
print_function printer = format_printers[format];
if (!printer) {
return B_ERR_INVALID_ARGUMENT;
return FX_ERR_INVALID_ARGUMENT;
}
return printer(b_stdtty, buf);
return printer(fx_stdtty, buf);
}
int b_putc(char c)
int fx_putc(char c)
{
return b_tty_putc(b_stdtty, 0, c);
return fx_tty_putc(fx_stdtty, 0, c);
}
int b_puts(const char* s)
int fx_puts(const char* s)
{
return b_tty_puts(b_stdtty, 0, s);
return fx_tty_puts(fx_stdtty, 0, s);
}
int b_printf(const char* format, ...)
int fx_printf(const char* format, ...)
{
va_list arg;
va_start(arg, format);
int x = b_tty_vprintf(
b_stdtty, B_TTY_DISABLE_INTERPOLATED_FORMATTING, format, arg);
int x = fx_tty_vprintf(
fx_stdtty, FX_TTY_DISABLE_INTERPOLATED_FORMATTING, format, arg);
va_end(arg);
return x;
}

View File

@@ -1,53 +1,53 @@
#ifndef _BLUELIB_PRINT_H_
#define _BLUELIB_PRINT_H_
#ifndef _FX_PRINT_H_
#define _FX_PRINT_H_
#include <blue/core/misc.h>
#include <blue/term.h>
#include <fx/core/misc.h>
#include <fx/term.h>
#include <stdio.h>
enum z__b_stream_modifier {
Z__B_STREAM_MOD_BLACK = 0x1,
Z__B_STREAM_MOD_RED = 0x2,
Z__B_STREAM_MOD_GREEN = 0x4,
Z__B_STREAM_MOD_BLUE = 0x8,
Z__B_STREAM_MOD_BRIGHT = 0x10,
enum z__fx_stream_modifier {
Z__FX_STREAM_MOD_BLACK = 0x1,
Z__FX_STREAM_MOD_RED = 0x2,
Z__FX_STREAM_MOD_GREEN = 0x4,
Z__FX_STREAM_MOD_FX = 0x8,
Z__FX_STREAM_MOD_BRIGHT = 0x10,
Z__B_STREAM_MOD_BG_BLACK = 0x20,
Z__B_STREAM_MOD_BG_RED = 0x40,
Z__B_STREAM_MOD_BG_GREEN = 0x80,
Z__B_STREAM_MOD_BG_BLUE = 0x100,
Z__B_STREAM_MOD_BG_BRIGHT = 0x200,
Z__FX_STREAM_MOD_BG_BLACK = 0x20,
Z__FX_STREAM_MOD_BG_RED = 0x40,
Z__FX_STREAM_MOD_BG_GREEN = 0x80,
Z__FX_STREAM_MOD_BG_FX = 0x100,
Z__FX_STREAM_MOD_BG_BRIGHT = 0x200,
Z__B_STREAM_MOD_BOLD = 0x400,
Z__B_STREAM_MOD_ITALIC = 0x800,
Z__B_STREAM_MOD_ULINE = 0x1000,
Z__B_STREAM_MOD_INVERT = 0x2000,
Z__FX_STREAM_MOD_BOLD = 0x400,
Z__FX_STREAM_MOD_ITALIC = 0x800,
Z__FX_STREAM_MOD_ULINE = 0x1000,
Z__FX_STREAM_MOD_INVERT = 0x2000,
Z__B_STREAM_MOD_RESET = 0x4000,
Z__FX_STREAM_MOD_RESET = 0x4000,
};
#define Z__B_STREAM_MOD_GET_FG_COLOUR(x) \
#define Z__FX_STREAM_MOD_GET_FG_COLOUR(x) \
((x) \
& (Z__B_STREAM_MOD_BLACK | Z__B_STREAM_MOD_RED \
| Z__B_STREAM_MOD_GREEN | Z__B_STREAM_MOD_BLUE))
#define Z__B_STREAM_MOD_CLEAR_FG_COLOUR(x) \
& (Z__FX_STREAM_MOD_BLACK | Z__FX_STREAM_MOD_RED \
| Z__FX_STREAM_MOD_GREEN | Z__FX_STREAM_MOD_FX))
#define Z__FX_STREAM_MOD_CLEAR_FG_COLOUR(x) \
((x) \
& ~(Z__B_STREAM_MOD_BLACK | Z__B_STREAM_MOD_RED \
| Z__B_STREAM_MOD_GREEN | Z__B_STREAM_MOD_BLUE))
& ~(Z__FX_STREAM_MOD_BLACK | Z__FX_STREAM_MOD_RED \
| Z__FX_STREAM_MOD_GREEN | Z__FX_STREAM_MOD_FX))
#define Z__B_STREAM_MOD_GET_BG_COLOUR(x) \
#define Z__FX_STREAM_MOD_GET_BG_COLOUR(x) \
((x) \
& (Z__B_STREAM_MOD_BG_BLACK | Z__B_STREAM_MOD_BG_RED \
| Z__B_STREAM_MOD_BG_GREEN | Z__B_STREAM_MOD_BG_BLUE))
#define Z__B_STREAM_MOD_CLEAR_BG_COLOUR(x) \
& (Z__FX_STREAM_MOD_BG_BLACK | Z__FX_STREAM_MOD_BG_RED \
| Z__FX_STREAM_MOD_BG_GREEN | Z__FX_STREAM_MOD_BG_FX))
#define Z__FX_STREAM_MOD_CLEAR_BG_COLOUR(x) \
((x) \
& ~(Z__B_STREAM_MOD_BG_BLACK | Z__B_STREAM_MOD_BG_RED \
| Z__B_STREAM_MOD_BG_GREEN | Z__B_STREAM_MOD_BG_BLUE))
& ~(Z__FX_STREAM_MOD_BG_BLACK | Z__FX_STREAM_MOD_BG_RED \
| Z__FX_STREAM_MOD_BG_GREEN | Z__FX_STREAM_MOD_BG_FX))
BLUE_API int z__b_stream_is_tty(FILE *fp);
BLUE_API int z__b_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h);
BLUE_API int z__b_stream_cursorpos(
FX_API int z__fx_stream_is_tty(FILE *fp);
FX_API int z__fx_stream_dimensions(FILE *fp, unsigned int *w, unsigned int *h);
FX_API int z__fx_stream_cursorpos(
FILE *in, FILE *out, unsigned int *x, unsigned int *y);
BLUE_API int z__b_stream_set_modifier(FILE *fp, unsigned int mod);
FX_API int z__fx_stream_set_modifier(FILE *fp, unsigned int mod);
#endif

View File

@@ -32,7 +32,7 @@
#include "printf.h"
#include <blue/term/tty.h>
#include <fx/term/tty.h>
#include <stdbool.h>
#include <stdint.h>
@@ -116,8 +116,8 @@
#endif
struct out_tty_args {
struct b_tty *tty;
enum b_tty_print_flags flags;
struct fx_tty *tty;
enum fx_tty_print_flags flags;
bool format_ch;
};
@@ -959,17 +959,17 @@ static void out_tty(char c, struct out_tty_args *args)
return;
}
enum b_tty_print_flags flags = args->flags;
enum fx_tty_print_flags flags = args->flags;
if (!args->format_ch && (flags & B_TTY_DISABLE_INTERPOLATED_FORMATTING)) {
flags |= B_TTY_DISABLE_FORMATTING;
if (!args->format_ch && (flags & FX_TTY_DISABLE_INTERPOLATED_FORMATTING)) {
flags |= FX_TTY_DISABLE_FORMATTING;
}
b_tty_putc(args->tty, flags, c);
fx_tty_putc(args->tty, flags, c);
}
int b_tty_vprintf(
struct b_tty *tty, enum b_tty_print_flags flags, const char *format,
int fx_tty_vprintf(
struct fx_tty *tty, enum fx_tty_print_flags flags, const char *format,
va_list args)
{
struct out_tty_args tty_args = {

View File

@@ -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,44 +120,44 @@ 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:
buf[buf_i++] = '4';
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;
@@ -165,12 +165,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 {
@@ -178,37 +178,37 @@ 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:
buf[buf_i++] = '4';
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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -4,7 +4,7 @@
#include <stdio.h>
#include <string.h>
int z__b_stream_is_tty(FILE *fp)
int z__fx_stream_is_tty(FILE *fp)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE console = (HANDLE)(INT_PTR)_get_osfhandle(fileno(fp));
@@ -13,7 +13,7 @@ int z__b_stream_is_tty(FILE *fp)
return status == TRUE ? 1 : 0;
}
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)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE console = (HANDLE)(INT_PTR)_get_osfhandle(fileno(fp));
@@ -34,7 +34,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)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE console = (HANDLE)(INT_PTR)_get_osfhandle(fileno(in));
@@ -67,7 +67,7 @@ int z__b_stream_cursorpos(FILE *in, FILE *out, unsigned int *x, unsigned int *y)
(attrib) &= ~(y); \
}
int z__b_stream_set_modifier(FILE *fp, unsigned int mod)
int z__fx_stream_set_modifier(FILE *fp, unsigned int mod)
{
WORD attrib = 0;
CONSOLE_SCREEN_BUFFER_INFO csbi;
@@ -81,52 +81,52 @@ int z__b_stream_set_modifier(FILE *fp, unsigned int mod)
attrib = csbi.wAttributes;
if (mod & Z__B_STREAM_MOD_RESET) {
attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
if (mod & Z__FX_STREAM_MOD_RESET) {
attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_FX;
SetConsoleTextAttribute(console, attrib);
return 0;
}
if (Z__B_STREAM_MOD_GET_FG_COLOUR(mod) != 0) {
if (mod & Z__B_STREAM_MOD_BLACK) {
if (Z__FX_STREAM_MOD_GET_FG_COLOUR(mod) != 0) {
if (mod & Z__FX_STREAM_MOD_BLACK) {
attrib
&= ~(FOREGROUND_RED | FOREGROUND_GREEN
| FOREGROUND_BLUE);
| FOREGROUND_FX);
} else {
APPLY_FLAG_X(
mod, attrib, Z__B_STREAM_MOD_RED, FOREGROUND_RED);
mod, attrib, Z__FX_STREAM_MOD_RED, FOREGROUND_RED);
APPLY_FLAG_X(
mod, attrib, Z__B_STREAM_MOD_GREEN,
mod, attrib, Z__FX_STREAM_MOD_GREEN,
FOREGROUND_GREEN);
APPLY_FLAG_X(
mod, attrib, Z__B_STREAM_MOD_BLUE, FOREGROUND_BLUE);
mod, attrib, Z__FX_STREAM_MOD_FX, FOREGROUND_FX);
}
}
if (Z__B_STREAM_MOD_GET_BG_COLOUR(mod) != 0) {
if (mod & Z__B_STREAM_MOD_BG_BLACK) {
if (Z__FX_STREAM_MOD_GET_BG_COLOUR(mod) != 0) {
if (mod & Z__FX_STREAM_MOD_BG_BLACK) {
attrib
&= ~(BACKGROUND_RED | BACKGROUND_GREEN
| BACKGROUND_BLUE);
| BACKGROUND_FX);
} else {
APPLY_FLAG_X(
mod, attrib, Z__B_STREAM_MOD_BG_RED,
mod, attrib, Z__FX_STREAM_MOD_BG_RED,
BACKGROUND_RED);
APPLY_FLAG_X(
mod, attrib, Z__B_STREAM_MOD_BG_GREEN,
mod, attrib, Z__FX_STREAM_MOD_BG_GREEN,
BACKGROUND_GREEN);
APPLY_FLAG_X(
mod, attrib, Z__B_STREAM_MOD_BG_BLUE,
BACKGROUND_BLUE);
mod, attrib, Z__FX_STREAM_MOD_BG_FX,
BACKGROUND_FX);
}
}
APPLY_FLAG(mod, attrib, Z__B_STREAM_MOD_ULINE, COMMON_LVB_UNDERSCORE);
APPLY_FLAG(mod, attrib, Z__B_STREAM_MOD_INVERT, COMMON_LVB_REVERSE_VIDEO);
APPLY_FLAG(mod, attrib, Z__FX_STREAM_MOD_ULINE, COMMON_LVB_UNDERSCORE);
APPLY_FLAG(mod, attrib, Z__FX_STREAM_MOD_INVERT, COMMON_LVB_REVERSE_VIDEO);
APPLY_FLAG(
mod, attrib, Z__B_STREAM_MOD_BRIGHT | Z__B_STREAM_MOD_BOLD,
mod, attrib, Z__FX_STREAM_MOD_BRIGHT | Z__FX_STREAM_MOD_BOLD,
FOREGROUND_INTENSITY);
APPLY_FLAG(mod, attrib, Z__B_STREAM_MOD_BG_BRIGHT, BACKGROUND_INTENSITY);
APPLY_FLAG(mod, attrib, Z__FX_STREAM_MOD_BG_BRIGHT, BACKGROUND_INTENSITY);
SetConsoleTextAttribute(console, attrib);
return 0;

View File

@@ -1,4 +1,4 @@
#include <blue/term/tty.h>
#include <fx/term/tty.h>
#include "../../tty.h"
#include <stdio.h>
#include <string.h>
@@ -23,62 +23,62 @@
#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 {
HANDLE t_in, t_out;
DWORD t_canon_mode_in, t_canon_mode_out;
enum s_key_code t_repeat_key;
unsigned int t_repeat_count;
enum tty_flags t_flags;
struct b_tty_vmode t_vmode;
struct fx_tty_vmode t_vmode;
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 WORD ansi_colour16_fg[] = {
[B_TTY_COLOUR16_BLACK] = 0,
[B_TTY_COLOUR16_RED] = FOREGROUND_RED,
[B_TTY_COLOUR16_GREEN] = FOREGROUND_GREEN,
[B_TTY_COLOUR16_YELLOW] = FOREGROUND_RED | FOREGROUND_GREEN,
[B_TTY_COLOUR16_BLUE] = FOREGROUND_BLUE,
[B_TTY_COLOUR16_MAGENTA] = FOREGROUND_RED | FOREGROUND_BLUE,
[B_TTY_COLOUR16_CYAN] = FOREGROUND_GREEN | FOREGROUND_BLUE,
[B_TTY_COLOUR16_WHITE] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
[B_TTY_COLOUR16_BRIGHT_BLACK] = FOREGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_RED] = FOREGROUND_RED | FOREGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_GREEN] = FOREGROUND_GREEN | FOREGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_YELLOW] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_BLUE] = FOREGROUND_BLUE | FOREGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_MAGENTA] = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_CYAN] = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_WHITE] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BLACK] = 0,
[FX_TTY_COLOUR16_RED] = FOREGROUND_RED,
[FX_TTY_COLOUR16_GREEN] = FOREGROUND_GREEN,
[FX_TTY_COLOUR16_YELLOW] = FOREGROUND_RED | FOREGROUND_GREEN,
[FX_TTY_COLOUR16_FX] = FOREGROUND_FX,
[FX_TTY_COLOUR16_MAGENTA] = FOREGROUND_RED | FOREGROUND_FX,
[FX_TTY_COLOUR16_CYAN] = FOREGROUND_GREEN | FOREGROUND_FX,
[FX_TTY_COLOUR16_WHITE] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_FX,
[FX_TTY_COLOUR16_BRIGHT_BLACK] = FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_RED] = FOREGROUND_RED | FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_GREEN] = FOREGROUND_GREEN | FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_YELLOW] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_FX] = FOREGROUND_FX | FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_MAGENTA] = FOREGROUND_RED | FOREGROUND_FX | FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_CYAN] = FOREGROUND_GREEN | FOREGROUND_FX | FOREGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_WHITE] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_FX | FOREGROUND_INTENSITY,
};
static WORD ansi_colour16_bg[] = {
[B_TTY_COLOUR16_BLACK] = 0,
[B_TTY_COLOUR16_RED] = BACKGROUND_RED,
[B_TTY_COLOUR16_GREEN] = BACKGROUND_GREEN,
[B_TTY_COLOUR16_YELLOW] = BACKGROUND_RED | BACKGROUND_GREEN,
[B_TTY_COLOUR16_BLUE] = BACKGROUND_BLUE,
[B_TTY_COLOUR16_MAGENTA] = BACKGROUND_RED | BACKGROUND_BLUE,
[B_TTY_COLOUR16_CYAN] = BACKGROUND_GREEN | BACKGROUND_BLUE,
[B_TTY_COLOUR16_WHITE] = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE,
[B_TTY_COLOUR16_BRIGHT_BLACK] = BACKGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_RED] = BACKGROUND_RED | BACKGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_GREEN] = BACKGROUND_GREEN | BACKGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_YELLOW] = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_BLUE] = BACKGROUND_BLUE | BACKGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_MAGENTA] = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_CYAN] = BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY,
[B_TTY_COLOUR16_BRIGHT_WHITE] = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BLACK] = 0,
[FX_TTY_COLOUR16_RED] = BACKGROUND_RED,
[FX_TTY_COLOUR16_GREEN] = BACKGROUND_GREEN,
[FX_TTY_COLOUR16_YELLOW] = BACKGROUND_RED | BACKGROUND_GREEN,
[FX_TTY_COLOUR16_FX] = BACKGROUND_FX,
[FX_TTY_COLOUR16_MAGENTA] = BACKGROUND_RED | BACKGROUND_FX,
[FX_TTY_COLOUR16_CYAN] = BACKGROUND_GREEN | BACKGROUND_FX,
[FX_TTY_COLOUR16_WHITE] = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_FX,
[FX_TTY_COLOUR16_BRIGHT_BLACK] = BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_RED] = BACKGROUND_RED | BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_GREEN] = BACKGROUND_GREEN | BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_YELLOW] = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_FX] = BACKGROUND_FX | BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_MAGENTA] = BACKGROUND_RED | BACKGROUND_FX | BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_CYAN] = BACKGROUND_GREEN | BACKGROUND_FX | BACKGROUND_INTENSITY,
[FX_TTY_COLOUR16_BRIGHT_WHITE] = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_FX | BACKGROUND_INTENSITY,
};
static void init_tty(struct b_tty *tty, FILE *in, FILE *out)
static void init_tty(struct fx_tty *tty, FILE *in, FILE *out)
{
HANDLE in_handle = INVALID_HANDLE_VALUE;
HANDLE out_handle = INVALID_HANDLE_VALUE;
@@ -93,7 +93,7 @@ static void init_tty(struct b_tty *tty, FILE *in, FILE *out)
tty->t_in = in_handle;
tty->t_out = out_handle;
tty->t_flags |= B_TTY_INIT;
tty->t_flags |= FX_TTY_INIT;
CONSOLE_SCREEN_BUFFER_INFO csbi = {0};
DWORD mode = 0;
@@ -101,51 +101,51 @@ static void init_tty(struct b_tty *tty, FILE *in, FILE *out)
if (in && GetConsoleScreenBufferInfo(in_handle, &csbi)) {
GetConsoleMode(in_handle, &mode);
tty->t_canon_mode_in = mode;
tty->t_flags |= B_TTY_INTERACTIVE;
tty->t_flags |= FX_TTY_INTERACTIVE;
}
if (out && GetConsoleScreenBufferInfo(out_handle, &csbi)) {
GetConsoleMode(out_handle, &mode);
tty->t_canon_mode_out = mode;
tty->t_flags |= B_TTY_INTERACTIVE;
tty->t_flags |= FX_TTY_INTERACTIVE;
}
}
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)
{
DWORD x;
WriteConsoleA(tty->t_out, &c, 1, &x, NULL);
}
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 tty_set_raw(struct b_tty *tty)
static void tty_set_raw(struct fx_tty *tty)
{
DWORD mode = tty->t_canon_mode_in;
mode &= ~(ENABLE_ECHO_INPUT | ENABLE_INSERT_MODE | ENABLE_LINE_INPUT | ENABLE_QUICK_EDIT_MODE | ENABLE_WINDOW_INPUT);
@@ -157,19 +157,19 @@ static void tty_set_raw(struct b_tty *tty)
SetConsoleMode(tty->t_out, mode);
}
static void tty_set_canon(struct b_tty *tty)
static void tty_set_canon(struct fx_tty *tty)
{
SetConsoleMode(tty->t_in, tty->t_canon_mode_in);
SetConsoleMode(tty->t_out, tty->t_canon_mode_out);
}
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:
tty_set_canon(tty);
break;
case B_TTY_RAW:
case FX_TTY_RAW:
tty_set_raw(tty);
break;
default:
@@ -177,43 +177,43 @@ 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;
}
WORD attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
WORD attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_FX;
SetConsoleTextAttribute(tty->t_out, attrib);
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;
}
@@ -233,7 +233,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;
@@ -250,7 +250,7 @@ static int compare_vmode(const struct b_tty_vmode *a, const struct b_tty_vmode *
return 0;
}
static void set_attrib(WORD *attrp, enum b_tty_attrib old, enum b_tty_attrib new)
static void set_attrib(WORD *attrp, enum fx_tty_attrib old, enum fx_tty_attrib new)
{
if (old == new) {
return;
@@ -259,32 +259,32 @@ static void set_attrib(WORD *attrp, enum b_tty_attrib old, enum b_tty_attrib new
WORD attrib = *attrp;
/* Bold ON */
if (!(old & B_TTY_ATTRIB_BOLD) && new & B_TTY_ATTRIB_BOLD) {
if (!(old & FX_TTY_ATTRIB_BOLD) && new & FX_TTY_ATTRIB_BOLD) {
attrib |= FOREGROUND_INTENSITY;
}
/* Bold OFF */
if (old & B_TTY_ATTRIB_BOLD && !(new & B_TTY_ATTRIB_BOLD)) {
if (old & FX_TTY_ATTRIB_BOLD && !(new & FX_TTY_ATTRIB_BOLD)) {
attrib &= ~FOREGROUND_INTENSITY;
}
/* Underline ON */
if (!(old & B_TTY_ATTRIB_UNDERLINE) && new & B_TTY_ATTRIB_UNDERLINE) {
if (!(old & FX_TTY_ATTRIB_UNDERLINE) && new & FX_TTY_ATTRIB_UNDERLINE) {
attrib |= COMMON_LVB_UNDERSCORE;
}
/* Underline OFF */
if (old & B_TTY_ATTRIB_UNDERLINE && !(new & B_TTY_ATTRIB_UNDERLINE)) {
if (old & FX_TTY_ATTRIB_UNDERLINE && !(new & FX_TTY_ATTRIB_UNDERLINE)) {
attrib &= ~COMMON_LVB_UNDERSCORE;
}
/* Italic ON */
if (!(old & B_TTY_ATTRIB_ITALIC) && new & B_TTY_ATTRIB_ITALIC) {
if (!(old & FX_TTY_ATTRIB_ITALIC) && new & FX_TTY_ATTRIB_ITALIC) {
/* not supported */
}
/* Italic OFF */
if (old & B_TTY_ATTRIB_ITALIC && !(new & B_TTY_ATTRIB_ITALIC)) {
if (old & FX_TTY_ATTRIB_ITALIC && !(new & FX_TTY_ATTRIB_ITALIC)) {
/* not supported */
}
@@ -292,22 +292,22 @@ static void set_attrib(WORD *attrp, enum b_tty_attrib old, enum b_tty_attrib new
}
static void set_fg(
WORD *attrp, const struct b_tty_colour *old,
const struct b_tty_colour *new)
WORD *attrp, const struct fx_tty_colour *old,
const struct fx_tty_colour *new)
{
if (compare_colour(old, new) == 0) {
return;
}
WORD attrib = *attrp;
attrib &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
attrib &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_FX | FOREGROUND_INTENSITY);
switch (new->c_mode) {
case B_TTY_COLOUR_16:
case FX_TTY_COLOUR_16:
attrib |= ansi_colour16_fg[new->c_16.value];
break;
default:
attrib |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
attrib |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_FX;
break;
}
@@ -315,27 +315,27 @@ static void set_fg(
}
static void set_bg(
WORD *attrp, const struct b_tty_colour *old,
const struct b_tty_colour *new)
WORD *attrp, const struct fx_tty_colour *old,
const struct fx_tty_colour *new)
{
if (compare_colour(old, new) == 0) {
return;
}
WORD attrib = *attrp;
attrib &= ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
attrib &= ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_FX | BACKGROUND_INTENSITY);
switch (new->c_mode) {
case B_TTY_COLOUR_16:
case FX_TTY_COLOUR_16:
attrib |= ansi_colour16_bg[new->c_16.value];
break;
default:
attrib |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;
attrib |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_FX;
break;
}
}
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;
@@ -357,10 +357,10 @@ void b_tty_set_vmode(struct b_tty *tty, const struct b_tty_vmode *vmode)
memcpy(&tty->t_vmode, vmode, sizeof *vmode);
}
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)) {
return B_ERR_NOT_SUPPORTED;
if (!(tty->t_flags & FX_TTY_INTERACTIVE)) {
return FX_ERR_NOT_SUPPORTED;
}
CONSOLE_SCREEN_BUFFER_INFO csbi = {0};
@@ -374,13 +374,13 @@ enum b_status b_tty_get_dimensions(struct b_tty* tty, unsigned int* w, unsigned
*h = csbi.srWindow.Bottom - csbi.srWindow.Top;
}
return B_SUCCESS;
return FX_SUCCESS;
}
enum b_status b_tty_get_cursor_position(struct b_tty *tty, unsigned int *x, unsigned int *y)
enum fx_status fx_tty_get_cursor_position(struct fx_tty *tty, unsigned int *x, unsigned int *y)
{
if (!(tty->t_flags & B_TTY_INTERACTIVE)) {
return B_ERR_NOT_SUPPORTED;
if (!(tty->t_flags & FX_TTY_INTERACTIVE)) {
return FX_ERR_NOT_SUPPORTED;
}
CONSOLE_SCREEN_BUFFER_INFO csbi = {0};
@@ -394,10 +394,10 @@ enum b_status b_tty_get_cursor_position(struct b_tty *tty, unsigned int *x, unsi
*y = csbi.dwCursorPosition.Y;
}
return B_SUCCESS;
return FX_SUCCESS;
}
b_keycode b_tty_read_key(struct b_tty *tty)
fx_keycode fx_tty_read_key(struct fx_tty *tty)
{
if (tty->t_repeat_count > 0) {
tty->t_repeat_count--;
@@ -413,7 +413,7 @@ b_keycode b_tty_read_key(struct b_tty *tty)
while (1) {
status = ReadConsoleInputA(in, &d, 1, &nr_read);
if (status == FALSE) {
return B_KEY_EOF;
return FX_KEY_EOF;
}
if (d.EventType != KEY_EVENT) {
@@ -424,7 +424,7 @@ b_keycode b_tty_read_key(struct b_tty *tty)
continue;
}
b_keycode key = 0;
fx_keycode key = 0;
switch (d.Event.KeyEvent.wVirtualKeyCode) {
case VK_CONTROL:
@@ -434,22 +434,22 @@ b_keycode b_tty_read_key(struct b_tty *tty)
case VK_MENU:
continue;
case VK_UP:
key = B_KEY_ARROW_UP;
key = FX_KEY_ARROW_UP;
break;
case VK_DOWN:
key = B_KEY_ARROW_DOWN;
key = FX_KEY_ARROW_DOWN;
break;
case VK_LEFT:
key = B_KEY_ARROW_LEFT;
key = FX_KEY_ARROW_LEFT;
break;
case VK_RIGHT:
key = B_KEY_ARROW_RIGHT;
key = FX_KEY_ARROW_RIGHT;
break;
case VK_BACK:
key = B_KEY_BACKSPACE;
key = FX_KEY_BACKSPACE;
break;
case VK_RETURN:
key = B_KEY_RETURN;
key = FX_KEY_RETURN;
break;
default:
if (d.Event.KeyEvent.uChar.UnicodeChar == 0) {
@@ -461,7 +461,7 @@ b_keycode b_tty_read_key(struct b_tty *tty)
}
if (d.Event.KeyEvent.dwControlKeyState & LEFT_CTRL_PRESSED) {
key = B_TTY_CTRL_KEY('a' + key - 1);
key = FX_TTY_CTRL_KEY('a' + key - 1);
}
if (d.Event.KeyEvent.wRepeatCount > 1) {
@@ -472,11 +472,11 @@ b_keycode b_tty_read_key(struct b_tty *tty)
return key;
}
return B_KEY_EOF;
return FX_KEY_EOF;
}
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)
{
CONSOLE_SCREEN_BUFFER_INFO console = {0};
GetConsoleScreenBufferInfo(tty->t_out, &console);
@@ -484,10 +484,10 @@ void b_tty_move_cursor_x(
cursor_pos.Y = console.dwCursorPosition.Y;
switch (base) {
case B_TTY_POS_CURSOR:
case FX_TTY_POS_CURSOR:
cursor_pos.X = console.dwCursorPosition.X + pos;
break;
case B_TTY_POS_START:
case FX_TTY_POS_START:
cursor_pos.X = pos;
break;
default:
@@ -497,7 +497,7 @@ void b_tty_move_cursor_x(
SetConsoleCursorPosition(tty->t_out, cursor_pos);
}
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)
{
CONSOLE_SCREEN_BUFFER_INFO console = {0};
GetConsoleScreenBufferInfo(tty->t_out, &console);
@@ -505,10 +505,10 @@ void b_tty_move_cursor_y(struct b_tty *tty, enum b_tty_position_base base, int p
cursor_pos.X = console.dwCursorPosition.X;
switch (base) {
case B_TTY_POS_CURSOR:
case FX_TTY_POS_CURSOR:
cursor_pos.Y = console.dwCursorPosition.Y + pos;
break;
case B_TTY_POS_START:
case FX_TTY_POS_START:
cursor_pos.Y = pos;
break;
default:
@@ -518,7 +518,7 @@ void b_tty_move_cursor_y(struct b_tty *tty, enum b_tty_position_base base, int p
SetConsoleCursorPosition(tty->t_out, cursor_pos);
}
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)
{
CONSOLE_SCREEN_BUFFER_INFO console = {0};
GetConsoleScreenBufferInfo(tty->t_out, &console);
@@ -529,13 +529,13 @@ void b_tty_clear(struct b_tty *tty, enum b_tty_clear_mode mode)
DWORD all_length = 0, line_length = 0;
if (mode & B_TTY_CLEAR_ALL) {
if (mode & FX_TTY_CLEAR_ALL) {
line_length = console.dwSize.X;
all_length = line_length * console.dwSize.Y;
} else if (mode & B_TTY_CLEAR_FROM_CURSOR) {
} else if (mode & FX_TTY_CLEAR_FROM_CURSOR) {
line_length = console.dwSize.X - console.dwCursorPosition.X + 1;
all_length = line_length + ((console.dwSize.Y - console.dwCursorPosition.Y) * console.dwSize.X);
} else if (mode & B_TTY_CLEAR_TO_CURSOR) {
} else if (mode & FX_TTY_CLEAR_TO_CURSOR) {
line_length = console.dwCursorPosition.X;
all_length = line_length
+ ((console.dwCursorPosition.Y - 1) * console.dwSize.X);
@@ -543,22 +543,22 @@ void b_tty_clear(struct b_tty *tty, enum b_tty_clear_mode mode)
abort();
}
if (mode & B_TTY_CLEAR_SCREEN) {
if (mode & FX_TTY_CLEAR_SCREEN) {
length = all_length;
if ((mode & B_TTY_CLEAR_ALL) || (mode & B_TTY_CLEAR_TO_CURSOR)) {
if ((mode & FX_TTY_CLEAR_ALL) || (mode & FX_TTY_CLEAR_TO_CURSOR)) {
start.X = 0;
start.Y = 0;
} else if (mode & B_TTY_CLEAR_FROM_CURSOR) {
} else if (mode & FX_TTY_CLEAR_FROM_CURSOR) {
start = console.dwCursorPosition;
}
} else if (mode & B_TTY_CLEAR_LINE) {
} else if (mode & FX_TTY_CLEAR_LINE) {
length = line_length;
if ((mode & B_TTY_CLEAR_ALL) || (mode & B_TTY_CLEAR_TO_CURSOR)) {
if ((mode & FX_TTY_CLEAR_ALL) || (mode & FX_TTY_CLEAR_TO_CURSOR)) {
start.X = 0;
start.Y = console.dwCursorPosition.Y;
} else if (mode & B_TTY_CLEAR_FROM_CURSOR) {
} else if (mode & FX_TTY_CLEAR_FROM_CURSOR) {
start = console.dwCursorPosition;
}
} else {

View File

@@ -1,14 +1,14 @@
#include "tty.h"
#include <blue/core/hash.h>
#include <blue/term/tty.h>
#include <fx/core/hash.h>
#include <fx/term/tty.h>
#include <string.h>
#define MOD_HASH_BLACK 0x4b5dd0abbc6fc1e4
#define MOD_HASH_RED 0x89e9be1960f4c21c
#define MOD_HASH_GREEN 0x0f40f029637fecbc
#define MOD_HASH_YELLOW 0x8346a574925e75a9
#define MOD_HASH_BLUE 0xc5ccd29bc2dda64d
#define MOD_HASH_FX 0xc5ccd29bc2dda64d
#define MOD_HASH_MAGENTA 0x6c90e772edbc8708
#define MOD_HASH_CYAN 0x70ae2e90c1bce27a
#define MOD_HASH_WHITE 0xced973885856e206
@@ -17,7 +17,7 @@
#define MOD_HASH_BRIGHT_RED 0xbad8e3fe841b9385
#define MOD_HASH_BRIGHT_GREEN 0x11cc5e579bdd2fb9
#define MOD_HASH_BRIGHT_YELLOW 0xfd579007fe8579f6
#define MOD_HASH_BRIGHT_BLUE 0x57c76bf18badb6d6
#define MOD_HASH_BRIGHT_FX 0x57c76bf18badb6d6
#define MOD_HASH_BRIGHT_MAGENTA 0xf6ecc6d3fdfec129
#define MOD_HASH_BRIGHT_CYAN 0x03df73fd4e12ec6d
#define MOD_HASH_BRIGHT_WHITE 0xb5ebc3323f57d7fb
@@ -26,7 +26,7 @@
#define MOD_HASH_BG_RED 0x145b1e4366c7d7aa
#define MOD_HASH_BG_GREEN 0xa00b8541d3b1e55a
#define MOD_HASH_BG_YELLOW 0x98b030fd86e3b3cf
#define MOD_HASH_BG_BLUE 0xa15529109506b5df
#define MOD_HASH_BG_FX 0xa15529109506b5df
#define MOD_HASH_BG_MAGENTA 0x86dbda99bcc86222
#define MOD_HASH_BG_CYAN 0xf16a3104cf61a098
#define MOD_HASH_BG_WHITE 0x3408c46ab5836674
@@ -35,7 +35,7 @@
#define MOD_HASH_BRIGHT_BG_RED 0x144f5dc138087701
#define MOD_HASH_BRIGHT_BG_GREEN 0xc4d88c6426ffe355
#define MOD_HASH_BRIGHT_BG_YELLOW 0xf7bb000a4a792602
#define MOD_HASH_BRIGHT_BG_BLUE 0x9b5c16d6807a1002
#define MOD_HASH_BRIGHT_BG_FX 0x9b5c16d6807a1002
#define MOD_HASH_BRIGHT_BG_MAGENTA 0xc59fb2196cdba3fd
#define MOD_HASH_BRIGHT_BG_CYAN 0x46feb6dc999a6f09
#define MOD_HASH_BRIGHT_BG_WHITE 0xa3e7d1da08826f5f
@@ -51,206 +51,206 @@
static void apply_code_to_vmode(struct tty_format_buf *fmt)
{
const char *modifier = fmt->buf;
uint64_t mod_hash = b_hash_cstr(modifier);
uint64_t mod_hash = fx_hash_cstr(modifier);
if (COMPARE_MOD_NAME(modifier, "black", mod_hash, MOD_HASH_BLACK)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BLACK;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BLACK;
}
if (COMPARE_MOD_NAME(modifier, "red", mod_hash, MOD_HASH_RED)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_RED;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_RED;
}
if (COMPARE_MOD_NAME(modifier, "green", mod_hash, MOD_HASH_GREEN)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_GREEN;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_GREEN;
}
if (COMPARE_MOD_NAME(modifier, "yellow", mod_hash, MOD_HASH_YELLOW)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_YELLOW;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_YELLOW;
}
if (COMPARE_MOD_NAME(modifier, "blue", mod_hash, MOD_HASH_BLUE)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BLUE;
if (COMPARE_MOD_NAME(modifier, "blue", mod_hash, MOD_HASH_FX)) {
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_FX;
}
if (COMPARE_MOD_NAME(modifier, "magenta", mod_hash, MOD_HASH_MAGENTA)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_MAGENTA;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_MAGENTA;
}
if (COMPARE_MOD_NAME(modifier, "cyan", mod_hash, MOD_HASH_CYAN)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_CYAN;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_CYAN;
}
if (COMPARE_MOD_NAME(modifier, "white", mod_hash, MOD_HASH_WHITE)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_WHITE;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_WHITE;
}
if (COMPARE_MOD_NAME(modifier, "dark_grey", mod_hash, MOD_HASH_DARK_GREY)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_BLACK;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_BLACK;
}
if (COMPARE_MOD_NAME(modifier, "bright_red", mod_hash, MOD_HASH_BRIGHT_RED)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_RED;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_RED;
}
if (COMPARE_MOD_NAME(
modifier, "bright_green", mod_hash, MOD_HASH_BRIGHT_GREEN)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_GREEN;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_GREEN;
}
if (COMPARE_MOD_NAME(
modifier, "bright_yellow", mod_hash, MOD_HASH_BRIGHT_YELLOW)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_YELLOW;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_YELLOW;
}
if (COMPARE_MOD_NAME(
modifier, "bright_blue", mod_hash, MOD_HASH_BRIGHT_BLUE)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_BLUE;
modifier, "bright_blue", mod_hash, MOD_HASH_BRIGHT_FX)) {
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_FX;
}
if (COMPARE_MOD_NAME(
modifier, "bright_magenta", mod_hash, MOD_HASH_BRIGHT_MAGENTA)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_MAGENTA;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_MAGENTA;
}
if (COMPARE_MOD_NAME(
modifier, "bright_cyan", mod_hash, MOD_HASH_BRIGHT_CYAN)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_CYAN;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_CYAN;
}
if (COMPARE_MOD_NAME(
modifier, "bright_white", mod_hash, MOD_HASH_BRIGHT_WHITE)) {
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = B_TTY_COLOUR16_BRIGHT_WHITE;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_fg.c_16.value = FX_TTY_COLOUR16_BRIGHT_WHITE;
}
if (COMPARE_MOD_NAME(modifier, "bg_black", mod_hash, MOD_HASH_BG_BLACK)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BLACK;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BLACK;
}
if (COMPARE_MOD_NAME(modifier, "bg_red", mod_hash, MOD_HASH_BG_RED)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_RED;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_RED;
}
if (COMPARE_MOD_NAME(modifier, "bg_green", mod_hash, MOD_HASH_BG_GREEN)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_GREEN;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_GREEN;
}
if (COMPARE_MOD_NAME(modifier, "bg_yellow", mod_hash, MOD_HASH_BG_YELLOW)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_YELLOW;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_YELLOW;
}
if (COMPARE_MOD_NAME(modifier, "bg_blue", mod_hash, MOD_HASH_BG_BLUE)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BLUE;
if (COMPARE_MOD_NAME(modifier, "bg_blue", mod_hash, MOD_HASH_BG_FX)) {
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_FX;
}
if (COMPARE_MOD_NAME(modifier, "bg_magenta", mod_hash, MOD_HASH_BG_MAGENTA)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_MAGENTA;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_MAGENTA;
}
if (COMPARE_MOD_NAME(modifier, "bg_cyan", mod_hash, MOD_HASH_BG_CYAN)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_CYAN;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_CYAN;
}
if (COMPARE_MOD_NAME(modifier, "bg_white", mod_hash, MOD_HASH_BG_WHITE)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_WHITE;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_WHITE;
}
if (COMPARE_MOD_NAME(
modifier, "bg_dark_grey", mod_hash, MOD_HASH_BG_DARK_GREY)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_BLACK;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_BLACK;
}
if (COMPARE_MOD_NAME(
modifier, "bright_bg_red", mod_hash, MOD_HASH_BRIGHT_BG_RED)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_RED;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_RED;
}
if (COMPARE_MOD_NAME(
modifier, "bright_bg_green", mod_hash,
MOD_HASH_BRIGHT_BG_GREEN)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_GREEN;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_GREEN;
}
if (COMPARE_MOD_NAME(
modifier, "bright_bg_yellow", mod_hash,
MOD_HASH_BRIGHT_BG_YELLOW)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_YELLOW;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_YELLOW;
}
if (COMPARE_MOD_NAME(
modifier, "bright_bg_blue", mod_hash, MOD_HASH_BRIGHT_BG_BLUE)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_BLUE;
modifier, "bright_bg_blue", mod_hash, MOD_HASH_BRIGHT_BG_FX)) {
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_FX;
}
if (COMPARE_MOD_NAME(
modifier, "bright_bg_magenta", mod_hash,
MOD_HASH_BRIGHT_BG_MAGENTA)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_MAGENTA;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_MAGENTA;
}
if (COMPARE_MOD_NAME(
modifier, "bright_bg_cyan", mod_hash, MOD_HASH_BRIGHT_BG_CYAN)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_CYAN;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_CYAN;
}
if (COMPARE_MOD_NAME(
modifier, "bright_bg_white", mod_hash,
MOD_HASH_BRIGHT_BG_WHITE)) {
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = B_TTY_COLOUR16_BRIGHT_WHITE;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_16;
fmt->vmode.v_bg.c_16.value = FX_TTY_COLOUR16_BRIGHT_WHITE;
}
if (COMPARE_MOD_NAME(modifier, "bold", mod_hash, MOD_HASH_BOLD)) {
fmt->vmode.v_attrib |= B_TTY_ATTRIB_BOLD;
fmt->vmode.v_attrib |= FX_TTY_ATTRIB_BOLD;
}
if (COMPARE_MOD_NAME(modifier, "uline", mod_hash, MOD_HASH_ULINE)) {
fmt->vmode.v_attrib |= B_TTY_ATTRIB_UNDERLINE;
fmt->vmode.v_attrib |= FX_TTY_ATTRIB_UNDERLINE;
}
if (COMPARE_MOD_NAME(modifier, "italic", mod_hash, MOD_HASH_ITALIC)) {
fmt->vmode.v_attrib |= B_TTY_ATTRIB_ITALIC;
fmt->vmode.v_attrib |= FX_TTY_ATTRIB_ITALIC;
}
if (COMPARE_MOD_NAME(modifier, "invert", mod_hash, MOD_HASH_INVERT)) {
fmt->vmode.v_attrib |= B_TTY_ATTRIB_INVERT;
fmt->vmode.v_attrib |= FX_TTY_ATTRIB_INVERT;
}
if (COMPARE_MOD_NAME(modifier, "reset", mod_hash, MOD_HASH_RESET)) {
fmt->reset_vmode = true;
fmt->vmode.v_fg.c_mode = B_TTY_COLOUR_NONE;
fmt->vmode.v_bg.c_mode = B_TTY_COLOUR_NONE;
fmt->vmode.v_fg.c_mode = FX_TTY_COLOUR_NONE;
fmt->vmode.v_bg.c_mode = FX_TTY_COLOUR_NONE;
fmt->vmode.v_attrib = 0;
}
}
@@ -270,23 +270,23 @@ static void format_buffer_clear(struct tty_format_buf *fmt)
fmt->reset_vmode = false;
}
static void flush_vmode(struct b_tty *tty, struct tty_format_buf *fmt)
static void flush_vmode(struct fx_tty *tty, struct tty_format_buf *fmt)
{
if (fmt->reset_vmode) {
b_tty_reset_vmode(tty);
fx_tty_reset_vmode(tty);
} else {
b_tty_set_vmode(tty, &fmt->vmode);
fx_tty_set_vmode(tty, &fmt->vmode);
}
}
int b_tty_putc(struct b_tty *tty, enum b_tty_print_flags flags, char c)
int fx_tty_putc(struct fx_tty *tty, enum fx_tty_print_flags flags, char c)
{
if (flags & B_TTY_DISABLE_FORMATTING) {
z__b_tty_putc(tty, c);
if (flags & FX_TTY_DISABLE_FORMATTING) {
z__fx_tty_putc(tty, c);
return c;
}
struct tty_format_buf *fmt = z__b_tty_get_format_buf(tty);
struct tty_format_buf *fmt = z__fx_tty_get_format_buf(tty);
if (c == '[') {
if (!fmt->in_format) {
@@ -296,7 +296,7 @@ int b_tty_putc(struct b_tty *tty, enum b_tty_print_flags flags, char c)
if (fmt->ptr == 0) {
fmt->in_format = false;
z__b_tty_putc(tty, '[');
z__fx_tty_putc(tty, '[');
return c;
}
@@ -322,29 +322,29 @@ int b_tty_putc(struct b_tty *tty, enum b_tty_print_flags flags, char c)
if (fmt->in_format) {
format_buffer_putc(fmt, c);
} else {
z__b_tty_putc(tty, c);
z__fx_tty_putc(tty, c);
}
return c;
}
int b_tty_puts(struct b_tty *tty, enum b_tty_print_flags flags, const char *s)
int fx_tty_puts(struct fx_tty *tty, enum fx_tty_print_flags flags, const char *s)
{
int r = 0;
while (s[r]) {
b_tty_putc(tty, flags, s[r]);
fx_tty_putc(tty, flags, s[r]);
r++;
}
return r;
}
int b_tty_printf(struct b_tty *tty, enum b_tty_print_flags flags, const char *s, ...)
int fx_tty_printf(struct fx_tty *tty, enum fx_tty_print_flags flags, const char *s, ...)
{
va_list arg;
va_start(arg, s);
int r = b_tty_vprintf(tty, flags, s, arg);
int r = fx_tty_vprintf(tty, flags, s, arg);
va_end(arg);
return r;
}

View File

@@ -1,12 +1,12 @@
#ifndef _TTY_H_
#define _TTY_H_
#include <blue/term/tty.h>
#include <fx/term/tty.h>
#include <stdbool.h>
#define TTY_TMPBUF_SIZE 128
struct b_tty;
struct fx_tty;
struct tty_format_buf {
bool in_format;
@@ -14,10 +14,10 @@ struct tty_format_buf {
char buf[TTY_TMPBUF_SIZE];
unsigned int ptr;
struct b_tty_vmode vmode;
struct fx_tty_vmode vmode;
};
extern struct tty_format_buf *z__b_tty_get_format_buf(struct b_tty *tty);
extern void z__b_tty_putc(struct b_tty *tty, char c);
extern struct tty_format_buf *z__fx_tty_get_format_buf(struct fx_tty *tty);
extern void z__fx_tty_putc(struct fx_tty *tty, char c);
#endif