meta: replace bluelib references with fx

This commit is contained in:
2026-03-16 13:59:14 +00:00
parent 73b4b77816
commit ef858dd061
106 changed files with 1402 additions and 1389 deletions

View File

@@ -1,7 +1,7 @@
#include <assert.h>
#include <blue/core/stringstream.h>
#include <blue/term/print.h>
#include <blue/term/tty.h>
#include <fx/core/stringstream.h>
#include <fx/term/print.h>
#include <fx/term/tty.h>
#include <ctype.h>
#include <mie/diag/amendment.h>
#include <mie/diag/class.h>
@@ -15,16 +15,16 @@
#define GET_CHAR_CONTINUE -1
struct snippet_print_ctx {
b_tty *ctx_stream;
fx_tty *ctx_stream;
struct mie_line_source *ctx_line_source;
size_t ctx_row, ctx_col;
size_t ctx_indent_offset;
bool ctx_has_underline, ctx_in_content;
b_stringstream *ctx_underline;
const b_string *ctx_linebuf;
const b_iterator *ctx_linebuf_ptr;
fx_stringstream *ctx_underline;
const fx_string *ctx_linebuf;
const fx_iterator *ctx_linebuf_ptr;
struct mie_diag_c_snippet *ctx_snippet;
@@ -40,31 +40,31 @@ struct snippet_print_ctx {
#define __STREAM_COLOUR_RESET "[reset]"
#define STREAM_COLOUR_ERROR(stream) \
b_tty_puts(stream, 0, __STREAM_COLOUR_ERROR);
#define STREAM_COLOUR_WARN(stream) b_tty_puts(stream, 0, __STREAM_COLOUR_WARN);
#define STREAM_COLOUR_HINT(stream) b_tty_puts(stream, 0, __STREAM_COLOUR_HINT);
fx_tty_puts(stream, 0, __STREAM_COLOUR_ERROR);
#define STREAM_COLOUR_WARN(stream) fx_tty_puts(stream, 0, __STREAM_COLOUR_WARN);
#define STREAM_COLOUR_HINT(stream) fx_tty_puts(stream, 0, __STREAM_COLOUR_HINT);
#define STREAM_COLOUR_ACCENT(stream) \
b_tty_puts(stream, 0, __STREAM_COLOUR_ACCENT);
fx_tty_puts(stream, 0, __STREAM_COLOUR_ACCENT);
#define STREAM_COLOUR_LINE_NO(stream) \
b_tty_puts(stream, 0, __STREAM_COLOUR_LINE_NO);
fx_tty_puts(stream, 0, __STREAM_COLOUR_LINE_NO);
#define STREAM_COLOUR_RESET(stream) \
b_tty_puts(stream, 0, __STREAM_COLOUR_RESET);
fx_tty_puts(stream, 0, __STREAM_COLOUR_RESET);
#define STREAM_COLOUR_ERROR_B(stream, str) \
b_stream_write_string(str, __STREAM_COLOUR_ERROR, NULL);
fx_stream_write_string(str, __STREAM_COLOUR_ERROR, NULL);
#define STREAM_COLOUR_WARN_B(stream, str) \
b_stream_write_string(str, __STREAM_COLOUR_WARN, NULL);
fx_stream_write_string(str, __STREAM_COLOUR_WARN, NULL);
#define STREAM_COLOUR_HINT_B(stream, str) \
b_stream_write_string(str, __STREAM_COLOUR_HINT, NULL);
fx_stream_write_string(str, __STREAM_COLOUR_HINT, NULL);
#define STREAM_COLOUR_ACCENT_B(stream, str) \
b_stream_write_string(str, __STREAM_COLOUR_ACCENT, NULL);
fx_stream_write_string(str, __STREAM_COLOUR_ACCENT, NULL);
#define STREAM_COLOUR_RESET_B(stream, str) \
b_stream_write_string(str, __STREAM_COLOUR_RESET, NULL);
fx_stream_write_string(str, __STREAM_COLOUR_RESET, NULL);
static void print_header(struct mie_diag *diag, b_tty *dest)
static void print_header(struct mie_diag *diag, fx_tty *dest)
{
unsigned int w;
b_tty_get_dimensions(dest, &w, NULL);
fx_tty_get_dimensions(dest, &w, NULL);
const struct mie_diag_class *diag_class = diag->diag_class;
assert(diag_class);
@@ -72,51 +72,51 @@ static void print_header(struct mie_diag *diag, b_tty *dest)
STREAM_COLOUR_ACCENT(dest);
size_t nr_written = 0;
nr_written += b_tty_puts(dest, 0, "--- ");
nr_written += fx_tty_puts(dest, 0, "--- ");
const char *s = diag_class->c_title;
while (*s) {
b_tty_putc(dest, 0, toupper(*s));
fx_tty_putc(dest, 0, toupper(*s));
s++;
nr_written++;
}
b_tty_putc(dest, 0, ' ');
fx_tty_putc(dest, 0, ' ');
nr_written++;
while (nr_written < w) {
b_tty_putc(dest, 0, '-');
fx_tty_putc(dest, 0, '-');
nr_written++;
}
STREAM_COLOUR_RESET(dest);
b_tty_putc(dest, 0, '\n');
fx_tty_putc(dest, 0, '\n');
}
static void print_location(struct mie_diag *diag, b_tty *out)
static void print_location(struct mie_diag *diag, fx_tty *out)
{
size_t x;
const char *name = mie_line_source_get_path(diag->diag_src);
b_tty_puts(out, 0, " ");
fx_tty_puts(out, 0, " ");
STREAM_COLOUR_ACCENT(out);
b_tty_puts(out, 0, "> ");
fx_tty_puts(out, 0, "> ");
STREAM_COLOUR_RESET(out);
b_tty_printf(
fx_tty_printf(
out, 0, "%s:%lu:%lu\n", name, diag->diag_loc.c_row,
diag->diag_loc.c_col);
}
static void print_msg(
struct mie_diag *diag, struct mie_diag_c_msg *msg, b_tty *stream)
struct mie_diag *diag, struct mie_diag_c_msg *msg, fx_tty *stream)
{
b_paragraph_format format = {
fx_paragraph_format format = {
.p_left_margin = 2,
.p_right_margin = 2,
};
b_print_paragraph(msg->msg_content, stream, &format);
fx_print_paragraph(msg->msg_content, stream, &format);
}
static bool highlight_contains_cell(
@@ -181,7 +181,7 @@ static bool amendment_contains_cell(
}
limit = a->a_replace.a_loc.c_row
+ b_max(ulong, a->a_replace.a_length, a->__x) - 1;
+ fx_max(ulong, a->a_replace.a_length, a->__x) - 1;
if (col > limit) {
return false;
@@ -280,7 +280,7 @@ static void update_highlighting(struct snippet_print_ctx *ctx)
static enum mie_status read_row(struct snippet_print_ctx *ctx, size_t row)
{
if (ctx->ctx_linebuf_ptr) {
b_iterator_unref(ctx->ctx_linebuf_ptr);
fx_iterator_unref(ctx->ctx_linebuf_ptr);
ctx->ctx_linebuf_ptr = NULL;
}
@@ -293,7 +293,7 @@ static enum mie_status read_row(struct snippet_print_ctx *ctx, size_t row)
return status;
}
ctx->ctx_linebuf_ptr = b_iterator_cbegin(ctx->ctx_linebuf);
ctx->ctx_linebuf_ptr = fx_iterator_cbegin(ctx->ctx_linebuf);
return MIE_SUCCESS;
}
@@ -309,7 +309,7 @@ static int get_char_amendment(struct snippet_print_ctx *ctx)
- 1;
return a->a_add.a_str[i];
case MIE_DIAG_AMENDMENT_REMOVE:
b_iterator_move_next(ctx->ctx_linebuf_ptr);
fx_iterator_move_next(ctx->ctx_linebuf_ptr);
return GET_CHAR_CONTINUE;
case MIE_DIAG_AMENDMENT_REPLACE:
i = ctx->ctx_col - a->a_add.a_loc.c_col;
@@ -320,7 +320,7 @@ static int get_char_amendment(struct snippet_print_ctx *ctx)
c = a->a_replace.a_str[i];
if (i < a->a_replace.a_length) {
b_iterator_move_next(ctx->ctx_linebuf_ptr);
fx_iterator_move_next(ctx->ctx_linebuf_ptr);
}
if (c != 0) {
@@ -341,15 +341,15 @@ static int get_char(struct snippet_print_ctx *ctx)
return get_char_amendment(ctx);
}
b_wchar c = B_WCHAR_INVALID;
fx_wchar c = FX_WCHAR_INVALID;
while (1) {
c = b_iterator_get_cvalue(ctx->ctx_linebuf_ptr).v_int;
if (c == B_WCHAR_INVALID) {
c = fx_iterator_get_cvalue(ctx->ctx_linebuf_ptr).v_int;
if (c == FX_WCHAR_INVALID) {
return GET_CHAR_STOP;
}
b_iterator_move_next(ctx->ctx_linebuf_ptr);
fx_iterator_move_next(ctx->ctx_linebuf_ptr);
if (isspace(c) && !ctx->ctx_in_content) {
ctx->ctx_indent_offset++;
@@ -364,7 +364,7 @@ static int get_char(struct snippet_print_ctx *ctx)
static void update_underline(struct snippet_print_ctx *ctx)
{
if (!ctx->ctx_hl) {
b_stream_write_char(ctx->ctx_underline, ' ');
fx_stream_write_char(ctx->ctx_underline, ' ');
return;
}
@@ -372,10 +372,10 @@ static void update_underline(struct snippet_print_ctx *ctx)
case MIE_DIAG_HIGHLIGHT_ERROR:
case MIE_DIAG_HIGHLIGHT_WARNING:
case MIE_DIAG_HIGHLIGHT_HINT:
b_stream_write_char(ctx->ctx_underline, '^');
fx_stream_write_char(ctx->ctx_underline, '^');
break;
default:
b_stream_write_char(ctx->ctx_underline, ' ');
fx_stream_write_char(ctx->ctx_underline, ' ');
break;
}
}
@@ -388,28 +388,28 @@ static void write_underline(struct snippet_print_ctx *ctx)
STREAM_COLOUR_RESET(ctx->ctx_stream);
STREAM_COLOUR_LINE_NO(ctx->ctx_stream);
b_tty_puts(ctx->ctx_stream, 0, " : ");
b_tty_puts(ctx->ctx_stream, 0, b_stringstream_ptr(ctx->ctx_underline));
fx_tty_puts(ctx->ctx_stream, 0, " : ");
fx_tty_puts(ctx->ctx_stream, 0, fx_stringstream_ptr(ctx->ctx_underline));
STREAM_COLOUR_RESET(ctx->ctx_stream);
b_tty_putc(ctx->ctx_stream, 0, '\n');
fx_tty_putc(ctx->ctx_stream, 0, '\n');
}
static void print_snippet(
struct mie_diag *diag, struct mie_diag_c_snippet *snippet, b_tty *stream)
struct mie_diag *diag, struct mie_diag_c_snippet *snippet, fx_tty *stream)
{
enum mie_status status = MIE_SUCCESS;
struct snippet_print_ctx printer = {
.ctx_stream = stream,
.ctx_snippet = snippet,
.ctx_underline = b_stringstream_create(),
.ctx_underline = fx_stringstream_create(),
.ctx_line_source = diag->diag_src,
};
for (unsigned long row = snippet->s_first_line;
row <= snippet->s_last_line; row++) {
STREAM_COLOUR_LINE_NO(stream);
b_tty_printf(stream, 0, " %4lu | ", row);
fx_tty_printf(stream, 0, " %4lu | ", row);
printer.ctx_row = row;
status = read_row(&printer, row);
@@ -433,23 +433,23 @@ static void print_snippet(
update_highlighting(&printer);
if (c == '[') {
b_tty_putc(stream, 0, c);
fx_tty_putc(stream, 0, c);
}
b_tty_putc(stream, 0, c);
fx_tty_putc(stream, 0, c);
update_underline(&printer);
}
b_tty_putc(stream, 0, '\n');
fx_tty_putc(stream, 0, '\n');
write_underline(&printer);
}
b_stringstream_unref(printer.ctx_underline);
fx_stringstream_unref(printer.ctx_underline);
}
static void print_component(
struct mie_diag *diag, struct mie_diag_component *component, b_tty *stream)
struct mie_diag *diag, struct mie_diag_component *component, fx_tty *stream)
{
switch (component->c_type) {
case MIE_DIAG_COMPONENT_MSG:
@@ -463,20 +463,20 @@ static void print_component(
}
}
enum mie_status mie_diag_write_pretty(struct mie_diag *diag, b_tty *stream)
enum mie_status mie_diag_write_pretty(struct mie_diag *diag, fx_tty *stream)
{
print_header(diag, stream);
print_location(diag, stream);
b_queue_entry *entry = b_queue_first(&diag->diag_components);
fx_queue_entry *entry = fx_queue_first(&diag->diag_components);
while (entry) {
struct mie_diag_component *c
= b_unbox(struct mie_diag_component, entry, c_entry);
= fx_unbox(struct mie_diag_component, entry, c_entry);
b_tty_putc(stream, 0, '\n');
fx_tty_putc(stream, 0, '\n');
print_component(diag, c, stream);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return MIE_SUCCESS;