1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added gnu readline

This commit is contained in:
James Booth 2015-01-27 22:13:09 +00:00
parent 25d31101bf
commit 2cdbfc7eb7
14 changed files with 428 additions and 243 deletions

View File

@ -133,6 +133,8 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [],
[AC_MSG_ERROR([glib 2.26 or higher is required for profanity])])
PKG_CHECK_MODULES([curl], [libcurl], [],
[AC_MSG_ERROR([libcurl is required for profanity])])
AC_CHECK_LIB([readline], [main], [],
[AC_MSG_ERROR([libreadline is required for profanity])])
AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"])

View File

@ -43,6 +43,8 @@
#include <string.h>
#include <glib.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "profanity.h"
#include "chat_session.h"
@ -71,6 +73,20 @@ static void _create_directories(void);
static void _connect_default(const char * const account);
static gboolean idle = FALSE;
static void cb_linehandler(char *);
static gboolean cmd_result = TRUE;
static void
cb_linehandler(char *line)
{
/* Can use ^D (stty eof) or `exit' to exit. */
if (*line) {
add_history(line);
}
rl_redisplay();
cmd_result = cmd_process_input(line);
free(line);
}
void
prof_run(const int disable_tls, char *log_level, char *account_name)
@ -79,26 +95,44 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
_connect_default(account_name);
ui_update();
char *line = NULL;
gboolean cmd_result = TRUE;
fd_set fds;
int r;
rl_callback_handler_install(NULL, cb_linehandler);
log_info("Starting main event loop");
struct timeval t;
t.tv_sec = 0;
t.tv_usec = 10000;
while(cmd_result) {
while(!line) {
_check_autoaway();
line = ui_readline();
#ifdef HAVE_LIBOTR
otr_poll();
#endif
notify_remind();
jabber_process_events();
ui_update();
_check_autoaway();
FD_ZERO(&fds);
FD_SET(fileno (rl_instream), &fds);
r = select(FD_SETSIZE, &fds, NULL, NULL, &t);
if (r < 0) {
perror ("rltest: select");
rl_callback_handler_remove();
break;
}
cmd_result = cmd_process_input(line);
ui_input_clear();
FREE_SET_NULL(line);
if (FD_ISSET (fileno (rl_instream), &fds)) {
rl_callback_read_char();
ui_write(rl_line_buffer, rl_point);
}
// line = ui_readline();
#ifdef HAVE_LIBOTR
otr_poll();
#endif
notify_remind();
jabber_process_events();
ui_update();
}
rl_callback_handler_remove();
}
void

View File

@ -177,6 +177,12 @@ ui_close(void)
endwin();
}
void
ui_write(char *line, int offset)
{
inp_write(line, offset);
}
char*
ui_readline(void)
{

View File

@ -131,6 +131,43 @@ inp_win_resize(void)
_inp_win_update_virtual();
}
static int
offset_to_col(char *str, int offset)
{
int i = 0;
int col = 0;
mbstate_t internal;
while (i != offset && str[i] != '\n') {
gunichar uni = g_utf8_get_char(&str[i]);
size_t ch_len = mbrlen(&str[i], 4, &internal);
i += ch_len;
col++;
if (g_unichar_iswide(uni)) {
col++;
}
}
return col;
}
void
inp_write(char *line, int offset)
{
int col = offset_to_col(line, offset);
cons_debug("LEN BYTES: %d", strlen(line));
cons_debug("LEN UTF8 : %d", g_utf8_strlen(line, -1));
cons_debug("OFFSET : %d", offset);
cons_debug("COL : %d", col);
cons_debug("");
werase(inp_win);
waddstr(inp_win, line);
wmove(inp_win, 0, col);
_inp_win_update_virtual();
}
void
inp_non_block(gint timeout)
{
@ -174,8 +211,8 @@ inp_read(int *key_type, wint_t *ch)
}
int col = getcurx(inp_win);
int wcols = getmaxx(stdscr);
key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, wcols);
int maxx = getmaxx(stdscr);
key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, maxx);
werase(inp_win);
waddstr(inp_win, line);
@ -265,44 +302,9 @@ _handle_edit(int key_type, const wint_t ch)
return 1;
// CTRL-RIGHT
} else if (line_utf8_pos < utf8_len && _is_ctrl_right(key_type, ch)) {
gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos);
gunichar curr_uni = g_utf8_get_char(curr_ch);
// find next word if in whitespace
while (g_unichar_isspace(curr_uni)) {
col++;
line_utf8_pos++;
curr_ch = g_utf8_find_next_char(curr_ch, NULL);
if (!curr_ch) {
break;
}
curr_uni = g_utf8_get_char(curr_ch);
}
if (curr_ch) {
while (!g_unichar_isspace(curr_uni)) {
line_utf8_pos++;
col++;
if (g_unichar_iswide(curr_uni)) {
col++;
}
curr_ch = g_utf8_find_next_char(curr_ch, NULL);
if (!curr_ch || line_utf8_pos >= utf8_len) {
break;
}
curr_uni = g_utf8_get_char(curr_ch);
}
}
} else if (_is_ctrl_right(key_type, ch)) {
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, wcols);
wmove(inp_win, 0, col);
// if gone off screen to right, jump right (half a screen worth)
if (col > pad_start + wcols) {
pad_start = pad_start + (wcols / 2);
_inp_win_update_virtual();
}
return 1;
// ALT-LEFT

View File

@ -48,5 +48,6 @@ void inp_non_block(gint);
void inp_block(void);
void inp_get_password(char *passwd);
void inp_history_append(char *inp);
void inp_write(char *line, int offset);
#endif

View File

@ -42,7 +42,7 @@
#include "common.h"
void
key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int wcols)
key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int maxx)
{
int utf8_len = g_utf8_strlen(line, -1);
@ -65,7 +65,7 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int
free(new_line);
gunichar uni = g_utf8_get_char(bytes);
if (*col == (*pad_start + wcols)) {
if (*col == (*pad_start + maxx)) {
(*pad_start)++;
if (g_unichar_iswide(uni)) {
(*pad_start)++;
@ -101,7 +101,7 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int
(*col)++;
}
if (*col - *pad_start > wcols-1) {
if (*col - *pad_start > maxx-1) {
(*pad_start)++;
if (g_unichar_iswide(uni)) {
(*pad_start)++;
@ -112,7 +112,7 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int
}
void
key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int wcols)
key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx)
{
if (*line_utf8_pos == 0) {
return;
@ -120,6 +120,7 @@ key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const co
gchar *curr_ch = g_utf8_offset_to_pointer(line, *line_utf8_pos);
gunichar curr_uni = g_utf8_get_char(curr_ch);
(*line_utf8_pos)--;
(*col)--;
if (g_unichar_iswide(curr_uni)) {
@ -145,7 +146,7 @@ key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const co
prev_uni = g_utf8_get_char(prev_ch);
(*line_utf8_pos)--;
(*col)--;
if (g_unichar_iswide(prev_uni)) {
if (g_unichar_iswide(curr_uni)) {
(*col)--;
}
if (g_unichar_isspace(prev_uni)) {
@ -169,3 +170,47 @@ key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const co
*pad_start = *col;
}
}
void
key_ctrl_right(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx)
{
int utf8_len = g_utf8_strlen(line, -1);
if (*line_utf8_pos >= utf8_len) {
return;
}
gchar *curr_ch = g_utf8_offset_to_pointer(line, *line_utf8_pos);
gunichar curr_uni = g_utf8_get_char(curr_ch);
// find next word if in whitespace
while (g_unichar_isspace(curr_uni)) {
(*col)++;
(*line_utf8_pos)++;
curr_ch = g_utf8_find_next_char(curr_ch, NULL);
if (!curr_ch) {
break;
}
curr_uni = g_utf8_get_char(curr_ch);
}
if (curr_ch) {
while (!g_unichar_isspace(curr_uni)) {
(*line_utf8_pos)++;
(*col)++;
if (g_unichar_iswide(curr_uni)) {
(*col)++;
}
curr_ch = g_utf8_find_next_char(curr_ch, NULL);
if (!curr_ch || *line_utf8_pos >= utf8_len) {
break;
}
curr_uni = g_utf8_get_char(curr_ch);
}
}
// if gone off screen to right, jump right (half a screen worth)
// if (col > pad_start + wcols) {
// pad_start = pad_start + (wcols / 2);
// _inp_win_update_virtual();
// }
}

View File

@ -37,8 +37,9 @@
#include <wchar.h>
void key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int wcols);
void key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int maxx);
void key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int wcols);
void key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx);
void key_ctrl_right(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx);
#endif

View File

@ -230,6 +230,7 @@ void ui_statusbar_new(const int win);
char * ui_readline(void);
void ui_input_clear(void);
void ui_input_nonblocking(gboolean);
void ui_write(char *line, int offset);
void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void));

View File

@ -85,6 +85,24 @@ void close_chat_sessions(void **state)
close_preferences(NULL);
}
int
utf8_pos_to_col(char *str, int utf8_pos)
{
int col = 0;
int i = 0;
for (i = 0; i<utf8_pos; i++) {
col++;
gchar *ch = g_utf8_offset_to_pointer(str, i);
gunichar uni = g_utf8_get_char(ch);
if (g_unichar_iswide(uni)) {
col++;
}
}
return col;
}
static GCompareFunc cmp_func;
void

View File

@ -6,5 +6,7 @@ void close_preferences(void **state);
void init_chat_sessions(void **state);
void close_chat_sessions(void **state);
int utf8_pos_to_col(char *str, int utf8_pos);
void glist_set_cmp(GCompareFunc func);
int glist_contents_equal(const void *actual, const void *expected);

View File

@ -1,5 +1,3 @@
#include "ui/keyhandlers.h"
#include "ui/inputwin.h"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@ -9,26 +7,15 @@
#include <locale.h>
#include "ui/keyhandlers.h"
#include "ui/inputwin.h"
#include "tests/helpers.h"
static char line[INP_WIN_MAX];
static int utf8_pos_to_col(char *str, int utf8_pos)
{
int col = 0;
// append
int i = 0;
for (i = 0; i<utf8_pos; i++) {
col++;
gchar *ch = g_utf8_offset_to_pointer(str, i);
gunichar uni = g_utf8_get_char(ch);
if (g_unichar_iswide(uni)) {
col++;
}
}
return col;
}
void append_non_wide_to_empty(void **state)
void append_to_empty(void **state)
{
setlocale(LC_ALL, "");
line[0] = '\0';
@ -60,7 +47,7 @@ void append_wide_to_empty(void **state)
assert_int_equal(pad_start, 0);
}
void append_non_wide_to_non_wide(void **state)
void append_to_single(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "a", 1);
@ -77,7 +64,8 @@ void append_non_wide_to_non_wide(void **state)
assert_int_equal(pad_start, 0);
}
void append_wide_to_non_wide(void **state)
void append_wide_to_single_non_wide(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "a", 1);
@ -94,7 +82,7 @@ void append_wide_to_non_wide(void **state)
assert_int_equal(pad_start, 0);
}
void append_non_wide_to_wide(void **state)
void append_non_wide_to_single_wide(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "", 1);
@ -111,7 +99,7 @@ void append_non_wide_to_wide(void **state)
assert_int_equal(pad_start, 0);
}
void append_wide_to_wide(void **state)
void append_wide_to_single_wide(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "", 1);
@ -147,25 +135,6 @@ void append_non_wide_when_overrun(void **state)
assert_int_equal(pad_start, 3);
}
void append_wide_when_overrun(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "0123456789四1234567", 18);
line[strlen(line)] = '\0';
int line_utf8_pos = 18;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 20);
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 20);
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 20);
assert_string_equal("0123456789四1234567三三三", line);
assert_int_equal(line_utf8_pos, 21);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 6);
}
void insert_non_wide_to_non_wide(void **state)
{
setlocale(LC_ALL, "");
@ -183,57 +152,6 @@ void insert_non_wide_to_non_wide(void **state)
assert_int_equal(pad_start, 0);
}
void insert_wide_to_non_wide(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcd", 26);
line[strlen(line)] = '\0';
int line_utf8_pos = 2;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 80);
assert_string_equal("abがcd", line);
assert_int_equal(line_utf8_pos, 3);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void insert_non_wide_to_wide(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "ひらなひ", 4);
line[strlen(line)] = '\0';
int line_utf8_pos = 2;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_printable(line, &line_utf8_pos, &col, &pad_start, '0', 80);
assert_string_equal("ひら0なひ", line);
assert_int_equal(line_utf8_pos, 3);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void insert_wide_to_wide(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "ひらなひ", 4);
line[strlen(line)] = '\0';
int line_utf8_pos = 2;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 80);
assert_string_equal("ひら三なひ", line);
assert_int_equal(line_utf8_pos, 3);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void insert_single_non_wide_when_pad_scrolled(void **state)
{
setlocale(LC_ALL, "");
@ -270,42 +188,6 @@ void insert_many_non_wide_when_pad_scrolled(void **state)
assert_int_equal(pad_start, 2);
}
void insert_single_wide_when_pad_scrolled(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15);
line[strlen(line)] = '\0';
int line_utf8_pos = 2;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 2;
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 12);
assert_string_equal("AA三AAAAAAAAAAAAA", line);
assert_int_equal(line_utf8_pos, 3);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 2);
}
void insert_many_wide_when_pad_scrolled(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15);
line[strlen(line)] = '\0';
int line_utf8_pos = 2;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 2;
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 12);
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 12);
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 12);
assert_string_equal("AAがが三AAAAAAAAAAAAA", line);
assert_int_equal(line_utf8_pos, 5);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 2);
}
void insert_single_non_wide_last_column(void **state)
{
setlocale(LC_ALL, "");
@ -341,39 +223,19 @@ void insert_many_non_wide_last_column(void **state)
assert_int_equal(pad_start, 4);
}
void insert_single_wide_last_column(void **state)
void ctrl_left_when_no_input(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcdefghijklmno", 15);
line[strlen(line)] = '\0';
int line_utf8_pos = 7;
line[0] = '\0';
int line_utf8_pos = 0;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 2;
int pad_start = 0;
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 5);
key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80);
assert_string_equal("abcdefg三hijklmno", line);
assert_int_equal(line_utf8_pos, 8);
assert_int_equal(line_utf8_pos, 0);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 4);
}
void insert_many_wide_last_column(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "abcdefghijklmno", 15);
line[strlen(line)] = '\0';
int line_utf8_pos = 7;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 2;
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 5);
key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 5);
assert_string_equal("abcdefg三がhijklmno", line);
assert_int_equal(line_utf8_pos, 9);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 6);
assert_int_equal(pad_start, 0);
}
void ctrl_left_when_at_start(void **state)
@ -678,4 +540,195 @@ void ctrl_left_when_word_overrun_to_left(void **state)
assert_int_equal(line_utf8_pos, 9);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 9);
}
void ctrl_right_when_no_input(void **state)
{
setlocale(LC_ALL, "");
line[0] = '\0';
int line_utf8_pos = 0;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 0);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_when_at_end(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
line[strlen(line)] = '\0';
int line_utf8_pos = 20;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 20);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_at_start(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword", 8);
line[strlen(line)] = '\0';
int line_utf8_pos = 0;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 8);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_in_middle(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword", 8);
line[strlen(line)] = '\0';
int line_utf8_pos = 3;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 8);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_at_end(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword", 8);
line[strlen(line)] = '\0';
int line_utf8_pos = 7;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 8);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_middle_first(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
line[strlen(line)] = '\0';
int line_utf8_pos = 4;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 8);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_end_first(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
line[strlen(line)] = '\0';
int line_utf8_pos = 7;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 8);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_space(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
line[strlen(line)] = '\0';
int line_utf8_pos = 8;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 20);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_from_start_second(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword anotherword", 20);
line[strlen(line)] = '\0';
int line_utf8_pos = 9;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 20);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_one_word_leading_whitespace(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, " someword", 15);
line[strlen(line)] = '\0';
int line_utf8_pos = 3;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 15);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_two_words_in_whitespace(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, " someword adfasdf", 30);
line[strlen(line)] = '\0';
int line_utf8_pos = 19;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 30);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}
void ctrl_right_trailing_whitespace_from_middle(void **state)
{
setlocale(LC_ALL, "");
g_utf8_strncpy(line, "someword ", 16);
line[strlen(line)] = '\0';
int line_utf8_pos = 3;
int col = utf8_pos_to_col(line, line_utf8_pos);
int pad_start = 0;
key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, 80);
assert_int_equal(line_utf8_pos, 8);
assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos));
assert_int_equal(pad_start, 0);
}

View File

@ -1,24 +1,18 @@
void append_non_wide_to_empty(void **state);
void append_to_empty(void **state);
void append_wide_to_empty(void **state);
void append_non_wide_to_non_wide(void **state);
void append_wide_to_non_wide(void **state);
void append_non_wide_to_wide(void **state);
void append_wide_to_wide(void **state);
void append_to_single(void **state);
void append_wide_to_single_non_wide(void **state);
void append_non_wide_to_single_wide(void **state);
void append_wide_to_single_wide(void **state);
void append_non_wide_when_overrun(void **state);
void append_wide_when_overrun(void **state);
void insert_non_wide_to_non_wide(void **state);
void insert_wide_to_non_wide(void **state);
void insert_non_wide_to_wide(void **state);
void insert_wide_to_wide(void **state);
void insert_single_non_wide_when_pad_scrolled(void **state);
void insert_many_non_wide_when_pad_scrolled(void **state);
void insert_single_wide_when_pad_scrolled(void **state);
void insert_many_wide_when_pad_scrolled(void **state);
void insert_single_non_wide_last_column(void **state);
void insert_many_non_wide_last_column(void **state);
void insert_single_wide_last_column(void **state);
void insert_many_wide_last_column(void **state);
void ctrl_left_when_no_input(void **state);
void ctrl_left_when_at_start(void **state);
void ctrl_left_when_in_first_word(void **state);
void ctrl_left_when_in_first_space(void **state);
@ -37,4 +31,17 @@ void ctrl_left_when_start_whitespace_middle_of_word(void **state);
void ctrl_left_in_whitespace_between_words(void **state);
void ctrl_left_in_whitespace_between_words_start_of_word(void **state);
void ctrl_left_in_whitespace_between_words_middle_of_word(void **state);
void ctrl_left_when_word_overrun_to_left(void **state);
void ctrl_left_when_word_overrun_to_left(void **state);
void ctrl_right_when_no_input(void **state);
void ctrl_right_when_at_end(void **state);
void ctrl_right_one_word_at_start(void **state);
void ctrl_right_one_word_in_middle(void **state);
void ctrl_right_one_word_at_end(void **state);
void ctrl_right_two_words_from_middle_first(void **state);
void ctrl_right_two_words_from_end_first(void **state);
void ctrl_right_two_words_from_space(void **state);
void ctrl_right_two_words_from_start_second(void **state);
void ctrl_right_one_word_leading_whitespace(void **state);
void ctrl_right_two_words_in_whitespace(void **state);
void ctrl_right_trailing_whitespace_from_middle(void **state);

View File

@ -624,26 +624,23 @@ int main(int argc, char* argv[]) {
unit_test(clears_chat_sessions),
unit_test(append_non_wide_to_empty),
unit_test(append_to_empty),
unit_test(append_wide_to_empty),
unit_test(append_non_wide_to_non_wide),
unit_test(append_wide_to_non_wide),
unit_test(append_non_wide_to_wide),
unit_test(append_wide_to_wide),
unit_test(append_to_single),
unit_test(append_wide_to_single_non_wide),
unit_test(append_non_wide_to_single_wide),
unit_test(append_wide_to_single_wide),
unit_test(append_non_wide_when_overrun),
unit_test(append_wide_when_overrun),
unit_test(insert_non_wide_to_non_wide),
unit_test(insert_wide_to_non_wide),
unit_test(insert_non_wide_to_wide),
unit_test(insert_wide_to_wide),
unit_test(insert_single_non_wide_when_pad_scrolled),
unit_test(insert_many_non_wide_when_pad_scrolled),
unit_test(insert_single_wide_when_pad_scrolled),
unit_test(insert_many_wide_when_pad_scrolled),
unit_test(insert_single_non_wide_last_column),
unit_test(insert_many_non_wide_last_column),
unit_test(insert_single_wide_last_column),
unit_test(insert_many_wide_last_column),
unit_test(ctrl_left_when_no_input),
unit_test(ctrl_left_when_at_start),
unit_test(ctrl_left_when_in_first_word),
unit_test(ctrl_left_when_in_first_space),
@ -663,6 +660,19 @@ int main(int argc, char* argv[]) {
unit_test(ctrl_left_in_whitespace_between_words_start_of_word),
unit_test(ctrl_left_in_whitespace_between_words_middle_of_word),
unit_test(ctrl_left_when_word_overrun_to_left),
unit_test(ctrl_right_when_no_input),
unit_test(ctrl_right_when_at_end),
unit_test(ctrl_right_one_word_at_start),
unit_test(ctrl_right_one_word_in_middle),
unit_test(ctrl_right_one_word_at_end),
unit_test(ctrl_right_two_words_from_middle_first),
unit_test(ctrl_right_two_words_from_end_first),
unit_test(ctrl_right_two_words_from_space),
unit_test(ctrl_right_two_words_from_start_second),
unit_test(ctrl_right_one_word_leading_whitespace),
unit_test(ctrl_right_two_words_in_whitespace),
unit_test(ctrl_right_trailing_whitespace_from_middle),
};
return run_tests(all_tests);

View File

@ -348,6 +348,9 @@ gboolean ui_win_has_unsaved_form(int num)
return FALSE;
}
void
ui_write(char *line, int offset) {}
// console window actions
void cons_show(const char * const msg, ...)