Browse Source

Add /move command

Causal Agent 2 months ago
parent
commit
d8cffb8ae7
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 52 additions and 8 deletions
  1. 10
    0
      catgirl.1
  2. 1
    0
      chat.h
  3. 10
    0
      input.c
  4. 31
    8
      ui.c

+ 10
- 0
catgirl.1 View File

@@ -162,6 +162,16 @@ Close the current window.
162 162
 .It Ic /help , /man
163 163
 View this manual.
164 164
 .
165
+.It Ic /move Ar num
166
+Move window to number.
167
+If
168
+.Ar num
169
+starts with
170
+.Cm +
171
+or
172
+.Cm - ,
173
+the number is relative to the current window.
174
+.
165 175
 .It Ic /open Op Ar range
166 176
 Open a
167 177
 .Ar range

+ 1
- 0
chat.h View File

@@ -126,6 +126,7 @@ void uiExit(int status);
126 126
 void uiPrompt(bool nickChanged);
127 127
 void uiShowTag(struct Tag tag);
128 128
 void uiShowNum(int num, bool relative);
129
+void uiMoveTag(struct Tag tag, int num, bool relative);
129 130
 void uiCloseTag(struct Tag tag);
130 131
 
131 132
 enum UIHeat {

+ 10
- 0
input.c View File

@@ -117,6 +117,15 @@ static void inputMan(struct Tag tag, char *params) {
117 117
 	eventWait((const char *[]) { "man", "1", "catgirl", NULL });
118 118
 }
119 119
 
120
+static void inputMove(struct Tag tag, char *params) {
121
+	char *num = strsep(&params, " ");
122
+	if (num) {
123
+		uiMoveTag(tag, strtol(num, NULL, 0), num[0] == '+' || num[0] == '-');
124
+	} else {
125
+		uiLog(tag, UIHot, L"/move requires a number");
126
+	}
127
+}
128
+
120 129
 static void inputOpen(struct Tag tag, char *params) {
121 130
 	if (params && !isdigit(params[0])) {
122 131
 		urlOpenMatch(tag, params);
@@ -174,6 +183,7 @@ static const struct {
174 183
 	{ "/join", inputJoin },
175 184
 	{ "/man", inputMan },
176 185
 	{ "/me", inputMe },
186
+	{ "/move", inputMove },
177 187
 	{ "/names", inputWho },
178 188
 	{ "/nick", inputNick },
179 189
 	{ "/open", inputOpen },

+ 31
- 8
ui.c View File

@@ -76,6 +76,15 @@ static void windowAppend(struct Window *win) {
76 76
 	windows.tag[win->tag.id] = win;
77 77
 }
78 78
 
79
+static void windowInsert(struct Window *win, struct Window *next) {
80
+	win->prev = next->prev;
81
+	win->next = next;
82
+	if (win->prev) win->prev->next = win;
83
+	win->next->prev = win;
84
+	if (!win->prev) windows.head = win;
85
+	windows.tag[win->tag.id] = win;
86
+}
87
+
79 88
 static void windowRemove(struct Window *win) {
80 89
 	windows.tag[win->tag.id] = NULL;
81 90
 	if (win->prev) win->prev->next = win->next;
@@ -365,6 +374,17 @@ void uiShowTag(struct Tag tag) {
365 374
 	uiShowWindow(windowFor(tag));
366 375
 }
367 376
 
377
+static void uiShowAuto(void) {
378
+	struct Window *unread = NULL;
379
+	struct Window *hot;
380
+	for (hot = windows.head; hot; hot = hot->next) {
381
+		if (hot->hot) break;
382
+		if (!unread && hot->unread) unread = hot;
383
+	}
384
+	if (!hot && !unread) return;
385
+	uiShowWindow(hot ? hot : unread);
386
+}
387
+
368 388
 void uiShowNum(int num, bool relative) {
369 389
 	struct Window *win = (relative ? windows.active : windows.head);
370 390
 	if (num < 0) {
@@ -375,15 +395,18 @@ void uiShowNum(int num, bool relative) {
375 395
 	if (win) uiShowWindow(win);
376 396
 }
377 397
 
378
-static void uiShowAuto(void) {
379
-	struct Window *unread = NULL;
380
-	struct Window *hot;
381
-	for (hot = windows.head; hot; hot = hot->next) {
382
-		if (hot->hot) break;
383
-		if (!unread && hot->unread) unread = hot;
398
+void uiMoveTag(struct Tag tag, int num, bool relative) {
399
+	struct Window *win = windowFor(tag);
400
+	windowRemove(win);
401
+	struct Window *ins = (relative ? win : windows.head);
402
+	if (num < 0) {
403
+		for (; ins; ins = ins->prev) if (!num++) break;
404
+	} else {
405
+		if (relative) ins = ins->next;
406
+		for (; ins; ins = ins->next) if (!num--) break;
384 407
 	}
385
-	if (!hot && !unread) return;
386
-	uiShowWindow(hot ? hot : unread);
408
+	ins ? windowInsert(win, ins) : windowAppend(win);
409
+	uiStatus();
387 410
 }
388 411
 
389 412
 void uiCloseTag(struct Tag tag) {

Loading…
Cancel
Save