Files
bshell/bshell.runtime/line-editor/line-editor.h
T
wash ad8b284869 runtime: implement an extensible line editor
the line editor supports custom keybinds and data storage, allowing for
a wide range of functionality to be implemented via plugins.

included plugins include:
* core: basic input and cursor movement.
* history: input history storage and retrieval (unfinished)
* highlight: support for colour-highlighting the line buffer (unfinished)
* syntax: parses the line buffer and uses `highlight` to apply syntax highlighting (unfinished).
* shell-integration:
  - allows a `prompt` function to be defined, which will be called to get the text to
    be used for the prompt
  - exposes key properties of the line editor to the shell environment, allowing line editor
    functionality to be extended via shell scripts.
2026-06-20 15:13:34 +01:00

77 lines
2.1 KiB
C

#ifndef _LINE_EDITOR_H_
#define _LINE_EDITOR_H_
#include <bshell/line-editor/line-editor.h>
#include <bshell/line-source.h>
#include <fx/collections/array.h>
#include <fx/collections/hashtable.h>
#include <fx/term/tty.h>
enum line_ed_flags {
LINE_ED_DONE = 0x01u,
LINE_ED_EOF = 0x02u,
};
struct cursor_points {
/* visual co-ordinates of the current cursor position */
unsigned long c_cursor_x, c_cursor_y;
/* visual co-ordinates of the last character in the rendered prompt
* string */
unsigned long c_render_limit_x, c_render_limit_y;
/* visual co-ordinates of the last cell that could be occupied by the
* cursor in the rendered prompt string */
unsigned long c_cursor_limit_x, c_cursor_limit_y;
};
struct line_render {
/* how many visual terminal rows are being used to display the current
* buffer. may be greater than the number of lines in ed_buffer if one
* or more of the lines exceeds the width of the terminal. will be
* less than or equal to the terminal height. */
unsigned long r_vlines;
/* the logical offset that the cursor was at when the prompt was
* rendered */
unsigned long r_cursor;
/* points of interest */
struct cursor_points ed_points;
};
struct data_cache {
fx_string *c_prompt;
fx_string *c_buffer;
};
struct bshell_line_ed_p {
bshell_line_ed *ed_self;
enum line_ed_flags ed_flags;
struct bshell_line_source ed_linesrc;
fx_bst ed_keymap;
fx_array *ed_plugins;
fx_tty *ed_tty;
struct data_cache ed_cache;
bshell_line_ed_plugin *ed_render_prompt;
bshell_line_ed_plugin *ed_render_buffer;
bshell_line_ed_plugin *ed_data;
struct line_render ed_render;
};
extern void line_ed_handle_key(struct bshell_line_ed_p *ed, fx_keycode code);
extern void line_ed_get_points(
struct bshell_line_ed_p *ed,
struct cursor_points *out);
extern void line_ed_hide(struct bshell_line_ed_p *ed);
extern void line_ed_show(struct bshell_line_ed_p *ed);
extern fx_string *line_ed_get_prompt(struct bshell_line_ed_p *ed);
extern fx_string *line_ed_get_buffer(struct bshell_line_ed_p *ed);
extern unsigned long line_ed_get_cursor(const struct bshell_line_ed_p *ed);
extern int line_ed_get_char_width(fx_wchar c);
#endif