aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cmdline.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-12 13:55:40 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-09-12 16:44:13 +0200
commitabb5d23eba21a2aafda0346c0c5dd845561b2aa2 (patch)
tree9e42c1e72e0d61c322c0af8d54a9d740a7e2e45c /src/cmdline.h
parent73d574b71a10d4661ada20275cafde75aff6c1ba (diff)
downloadsciteco-abb5d23eba21a2aafda0346c0c5dd845561b2aa2.tar.gz
function key macros have been reworked into a more generic key macro feature
* ALL keypresses (the UTF-8 sequences resulting from key presses) can now be remapped. * This is especially useful with Unicode support, as you might want to alias international characters to their corresponding latin form in the start state, so you don't have to change keyboard layouts so often. This is done automatically in Gtk, where we have hardware key press information, but has to be done with key macros in Curses. There is a new key mask 4 (bit 3) for that purpose now. * Also, you might want to define non-ANSI letters to perform special functions in the start state where it won't be accepted by the parser anyway. Suppose you have a macro M→, you could define @^U[^K→]{m→} 1^_U[^K→] This effectively "extends" the parser and allow you to call macro "→" by a single key press. See also #5. * The register prefix has been changed from ^F (for function) to ^K (for key). This is the only thing you have to change in order to migrate existing function key macros. * Key macros are enabled by default. There is no longer any way to disable function key handling in curses, as I never found any reason or need to disable it. Theoretically, the default ESCDELAY could turn out to be too small and function keys don't get through. I doubt that's possible unless on extremely slow serial lines. Even then, you'd have to increase ESCDELAY and instead of disabling function keys simply define an escape surrogate. * The ED flag has been removed and its place is reserved for a future mouse support flag (which does make sense to disable in curses sometimes). fnkeys.tes is consequently also enabled by default in sample.teco_ini. * Key macros are handled as an unit. If one character results in an error, the entire string is rubbed out. This fixes the "CLOSE" key on Gtk. It also makes sure that the original error message is preserved and not overwritten by some subsequent syntax error. It was never useful that we kept inserting characters after the first error.
Diffstat (limited to 'src/cmdline.h')
-rw-r--r--src/cmdline.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/cmdline.h b/src/cmdline.h
index 4aa862c..f4b84e4 100644
--- a/src/cmdline.h
+++ b/src/cmdline.h
@@ -60,16 +60,29 @@ typedef struct {
extern teco_cmdline_t teco_cmdline;
-gboolean teco_cmdline_insert(const gchar *data, gsize len, GError **error);
+gboolean teco_cmdline_keypress(const gchar *data, gsize len, GError **error);
-gboolean teco_cmdline_rubin(GError **error);
+typedef enum {
+ TECO_KEYMACRO_ERROR = 0, /**< GError occurred */
+ TECO_KEYMACRO_SUCCESS, /**< key macro found and inserted */
+ TECO_KEYMACRO_UNDEFINED /**< no key macro found */
+} teco_keymacro_status_t;
-gboolean teco_cmdline_keypress_wc(gunichar key, GError **error);
-gboolean teco_cmdline_keypress(const gchar *str, gsize len, GError **error);
+teco_keymacro_status_t teco_cmdline_keymacro(const gchar *name, gssize name_len, GError **error);
-gboolean teco_cmdline_fnmacro(const gchar *name, GError **error);
-
-void teco_cmdline_rubout(void);
+static inline gboolean
+teco_cmdline_keymacro_c(gchar key, GError **error)
+{
+ switch (teco_cmdline_keymacro(&key, sizeof(key), error)) {
+ case TECO_KEYMACRO_ERROR:
+ return FALSE;
+ case TECO_KEYMACRO_SUCCESS:
+ break;
+ case TECO_KEYMACRO_UNDEFINED:
+ return teco_cmdline_keypress(&key, sizeof(key), error);
+ }
+ return TRUE;
+}
extern gboolean teco_quit_requested;