meta: rename to fx
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/term/print.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum sample_code {
|
||||
@@ -13,25 +13,25 @@ enum sample_msg {
|
||||
SAMPLE_MSG_A_TEMPLATED_MSG,
|
||||
};
|
||||
|
||||
static const b_error_definition sample_errors[] = {
|
||||
B_ERROR_DEFINITION(SAMPLE_OK, "OK", "Success"),
|
||||
B_ERROR_DEFINITION(SAMPLE_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
|
||||
B_ERROR_DEFINITION_TEMPLATE(
|
||||
static const fx_error_definition sample_errors[] = {
|
||||
FX_ERROR_DEFINITION(SAMPLE_OK, "OK", "Success"),
|
||||
FX_ERROR_DEFINITION(SAMPLE_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
|
||||
FX_ERROR_DEFINITION_TEMPLATE(
|
||||
SAMPLE_ERR_FILE_READ_FAILED, "FILE_READ_FAILED",
|
||||
"Failed to read file @i[filepath]",
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
"filepath", B_ERROR_TEMPLATE_PARAM_STRING, "%s")),
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"filepath", FX_ERROR_TEMPLATE_PARAM_STRING, "%s")),
|
||||
};
|
||||
|
||||
static const b_error_msg sample_error_msg[] = {
|
||||
B_ERROR_MSG_TEMPLATE(
|
||||
static const fx_error_msg sample_error_msg[] = {
|
||||
FX_ERROR_MSG_TEMPLATE(
|
||||
SAMPLE_MSG_A_TEMPLATED_MSG, "A templated message: @e[param1]",
|
||||
B_ERROR_TEMPLATE_PARAM(
|
||||
"param1", B_ERROR_TEMPLATE_PARAM_STRING, "%s")),
|
||||
FX_ERROR_TEMPLATE_PARAM(
|
||||
"param1", FX_ERROR_TEMPLATE_PARAM_STRING, "%s")),
|
||||
};
|
||||
|
||||
static const char *sample_code_to_string(
|
||||
const struct b_error_vendor *vendor, b_error_status_code code)
|
||||
const struct fx_error_vendor *vendor, fx_error_status_code code)
|
||||
{
|
||||
switch (code) {
|
||||
case SAMPLE_OK:
|
||||
@@ -45,7 +45,7 @@ static const char *sample_code_to_string(
|
||||
}
|
||||
}
|
||||
|
||||
static b_error_vendor sample_vendor = {
|
||||
static fx_error_vendor sample_vendor = {
|
||||
.v_name = "Sample",
|
||||
.v_error_definitions = sample_errors,
|
||||
.v_error_definitions_length = sizeof sample_errors,
|
||||
@@ -53,31 +53,31 @@ static b_error_vendor sample_vendor = {
|
||||
.v_msg_length = sizeof sample_error_msg,
|
||||
};
|
||||
|
||||
static b_result error_return_3(void)
|
||||
static fx_result error_return_3(void)
|
||||
{
|
||||
b_result err = b_error_with_string(
|
||||
fx_result err = fx_error_with_string(
|
||||
&sample_vendor, SAMPLE_ERR_IO_FAILURE,
|
||||
"I/O failure while reading file");
|
||||
|
||||
b_error_add_submsg_string(
|
||||
err, B_ERROR_SUBMSG_ERROR, "An @e{error} message");
|
||||
b_error_add_submsg_string(
|
||||
err, B_ERROR_SUBMSG_WARNING, "A @w{warning} message");
|
||||
b_error_add_submsg_template(
|
||||
err, B_ERROR_SUBMSG_WARNING, SAMPLE_MSG_A_TEMPLATED_MSG,
|
||||
B_ERROR_PARAM("param1", "Hello!"));
|
||||
fx_error_add_submsg_string(
|
||||
err, FX_ERROR_SUBMSG_ERROR, "An @e{error} message");
|
||||
fx_error_add_submsg_string(
|
||||
err, FX_ERROR_SUBMSG_WARNING, "A @w{warning} message");
|
||||
fx_error_add_submsg_template(
|
||||
err, FX_ERROR_SUBMSG_WARNING, SAMPLE_MSG_A_TEMPLATED_MSG,
|
||||
FX_ERROR_PARAM("param1", "Hello!"));
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static b_result error_return_2(void)
|
||||
static fx_result error_return_2(void)
|
||||
{
|
||||
return b_result_propagate(error_return_3());
|
||||
return fx_result_propagate(error_return_3());
|
||||
}
|
||||
|
||||
static b_result error_return_1(void)
|
||||
static fx_result error_return_1(void)
|
||||
{
|
||||
return b_result_propagate(error_return_2());
|
||||
return fx_result_propagate(error_return_2());
|
||||
}
|
||||
|
||||
struct param {
|
||||
@@ -100,39 +100,39 @@ static void __test(struct param params[])
|
||||
|
||||
#define test(...) __test((struct param[]) {__VA_ARGS__, {}})
|
||||
|
||||
static b_result some_operation(void)
|
||||
static fx_result some_operation(void)
|
||||
{
|
||||
b_result result = error_return_2();
|
||||
if (b_result_is_error(result)) {
|
||||
b_result err = b_error_with_template(
|
||||
fx_result result = error_return_2();
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_result err = fx_error_with_template(
|
||||
&sample_vendor, SAMPLE_ERR_FILE_READ_FAILED,
|
||||
B_ERROR_PARAM("filepath", "src/Manifest.json"));
|
||||
b_error_add_submsg_string(
|
||||
err, B_ERROR_SUBMSG_INFO,
|
||||
FX_ERROR_PARAM("filepath", "src/Manifest.json"));
|
||||
fx_error_add_submsg_string(
|
||||
err, FX_ERROR_SUBMSG_INFO,
|
||||
"An @i{informational} message");
|
||||
|
||||
b_error_caused_by_b_status(result, B_ERR_IO_FAILURE);
|
||||
b_result err2 = b_error_caused_by(err, result);
|
||||
fx_error_caused_by_fx_status(result, FX_ERR_IO_FAILURE);
|
||||
fx_result err2 = fx_error_caused_by(err, result);
|
||||
|
||||
return err2;
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
b_set_error_report_function(b_enhanced_error_reporter, B_ERROR_REPORT_ALL);
|
||||
fx_set_error_report_function(fx_enhanced_error_reporter, FX_ERROR_REPORT_ALL);
|
||||
|
||||
test(PARAM("Hello", 1), PARAM("Goodbye", 2));
|
||||
|
||||
b_result err;
|
||||
if (B_CATCH(err, some_operation())) {
|
||||
b_throw(err);
|
||||
fx_result err;
|
||||
if (FX_CATCH(err, some_operation())) {
|
||||
fx_throw(err);
|
||||
}
|
||||
|
||||
b_throw_status(B_ERR_INVALID_ARGUMENT);
|
||||
b_throw_status_string(B_ERR_INVALID_ARGUMENT, "Hello!");
|
||||
fx_throw_status(FX_ERR_INVALID_ARGUMENT);
|
||||
fx_throw_status_string(FX_ERR_INVALID_ARGUMENT, "Hello!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <blue/term/tty.h>
|
||||
#include <blue/term/print.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <fx/term/tty.h>
|
||||
#include <fx/term/print.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define F_GREEN "[green]"
|
||||
@@ -55,25 +55,25 @@ static const char *text2
|
||||
int main(void)
|
||||
{
|
||||
const char *s = "[magenta,uline]Hello, [bright_magenta]world![reset]";
|
||||
b_puts(s);
|
||||
b_putc('\n');
|
||||
fx_puts(s);
|
||||
fx_putc('\n');
|
||||
|
||||
b_string *str = b_string_create_from_cstr(s);
|
||||
size_t len = b_string_get_size(str, B_STRLEN_IGNORE_MOD);
|
||||
fx_string *str = fx_string_create_from_cstr(s);
|
||||
size_t len = fx_string_get_size(str, FX_STRLEN_IGNORE_MOD);
|
||||
printf("length = %zu\n", len);
|
||||
|
||||
b_paragraph_format format = { 0 };
|
||||
fx_paragraph_format format = { 0 };
|
||||
format.p_left_margin = 5;
|
||||
format.p_right_margin = 5;
|
||||
format.p_flags = B_PARAGRAPH_DOUBLE_LINE_BREAK;
|
||||
format.p_flags = FX_PARAGRAPH_DOUBLE_LINE_BREAK;
|
||||
|
||||
b_print_paragraph(text, b_stdtty, &format);
|
||||
fx_print_paragraph(text, fx_stdtty, &format);
|
||||
|
||||
b_i("An informational message\n\nWith multiple lines");
|
||||
b_warn("A warning message\nWith multiple lines");
|
||||
b_err("An error message\nWith multiple lines");
|
||||
fx_i("An informational message\n\nWith multiple lines");
|
||||
fx_warn("A warning message\nWith multiple lines");
|
||||
fx_err("An error message\nWith multiple lines");
|
||||
|
||||
b_printf("[red]formatting ignored: '%s'[reset]\n[dark_grey]dark text[reset]\n", "[blue]wow![reset]");
|
||||
fx_printf("[red]formatting ignored: '%s'[reset]\n[dark_grey]dark text[reset]\n", "[blue]wow![reset]");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user