summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-03-23 14:55:43 -0400
committerJune McEnroe <june@causal.agency>2020-03-23 14:55:43 -0400
commit60b189200e1a77741bb441de39621ac17db1b6f7 (patch)
tree2e4f874ec4ccc57c620ab45c98c52762c4b1c1c0
parentAllow commands to take multiline input (diff)
downloadcatgirl-60b189200e1a77741bb441de39621ac17db1b6f7.tar.gz
catgirl-60b189200e1a77741bb441de39621ac17db1b6f7.zip
Handle bracketed paste, including newlines
-rw-r--r--ui.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/ui.c b/ui.c
index b3f3b09..0500118 100644
--- a/ui.c
+++ b/ui.c
@@ -704,8 +704,15 @@ static void inputAdd(struct Style *style, const char *str) {
 			break; case R: waddch(input, 'R');
 			break; case I: waddch(input, 'I');
 			break; case U: waddch(input, 'U');
+			break; case '\n': waddch(input, 'N');
 		}
 		if (str - code > 1) waddnstr(input, &code[1], str - &code[1]);
+		if (str[0] == '\n') {
+			str++;
+			len--;
+		}
+		size_t nl = strcspn(str, "\n");
+		if (nl < len) len = nl;
 		wattr_set(
 			input,
 			style->attr | colorAttr(Colors[style->fg]),
@@ -853,8 +860,6 @@ static void keyCode(int code) {
 		break; case KEY_RESIZE:  resize();
 		break; case KeyFocusIn:  unmark(window);
 		break; case KeyFocusOut: mark(window);
-		break; case KeyPasteOn:; // TODO
-		break; case KeyPasteOff:; // TODO
 
 		break; case KeyMetaSlash: windowShow(windows.swap);
 
@@ -939,9 +944,15 @@ void uiRead(void) {
 
 	int ret;
 	wint_t ch;
-	static bool style;
+	static bool paste, style;
 	while (ERR != (ret = wget_wch(input, &ch))) {
-		if (ret == KEY_CODE_YES) {
+		if (ret == KEY_CODE_YES && ch == KeyPasteOn) {
+			paste = true;
+		} else if (ret == KEY_CODE_YES && ch == KeyPasteOff) {
+			paste = false;
+		} else if (paste) {
+			edit(windows.ptrs[windows.show]->id, EditInsert, ch);
+		} else if (ret == KEY_CODE_YES) {
 			keyCode(ch);
 		} else if (ch == (L'Z' ^ L'@')) {
 			style = true;
an='3' class='logmsg'> 2022-02-20Use separate edit buffers for each IDJune McEnroe 2022-02-20Make sure new cap is actually larger than new lengthJune McEnroe 2022-02-20Remove unused mbs.len field from struct EditJune McEnroe 2022-02-19Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe In other words, warn when a function is missing static. I don't see why this isn't in -Wextra. 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe I know, it feels wrong. 2022-02-18Implement new line editing "library"June McEnroe Losing tab complete and text macros, for now. This new implementation works on an instance of a struct and does not interact with the rest of catgirl, making it possible to copy into another project. Unlike existing line editing libraries, this one is entirely abstract and can be rendered externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe