Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / fe-text / term-curses.c
index 63db46e542bccc457f393531e45e2ed6bc5b6ac4..fc674fd350477c9311ffc540a7d48024c027b758 100644 (file)
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 #include "module.h"
+#include "signals.h"
 #include "settings.h"
 
 #include "term.h"
@@ -276,8 +277,8 @@ static int get_attr(int color)
 
        if (!term_use_colors)
                attr = (color & 0x70) ? A_REVERSE : 0;
-       else if (((color & 0x0f) == 8) && (color & ATTR_BOLD) == 0)
-                attr = (A_DIM | COLOR_PAIR(63));
+       else if ((color & 0xff) == 8 || (color & (0xff | ATTR_RESETFG)) == 0)
+               attr = COLOR_PAIR(63);
        else if ((color & 0x77) == 0)
                attr = A_NORMAL;
        else {
@@ -285,7 +286,7 @@ static int get_attr(int color)
                        color &= ~0x0f;
                        color |= settings_get_int("default_color");
                }
-               attr = (COLOR_PAIR((color&7) + (color&0x70)/2));
+               attr = COLOR_PAIR((color&7) | ((color&0x70)>>1));
        }
 
        if ((color & 0x08) || (color & ATTR_BOLD)) attr |= A_BOLD;
@@ -308,13 +309,22 @@ void term_move(TERM_WINDOW *window, int x, int y)
         wmove(window->win, y, x);
 }
 
-void term_addch(TERM_WINDOW *window, int chr)
+void term_addch(TERM_WINDOW *window, char chr)
 {
         waddch(window->win, chr);
 }
 
 void term_add_unichar(TERM_WINDOW *window, unichar chr)
 {
+#ifdef WIDEC_CURSES
+       cchar_t wch;
+       wchar_t temp[2];
+       temp[0] = chr;
+       temp[1] = 0;
+       if (setcchar(&wch, temp, A_NORMAL, 0, NULL) == OK)
+               wadd_wch(window->win, &wch);
+       else
+#endif
         waddch(window->win, chr);
 }
 
@@ -362,36 +372,37 @@ void term_refresh(TERM_WINDOW *window)
 void term_stop(void)
 {
        term_deinit_int();
-       kill(getpid(), SIGSTOP);
+       kill(getpid(), SIGTSTP);
         term_init_int();
        irssi_redraw();
 }
 
-void term_auto_detach(int set)
-{
-}
-
 void term_set_input_type(int type)
 {
 }
 
-int term_gets(unichar *buffer, int size)
+void term_gets(GArray *buffer, int *line_count)
 {
-       int key, count;
+#ifdef WIDEC_CURSES
+       wint_t key;
+#else
+       int key;
+#endif
 
-       for (count = 0; count < size; ) {
-               key = getch();
+       for (;;) {
+#ifdef WIDEC_CURSES
+               if (get_wch(&key) == ERR)
+#else
+               if ((key = getch()) == ERR)
+#endif
+                       break;
 #ifdef KEY_RESIZE
                if (key == KEY_RESIZE)
                        continue;
 #endif
 
-               if (key == ERR)
-                       break;
-
-                buffer[count] = key;
-                count++;
+               g_array_append_val(buffer, key);
+               if (key == '\r' || key == '\n')
+                       (*line_count)++;
        }
-
-       return count;
 }