aboutsummaryrefslogtreecommitdiff
path: root/line-editor.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-18 04:24:58 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-18 04:24:58 +0200
commitb6dd94072080d29b356d2c22d9f317deac55331d (patch)
tree82047a097e670ec7c2624b1d9c3137b8ab9ea065 /line-editor.c
parentd8e0d1b2fe2bfc4a327d8056d6d63e7b58435632 (diff)
downloadnncmpp-b6dd94072080d29b356d2c22d9f317deac55331d.tar.gz
nncmpp-b6dd94072080d29b356d2c22d9f317deac55331d.tar.xz
nncmpp-b6dd94072080d29b356d2c22d9f317deac55331d.zip
Implement M-u, M-l, M-c from Readline
Diffstat (limited to 'line-editor.c')
-rw-r--r--line-editor.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/line-editor.c b/line-editor.c
index 4c37a92..8e42b5a 100644
--- a/line-editor.c
+++ b/line-editor.c
@@ -1,7 +1,7 @@
/*
* line-editor.c: a line editor component for the TUI part of liberty
*
- * Copyright (c) 2017 - 2018, Přemysl Eric Janouch <p@janouch.name>
+ * Copyright (c) 2017 - 2022, Přemysl Eric Janouch <p@janouch.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -48,6 +48,10 @@ enum line_editor_action
LINE_EDITOR_HOME, ///< Go to start of line
LINE_EDITOR_END, ///< Go to end of line
+ LINE_EDITOR_UPCASE_WORD, ///< Convert word to uppercase
+ LINE_EDITOR_DOWNCASE_WORD, ///< Convert word to lowercase
+ LINE_EDITOR_CAPITALIZE_WORD, ///< Capitalize word
+
LINE_EDITOR_B_DELETE, ///< Delete last character
LINE_EDITOR_F_DELETE, ///< Delete next character
LINE_EDITOR_B_KILL_WORD, ///< Delete last word
@@ -197,6 +201,41 @@ line_editor_action (struct line_editor *self, enum line_editor_action action)
self->point = self->len;
return true;
+ case LINE_EDITOR_UPCASE_WORD:
+ {
+ int i = self->point;
+ for (; i < (int) self->len && self->line[i] == ' '; i++);
+ for (; i < (int) self->len && self->line[i] != ' '; i++)
+ self->line[i] = uc_toupper (self->line[i]);
+ self->point = i;
+ line_editor_changed (self);
+ return true;
+ }
+ case LINE_EDITOR_DOWNCASE_WORD:
+ {
+ int i = self->point;
+ for (; i < (int) self->len && self->line[i] == ' '; i++);
+ for (; i < (int) self->len && self->line[i] != ' '; i++)
+ self->line[i] = uc_tolower (self->line[i]);
+ self->point = i;
+ line_editor_changed (self);
+ return true;
+ }
+ case LINE_EDITOR_CAPITALIZE_WORD:
+ {
+ int i = self->point;
+ ucs4_t (*converter) (ucs4_t) = uc_totitle;
+ for (; i < (int) self->len && self->line[i] == ' '; i++);
+ for (; i < (int) self->len && self->line[i] != ' '; i++)
+ {
+ self->line[i] = converter (self->line[i]);
+ converter = uc_tolower;
+ }
+ self->point = i;
+ line_editor_changed (self);
+ return true;
+ }
+
case LINE_EDITOR_B_DELETE:
{
if (self->point < 1)