From 299ef2c45756e7123167d291cc476ada25469e58 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 16 Feb 2017 13:04:26 +0100 Subject: lib/mbsedit: add simple buffer editor Signed-off-by: Karel Zak --- include/mbsedit.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 include/mbsedit.h (limited to 'include/mbsedit.h') diff --git a/include/mbsedit.h b/include/mbsedit.h new file mode 100644 index 000000000..8d1c6c255 --- /dev/null +++ b/include/mbsedit.h @@ -0,0 +1,32 @@ +#ifndef UTIL_LINUX_MBSEDIT_H +# define UTIL_LINUX_MBSEDIT_H + +#include "mbsalign.h" +#include "widechar.h" + +struct mbs_editor { + char *buf; /* buffer */ + size_t max_bytes; /* size of the buffer */ + size_t max_cells; /* maximal allowed number of cells */ + size_t cur_cells; /* number of cells to print the buffer */ + size_t cur_bytes; /* number of chars in bytes */ + size_t cursor; /* cursor position in bytes */ + size_t cursor_cells; /* cursor position in cells */ +}; + +enum { + MBS_EDIT_LEFT, + MBS_EDIT_RIGHT, + MBS_EDIT_END, + MBS_EDIT_HOME +}; + +struct mbs_editor *mbs_new_edit(char *buf, size_t bufsz, size_t ncells); +char *mbs_free_edit(struct mbs_editor *edit); + +int mbs_edit_goto(struct mbs_editor *edit, int where); +int mbs_edit_delete(struct mbs_editor *edit); +int mbs_edit_backspace(struct mbs_editor *edit); +int mbs_edit_insert(struct mbs_editor *edit, wint_t c); + +#endif /* UTIL_LINUX_MBSEDIT_H */ -- cgit v1.2.3-55-g7522