about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJesse R. Adams <jesse@techno-geeks.org>2013-09-25 12:51:54 -0700
committerJesse R. Adams <jesse@techno-geeks.org>2013-09-25 12:51:54 -0700
commit8be4cd1f2731ebec069c5848148b6748f318ea98 (patch)
treec964f30e8522a3a0a25faea1310ef500aa3eb043
parentce3b99f5771809f38119e9449099bdb1b0768b8f (diff)
downloadprofani-tty-8be4cd1f2731ebec069c5848148b6748f318ea98.tar.gz
Adding irssi style Alt-Left/Right window navigation
-rw-r--r--src/ui/console.c2
-rw-r--r--src/ui/inputwin.c21
2 files changed, 23 insertions, 0 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 17e97ca3..192edfc4 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1289,6 +1289,8 @@ cons_navigation_help(void)
     cons_show("");
     cons_show("Alt-1                    : This console window.");
     cons_show("Alt-2..Alt-0             : Chat windows.");
+    cons_show("Alt-LEFT                 : Previous chat window");
+    cons_show("Alt-RIGHT                : Next chat window");
     cons_show("F1                       : This console window.");
     cons_show("F2..F10                  : Chat windows.");
     cons_show("UP, DOWN                 : Navigate input history.");
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 598911cd..dc8e994a 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -40,6 +40,7 @@
 #include "log.h"
 #include "profanity.h"
 #include "ui/ui.h"
+#include "ui/windows.h"
 #include "xmpp/xmpp.h"
 
 #define _inp_win_refresh() prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1)
@@ -559,6 +560,8 @@ _handle_alt_key(char *input, int *size, int key)
 {
     int end_del = getcurx(inp_win);
     int start_del = end_del;
+    int current = wins_get_current_num();
+    int new;
 
     switch (key)
     {
@@ -592,6 +595,24 @@ _handle_alt_key(char *input, int *size, int key)
         case '0':
             ui_switch_win(0);
             break;
+        case KEY_LEFT:
+            if (current == 0) {
+                new = 9;
+            } else {
+                new = current - 1;
+            }
+
+            ui_switch_win(new);
+            break;
+        case KEY_RIGHT:
+            if (current == 9) {
+                new = 0;
+            } else {
+                new = current + 1;
+            }
+
+            ui_switch_win(new);
+            break;
         case 263:
         case 127:
             input[*size] = '\0';
n208'>208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#include "ui/ui.h"
#include "ui/stub_ui.h"

#include "xmpp/xmpp.h"
#include "xmpp/roster_list.h"
#include "command/cmd_funcs.h"

#define CMD_ROSTER "/roster"

static void test_with_connection_status(jabber_conn_status_t status)
{
    gchar *args[] = { NULL };

    will_return(connection_get_status, status);

    expect_cons_show("You are not currently connected.");

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_shows_message_when_disconnecting(void **state)
{
    test_with_connection_status(JABBER_DISCONNECTING);
}

void cmd_roster_shows_message_when_connecting(void **state)
{
    test_with_connection_status(JABBER_CONNECTING);
}

void cmd_roster_shows_message_when_disconnected(void **state)
{
    test_with_connection_status(JABBER_DISCONNECTED);
}

void cmd_roster_shows_roster_when_no_args(void **state)
{
    gchar *args[] = { NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    roster_create();
    roster_add("bob@server.org", "bob", NULL, "both", FALSE);
    GSList *roster = roster_get_contacts(ROSTER_ORD_NAME);

    expect_memory(cons_show_roster, list, roster, sizeof(roster));

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);

    roster_destroy();
}

void cmd_roster_add_shows_message_when_no_jid(void **state)
{
    gchar *args[] = { "add", NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_add_sends_roster_add_request(void **state)
{
    char *jid = "bob@server.org";
    char *nick = "bob";
    gchar *args[] = { "add", jid, nick, NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(roster_send_add_new, barejid, jid);
    expect_string(roster_send_add_new, name, nick);

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_remove_shows_message_when_no_jid(void **state)
{
    gchar *args[] = { "remove", NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_remove_sends_roster_remove_request(void **state)
{
    char *jid = "bob@server.org";
    gchar *args[] = { "remove", jid, NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(roster_send_remove, barejid, jid);

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_nick_shows_message_when_no_jid(void **state)
{
    gchar *args[] = { "nick", NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_nick_shows_message_when_no_nick(void **state)
{
    gchar *args[] = { "nick", "bob@server.org", NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_nick_shows_message_when_no_contact_exists(void **state)
{
    gchar *args[] = { "nick", "bob@server.org", "bobster", NULL };

    roster_create();

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_cons_show("Contact not found in roster: bob@server.org");

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);

    roster_destroy();
}

void cmd_roster_nick_sends_name_change_request(void **state)
{
    char *jid = "bob@server.org";
    char *nick = "bobster";
    gchar *args[] = { "nick", jid, nick, NULL };

    roster_create();
    GSList *groups = NULL;
    groups = g_slist_append(groups, strdup("group1"));
    roster_add(jid, "bob", groups, "both", FALSE);

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(roster_send_name_change, barejid, jid);
    expect_string(roster_send_name_change, new_name, nick);
    expect_memory(roster_send_name_change, groups, groups, sizeof(groups));

    expect_cons_show("Nickname for bob@server.org set to: bobster.");

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);

    PContact contact = roster_get_contact(jid);
    assert_string_equal(p_contact_name(contact), nick);
    roster_destroy();
}

void cmd_roster_clearnick_shows_message_when_no_jid(void **state)
{
    gchar *args[] = { "clearnick", NULL };

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(cons_bad_cmd_usage, cmd, CMD_ROSTER);

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);
}

void cmd_roster_clearnick_shows_message_when_no_contact_exists(void **state)
{
    gchar *args[] = { "clearnick", "bob@server.org", NULL };

    roster_create();

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_cons_show("Contact not found in roster: bob@server.org");

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);

    roster_destroy();
}

void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void **state)
{
    char *jid = "bob@server.org";
    gchar *args[] = { "clearnick", jid, NULL };

    roster_create();
    GSList *groups = NULL;
    groups = g_slist_append(groups, strdup("group1"));
    roster_add(jid, "bob", groups, "both", FALSE);

    will_return(connection_get_status, JABBER_CONNECTED);

    expect_string(roster_send_name_change, barejid, jid);
    expect_value(roster_send_name_change, new_name, NULL);
    expect_memory(roster_send_name_change, groups, groups, sizeof(groups));

    expect_cons_show("Nickname for bob@server.org removed.");

    gboolean result = cmd_roster(NULL, CMD_ROSTER, args);
    assert_true(result);

    PContact contact = roster_get_contact(jid);
    assert_null(p_contact_name(contact));

    roster_destroy();
}