summaryrefslogtreecommitdiff
path: root/shed_insert.c
diff options
context:
space:
mode:
Diffstat (limited to 'shed_insert.c')
-rw-r--r--shed_insert.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/shed_insert.c b/shed_insert.c
new file mode 100644
index 0000000..384cbea
--- /dev/null
+++ b/shed_insert.c
@@ -0,0 +1,62 @@
+#define _POSIX_C_SOURCE 200809L
+#include <termios.h>
+#include "shed.h"
+
+static int shed_insert_special(struct shed *e, struct termios *t, char c)
+{
+ if (c == '\n') {
+ return shed_execute(e);
+ }
+
+ if (c == t->c_cc[VERASE]) {
+ return shed_backspace(e);
+ }
+
+ if (c == t->c_cc[VINTR]) {
+ return shed_cancel(e);
+ }
+
+ if (c == t->c_cc[VKILL]) {
+ return shed_erase(e);
+ }
+
+ if (c == CTRL_V) {
+ /* quote the next character */
+ return 1;
+ }
+
+ if (c == CTRL_W) {
+ return shed_worderase(e);
+ }
+
+ if (c == t->c_cc[VEOF]) {
+ return shed_eof(e);
+ }
+
+ if (c == ESCAPE) {
+ e->handle = shed_handle_edit;
+ return 1;
+ }
+
+ return -1;
+}
+
+int shed_handle_insert(struct shed *e, struct termios *t, char c)
+{
+ int r = shed_insert_special(e, t, c);
+ if (r == -1) {
+ shed_insert_char(e->cur, c);
+ r = 1;
+ }
+ return r;
+}
+
+int shed_handle_replace(struct shed *e, struct termios *t, char c)
+{
+ int r = shed_insert_special(e, t, c);
+ if (r == -1) {
+ shed_replace_char(e->cur, c);
+ r = 1;
+ }
+ return r;
+}