Permalink
Browse files

Improve input management

  • Loading branch information...
1 parent a6381e5 commit 9d4a1f53c4ce278f6606350956cf20352192f0bd @xorg62 committed Feb 27, 2012
Showing with 59 additions and 34 deletions.
  1. +5 −1 src/hftirc.c
  2. +1 −0 src/hftirc.h
  3. +1 −1 src/input.c
  4. +49 −31 src/ui.c
  5. +3 −1 src/util.c
View
6 src/hftirc.c
@@ -5,8 +5,12 @@
#include <signal.h>
#include <getopt.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/types.h>
#include "hftirc.h"
+#include "ui.h"
void
signal_handler(int signal)
@@ -25,7 +29,6 @@ main(int argc, char **argv)
struct timeval tv;
struct session *session;
struct session_info *info;
- struct buffer *buffer;
fd_set set;
int i, n, maxfd, nsession;
@@ -122,4 +125,5 @@ main(int argc, char **argv)
endwin();
+ return 0;
}
View
1 src/hftirc.h
@@ -7,6 +7,7 @@
#define HFTIRC_H
#define _XOPEN_SOURCE_EXTENDED 1
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
View
2 src/input.c
@@ -23,7 +23,7 @@ input_quit(const char *input)
/*
* Input management: Index array + associativ loop
*/
-static struct
+static const struct
{
char *cmd;
int len;
View
80 src/ui.c
@@ -3,6 +3,8 @@
* For license, see COPYING
*/
+#include <ctype.h>
+
#include "hftirc.h"
#include "ui.h"
#include "util.h"
@@ -67,21 +69,6 @@ ui_init_color(void)
H.ui.c = n;
}
-static void
-ui_update_cursor(void)
-{
- struct inputbuffer *ib = &H.ui.ib;
- wchar_t c ;
-
- wmove(H.ui.inputwin, 0, ib->cpos);
-
- if(!(c = ib->buffer[ib->pos]))
- c = ' ';
-
- hftirc_waddwch(H.ui.inputwin, A_REVERSE, c);
- wrefresh(H.ui.inputwin);
-}
-
void
ui_init(void)
{
@@ -227,7 +214,7 @@ ui_print_buf(struct buffer *b, char *fmt, ...)
(void)vasprintf(&str, fmt, args);
va_end(args);
- xasprintf(&fstr, "[dev:4:20] %s\n", str);
+ xasprintf(&fstr, "[dev:4:20] %s\n", str);
bl = ui_buffer_line_new(b, fstr);
@@ -258,9 +245,8 @@ ui_get_input(void)
{
struct buffer *bf;
struct inputbuffer *ib = &H.ui.ib;
- wchar_t tmpbuf[BUFSIZE], *cmp;
char buf[BUFSIZE];
- int i, j, n, b = 1, t;
+ int i, j, n, t;
wint_t c;
switch((t = get_wch(&c)))
@@ -269,6 +255,22 @@ ui_get_input(void)
default:
switch(c)
{
+ case KEY_F(1):
+ case CTRLK('p'):
+ if(!(bf = TAILQ_PREV(H.bufsel, bsub, next)))
+ bf = TAILQ_LAST(&H.h.buffer, bsub);
+
+ ui_buffer_set(bf);
+ break;
+
+ case KEY_F(2):
+ case CTRLK('n'):
+ if(!(bf = TAILQ_NEXT(H.bufsel, next)))
+ bf = TAILQ_FIRST(&H.h.buffer);
+
+ ui_buffer_set(bf);
+ break;
+
case KEY_HOME:
wmove(H.ui.inputwin, 0, 0);
ib->pos = ib->cpos = 0;
@@ -290,6 +292,15 @@ ui_get_input(void)
ib->cpos = (int)wcslen(ib->buffer);
break;
+ case KEY_DC:
+ wdelch(H.ui.inputwin);
+
+ if(ib->buffer[ib->pos] != 0 && ib->pos >= 0)
+ for(i = ib->pos;
+ ib->buffer[i];
+ ib->buffer[i] = ib->buffer[i + 1], ++i);
+ break;
+
case KEY_UP:
if(ib->nhisto)
{
@@ -530,22 +541,29 @@ ui_get_input(void)
ib->prev = c;
werase(H.ui.inputwin);
ib->cpos = (ib->cpos < 0 ? 0 : ib->cpos);
- mvwaddwstr(H.ui.inputwin, 0, 0, ib->buffer + ib->split);
- wcstombs(buf, ib->buffer, BUFSIZE);
+
+ for(i = 0; (c = *(ib->buffer + ib->split + i)); ++i)
+ hftirc_waddwch(H.ui.inputwin, (i == ib->cpos ? A_REVERSE : A_NORMAL), c);
+
+ if(ib->cpos == wcslen(ib->buffer) || ib->cpos == COLS - 1 || ib->spting)
+ waddch(H.ui.inputwin, ' ' | A_REVERSE);
/* /<num> to go on the buffer num */
- if(buf[0] == '/' &&
- ((isdigit(buf[1]) && (n= atoi(&buf[1])) >= 0 && n < 10) /* /n */
- || (buf[1] == ' ' && (n = atoi(&buf[2])) > 9)) /* / nn */
- && (bf = ui_buffer_gb_id(n)))
+ if(ib->buffer[0] == '/')
{
- ui_buffer_set(bf);
- werase(H.ui.inputwin);
- wmemset(ib->buffer, 0, BUFSIZE);
- ib->pos = ib->cpos = ib->split = ib->hits = 0;
- wmove(H.ui.inputwin, 0, 0);
+ if((isdigit((char)ib->buffer[1]) && (n = atoi((char*)&ib->buffer[1])) >= 0 && n < 10) /* /n */
+ || (ib->buffer[1] == ' ' && (n = atoi((char*)&ib->buffer[2])) > 9)) /* / nn */
+ {
+ if((bf = ui_buffer_gb_id(n)))
+ {
+ ui_buffer_set(bf);
+ werase(H.ui.inputwin);
+ wmemset(ib->buffer, 0, BUFSIZE);
+ ib->pos = ib->cpos = ib->split = ib->hits = 0;
+ wmove(H.ui.inputwin, 0, 0);
+ }
+ }
}
- ui_update_cursor();
-
+ wrefresh(H.ui.inputwin);
}
View
4 src/util.c
@@ -3,6 +3,8 @@
* For license, see COPYING
*/
+#include <err.h>
+
#include "hftirc.h"
#include "util.h"
@@ -48,7 +50,7 @@ void
hftirc_waddwch(WINDOW *w, unsigned int mask, wchar_t wch)
{
cchar_t cch;
- wchar_t wstr[2] = { wch, '\0' };
+ wchar_t wstr[2] = { wch };
wattron(w, mask);

0 comments on commit 9d4a1f5

Please sign in to comment.