about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-15 23:45:18 +0000
committerJames Booth <boothj5@gmail.com>2015-01-15 23:45:18 +0000
commit9083bfdb5c7fa166802f1839442a045ecb61f7e9 (patch)
tree0b26e03c75b51b6f6c1811969a2d4c54df72bbdc
parentbb11dc097320443c810ea0572f7b988bfa48e4a4 (diff)
parent51105720ab32faa4548655266ca0ae4c661f0701 (diff)
downloadprofani-tty-9083bfdb5c7fa166802f1839442a045ecb61f7e9.tar.gz
Merge branch 'master' into inp-utf8
Conflicts:
	src/ui/inputwin.c
-rw-r--r--src/command/command.c7
-rw-r--r--src/profanity.c2
-rw-r--r--src/ui/core.c9
-rw-r--r--src/ui/inputwin.c30
-rw-r--r--src/ui/inputwin.h2
-rw-r--r--src/ui/ui.h2
6 files changed, 26 insertions, 26 deletions
diff --git a/src/command/command.c b/src/command/command.c
index fb2ef9c5..5535c022 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -1772,9 +1772,10 @@ cmd_process_input(char *inp)
 void
 cmd_execute_connect(const char * const account)
 {
-    char inp[INP_WIN_MAX];
-    snprintf(inp, sizeof(inp), "%s %s", "/connect", account);
-    cmd_process_input(inp);
+    GString *command = g_string_new("/connect ");
+    g_string_append(command, account);
+    cmd_process_input(command->str);
+    g_string_free(command, TRUE);
 }
 
 static gboolean
diff --git a/src/profanity.c b/src/profanity.c
index d7613396..13297124 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -97,7 +97,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
         }
         cmd_result = cmd_process_input(line);
         ui_input_clear();
-        line = NULL;
+        FREE_SET_NULL(line);
     }
 }
 
diff --git a/src/ui/core.c b/src/ui/core.c
index 9ded610b..69701616 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -74,7 +74,6 @@
 
 static char *win_title;
 
-static char line[INP_WIN_MAX];
 static int inp_size;
 
 #ifdef HAVE_LIBXSS
@@ -183,8 +182,8 @@ ui_readline(void)
 {
     int key_type;
     wint_t ch;
-    inp_get_char(line, &key_type, &ch);
 
+    char *line = inp_get_char(&key_type, &ch);
     _win_handle_switch(ch);
 
     ProfWin *current = wins_get_current();
@@ -201,11 +200,7 @@ ui_readline(void)
         ui_input_nonblocking(FALSE);
     }
 
-    if (ch == '\n') {
-        return line;
-    } else {
-        return NULL;
-    }
+    return line;
 }
 
 void
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 917f6ad7..fbfd1e3a 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -72,9 +72,12 @@
 #define KEY_CTRL_U 0025
 #define KEY_CTRL_W 0027
 
+#define INP_WIN_MAX 1000
+
 static WINDOW *inp_win;
 static int pad_start = 0;
 static int rows, cols;
+static char line[INP_WIN_MAX];
 static int inp_size;
 
 static int _handle_edit(int result, const wint_t ch, char *input);
@@ -133,17 +136,17 @@ inp_block(void)
     wtimeout(inp_win, -1);
 }
 
-void
-inp_get_char(char *result, int *key_type, wint_t *ch)
+char *
+inp_get_char(int *key_type, wint_t *ch)
 {
-    int display_size = _get_display_length(input);
+    int display_size = _get_display_length(line);
 
     // echo off, and get some more input
     noecho();
     *key_type = wget_wch(inp_win, ch);
 
     gboolean in_command = FALSE;
-    if ((display_size > 0 && result[0] == '/') ||
+    if ((display_size > 0 && line[0] == '/') ||
             (display_size == 0 && *ch == '/')) {
         in_command = TRUE;
     }
@@ -156,11 +159,11 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
     }
 
     // if it wasn't an arrow key etc
-    if (!_handle_edit(*key_type, *ch, result)) {
+    if (!_handle_edit(*key_type, *ch, line)) {
         if (_printable(*ch) && *key_type != KEY_CODE_YES) {
             if (inp_size >= INP_WIN_MAX) {
                 *ch = ERR;
-                return;
+                return NULL;
             }
 
             int inp_x = getcurx(inp_win);
@@ -170,9 +173,9 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
                 char bytes[MB_CUR_MAX];
                 size_t utf_len = wcrtomb(bytes, *ch, NULL);
 
-                char *next_ch = g_utf8_offset_to_pointer(result, inp_x);
+                char *next_ch = g_utf8_offset_to_pointer(line, inp_x);
                 char *offset;
-                for (offset = &result[inp_size - 1]; offset >= next_ch; offset--) {
+                for (offset = &line[inp_size - 1]; offset >= next_ch; offset--) {
                     *(offset + utf_len) = *offset;
                 }
                 int i;
@@ -181,7 +184,7 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
                 }
 
                 inp_size += utf_len;
-                result[inp_size] = '\0';
+                line[inp_size] = '\0';
                 waddstr(inp_win, next_ch);
                 wmove(inp_win, 0, inp_x + 1);
 
@@ -199,9 +202,9 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
                 if (utf_len < MB_CUR_MAX) {
                     int i;
                     for (i = 0 ; i < utf_len; i++) {
-                        result[inp_size++] = bytes[i];
+                        line[inp_size++] = bytes[i];
                     }
-                    result[inp_size] = '\0';
+                    line[inp_size] = '\0';
 
                     bytes[utf_len] = '\0';
                     waddstr(inp_win, bytes);
@@ -224,8 +227,11 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
     echo();
 
     if (*ch == '\n') {
-        result[inp_size++] = '\0';
+        line[inp_size++] = '\0';
         inp_size = 0;
+        return strdup(line);
+    } else {
+        return NULL;
     }
 }
 
diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h
index eb6c2127..5d104cdb 100644
--- a/src/ui/inputwin.h
+++ b/src/ui/inputwin.h
@@ -36,7 +36,7 @@
 #define UI_INPUTWIN_H
 
 void create_input_window(void);
-void inp_get_char(char *result, int *key_type, wint_t *ch);
+char* inp_get_char(int *key_type, wint_t *ch);
 void inp_win_reset(void);
 void inp_win_resize(void);
 void inp_put_back(void);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index be6d2fd0..90dd4d28 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -51,8 +51,6 @@
 #include "ui/window.h"
 #include "xmpp/xmpp.h"
 
-#define INP_WIN_MAX 1000
-
 // ui startup and control
 void ui_init(void);
 void ui_load_colours(void);
n487'>487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734