Browse Source

Add M-? to apply ROT13

June 1 month ago
parent
commit
0b3d927e03
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 16 additions and 0 deletions
  1. 3
    0
      catgirl.1
  2. 1
    0
      chat.h
  3. 11
    0
      edit.c
  4. 1
    0
      ui.c

+ 3
- 0
catgirl.1 View File

@@ -293,6 +293,9 @@ Delete line after cursor.
293 293
 .It Aq Sy Tab
294 294
 Cycle through completions
295 295
 for commands, nicks and channels.
296
+.
297
+.It Sy M-?
298
+ROT13-encode line.
296 299
 .El
297 300
 .
298 301
 .Ss IRC Formatting

+ 1
- 0
chat.h View File

@@ -162,6 +162,7 @@ enum Edit {
162 162
 	EditKillBackWord,
163 163
 	EditKillForeWord,
164 164
 	EditKillLine,
165
+	EditROT13,
165 166
 	EditComplete,
166 167
 	EditEnter,
167 168
 };

+ 11
- 0
edit.c View File

@@ -19,6 +19,7 @@
19 19
 #include <stdlib.h>
20 20
 #include <sysexits.h>
21 21
 #include <wchar.h>
22
+#include <wctype.h>
22 23
 
23 24
 #include "chat.h"
24 25
 
@@ -94,6 +95,14 @@ static void killForeWord(void) {
94 95
 	line.ptr = from;
95 96
 }
96 97
 
98
+static void rot13(void) {
99
+	for (wchar_t *ch = line.buf; ch != line.end; ++ch) {
100
+		if (!iswascii(*ch)) continue;
101
+		if (iswupper(*ch)) *ch = L'A' + (*ch - L'A' + 13) % 26;
102
+		if (iswlower(*ch)) *ch = L'a' + (*ch - L'a' + 13) % 26;
103
+	}
104
+}
105
+
97 106
 static char *prefix;
98 107
 static void complete(struct Tag tag) {
99 108
 	if (!line.tab) {
@@ -175,6 +184,8 @@ void edit(struct Tag tag, enum Edit op, wchar_t ch) {
175 184
 		break; case EditKillForeWord: reject(); killForeWord();
176 185
 		break; case EditKillLine:     reject(); line.end = line.ptr;
177 186
 
187
+		break; case EditROT13: accept(); rot13();
188
+
178 189
 		break; case EditComplete: complete(tag);
179 190
 
180 191
 		break; case EditEnter: accept(); enter(tag);

+ 1
- 0
ui.c View File

@@ -472,6 +472,7 @@ static void keyChar(wchar_t ch) {
472 472
 			break; case L'f':  edit(ui.view->tag, EditForeWord, 0);
473 473
 			break; case L'\b': edit(ui.view->tag, EditKillBackWord, 0);
474 474
 			break; case L'd':  edit(ui.view->tag, EditKillForeWord, 0);
475
+			break; case L'?':  edit(ui.view->tag, EditROT13, 0);
475 476
 			break; case L'm':  uiLog(ui.view->tag, UICold, L"");
476 477
 			break; default: {
477 478
 				if (ch >= L'0' && ch <= L'9') uiViewNum(ch - L'0');

Loading…
Cancel
Save