77 lines
2.1 KiB
C
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
|