Files
bshell/bshell.runtime/line-editor/highlight.c
T

62 lines
1.7 KiB
C
Raw Normal View History

#include <bshell/line-editor/highlight.h>
#include <bshell/line-editor/line-editor.h>
#include <bshell/line-editor/plugin.h>
#include <fx/term/tty.h>
struct bshell_line_ed_highlight_p {
};
static void init(fx_object *obj, void *priv)
{
}
static void fini(fx_object *obj, void *priv)
{
}
static enum bshell_status render_buffer(
bshell_line_ed_plugin *plugin,
bshell_line_ed *ed)
{
fx_string *buf = bshell_line_ed_get_buffer(ed);
fx_tty *tty = bshell_line_ed_get_tty(ed);
const char *s = fx_string_get_cstr(buf);
for (unsigned long i = 0; *s; i++) {
fx_wchar c = fx_wchar_utf8_codepoint_decode(s);
unsigned int stride = fx_wchar_utf8_codepoint_size(c);
if (stride == 0) {
break;
}
char cs[5] = {0};
fx_wchar_utf8_codepoint_encode(c, cs);
fx_tty_puts(tty, 0, cs);
s += stride;
}
fx_tty_puts(tty, 0, "[reset]");
return BSHELL_SUCCESS;
}
FX_TYPE_CLASS_BEGIN(bshell_line_ed_highlight)
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
FX_INTERFACE_ENTRY(to_string) = NULL;
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
FX_TYPE_VTABLE_INTERFACE_BEGIN(
bshell_line_ed_plugin,
BSHELL_TYPE_LINE_EDITOR_PLUGIN)
FX_INTERFACE_ENTRY(p_render_buffer) = render_buffer;
FX_TYPE_VTABLE_INTERFACE_END(bshell_command, BSHELL_TYPE_COMMAND)
FX_TYPE_CLASS_END(bshell_line_ed_highlight)
FX_TYPE_DEFINITION_BEGIN(bshell_line_ed_highlight)
FX_TYPE_ID(0x162823ef, 0x4893, 0x4089, 0xa4f6, 0xf015a1976881);
FX_TYPE_NAME("bshell.runtime.line_editor.plugins.highlight");
FX_TYPE_EXTENDS(BSHELL_TYPE_LINE_EDITOR_PLUGIN);
FX_TYPE_CLASS(bshell_line_ed_highlight_class);
FX_TYPE_INSTANCE_INIT(init);
FX_TYPE_INSTANCE_FINI(fini);
FX_TYPE_INSTANCE_PRIVATE(struct bshell_line_ed_highlight_p);
FX_TYPE_DEFINITION_END(bshell_line_ed_highlight)