Browse Source

Add /move command

master
Causal Agent 7 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.
.It Ic /help , /man
View this manual.
.
.It Ic /move Ar num
Move window to number.
If
.Ar num
starts with
.Cm +
or
.Cm - ,
the number is relative to the current window.
.
.It Ic /open Op Ar range
Open a
.Ar range

+ 1
- 0
chat.h View File

@@ -126,6 +126,7 @@ void uiExit(int status);
void uiPrompt(bool nickChanged);
void uiShowTag(struct Tag tag);
void uiShowNum(int num, bool relative);
void uiMoveTag(struct Tag tag, int num, bool relative);
void uiCloseTag(struct Tag tag);

enum UIHeat {

+ 10
- 0
input.c View File

@@ -117,6 +117,15 @@ static void inputMan(struct Tag tag, char *params) {
eventWait((const char *[]) { "man", "1", "catgirl", NULL });
}

static void inputMove(struct Tag tag, char *params) {
char *num = strsep(&params, " ");
if (num) {
uiMoveTag(tag, strtol(num, NULL, 0), num[0] == '+' || num[0] == '-');
} else {
uiLog(tag, UIHot, L"/move requires a number");
}
}

static void inputOpen(struct Tag tag, char *params) {
if (params && !isdigit(params[0])) {
urlOpenMatch(tag, params);
@@ -174,6 +183,7 @@ static const struct {
{ "/join", inputJoin },
{ "/man", inputMan },
{ "/me", inputMe },
{ "/move", inputMove },
{ "/names", inputWho },
{ "/nick", inputNick },
{ "/open", inputOpen },

+ 31
- 8
ui.c View File

@@ -76,6 +76,15 @@ static void windowAppend(struct Window *win) {
windows.tag[win->tag.id] = win;
}

static void windowInsert(struct Window *win, struct Window *next) {
win->prev = next->prev;
win->next = next;
if (win->prev) win->prev->next = win;
win->next->prev = win;
if (!win->prev) windows.head = win;
windows.tag[win->tag.id] = win;
}

static void windowRemove(struct Window *win) {
windows.tag[win->tag.id] = NULL;
if (win->prev) win->prev->next = win->next;
@@ -365,6 +374,17 @@ void uiShowTag(struct Tag tag) {
uiShowWindow(windowFor(tag));
}

static void uiShowAuto(void) {
struct Window *unread = NULL;
struct Window *hot;
for (hot = windows.head; hot; hot = hot->next) {
if (hot->hot) break;
if (!unread && hot->unread) unread = hot;
}
if (!hot && !unread) return;
uiShowWindow(hot ? hot : unread);
}

void uiShowNum(int num, bool relative) {
struct Window *win = (relative ? windows.active : windows.head);
if (num < 0) {
@@ -375,15 +395,18 @@ void uiShowNum(int num, bool relative) {
if (win) uiShowWindow(win);
}

static void uiShowAuto(void) {
struct Window *unread = NULL;
struct Window *hot;
for (hot = windows.head; hot; hot = hot->next) {
if (hot->hot) break;
if (!unread && hot->unread) unread = hot;
void uiMoveTag(struct Tag tag, int num, bool relative) {
struct Window *win = windowFor(tag);
windowRemove(win);
struct Window *ins = (relative ? win : windows.head);
if (num < 0) {
for (; ins; ins = ins->prev) if (!num++) break;
} else {
if (relative) ins = ins->next;
for (; ins; ins = ins->next) if (!num--) break;
}
if (!hot && !unread) return;
uiShowWindow(hot ? hot : unread);
ins ? windowInsert(win, ins) : windowAppend(win);
uiStatus();
}

void uiCloseTag(struct Tag tag) {

Loading…
Cancel
Save