about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/input_win.c63
-rw-r--r--src/profanity.c4
-rw-r--r--src/ui.h6
-rw-r--r--src/windows.c10
4 files changed, 51 insertions, 32 deletions
diff --git a/src/input_win.c b/src/input_win.c
index c809454e..470f7cb9 100644
--- a/src/input_win.c
+++ b/src/input_win.c
@@ -38,11 +38,12 @@
  * pad_start    : 3
  * cols         : 4
  */
-
+#define _XOPEN_SOURCE_EXTENDED
 #include "config.h"
 
 #include <stdlib.h>
 #include <string.h>
+#include <wchar.h>
 
 #ifdef HAVE_NCURSES_H
 #include <ncurses.h>
@@ -64,9 +65,9 @@
 static WINDOW *inp_win;
 static int pad_start = 0;
 
-static int _handle_edit(const int ch, char *input, int *size);
-static int _printable(const int ch);
-static gboolean _special_key(const int ch);
+static int _handle_edit(const wint_t ch, char *input, int *size);
+static int _printable(const wint_t ch);
+static gboolean _special_key(const wint_t ch);
 
 void
 create_input_window(void)
@@ -128,59 +129,73 @@ inp_block(void)
     wtimeout(inp_win, -1);
 }
 
-void
-inp_get_char(int *ch, char *input, int *size)
+wint_t
+inp_get_char(char *input, int *size)
 {
     int inp_y = 0;
     int inp_x = 0;
     int i;
+    wint_t ch;
+    int display_size = 0;
+
+    if (*size != 0) {
+        display_size = g_utf8_strlen(input, *size);
+    }
 
     // echo off, and get some more input
     noecho();
-    *ch = wgetch(inp_win);
+    wget_wch(inp_win, &ch);
 
     gboolean in_command = FALSE;
 
-    if ((*size >= 1 && input[0] == '/') ||
-            (*size == 0 && *ch == '/')) {
+    if ((display_size > 0 && input[0] == '/') ||
+            (display_size == 0 && ch == '/')) {
         in_command = TRUE;
     }
 
     if (prefs_get_states()) {
-        if (*ch == ERR) {
+        if (ch == ERR) {
             prof_handle_idle();
         }
-        if (prefs_get_outtype() && (*ch != ERR) && !in_command
-                                                && _printable(*ch)) {
+        if (prefs_get_outtype() && (ch != ERR) && !in_command
+                                                && _printable(ch)) {
             prof_handle_activity();
         }
     }
 
     // if it wasn't an arrow key etc
-    if (!_handle_edit(*ch, input, size)) {
-        if (_printable(*ch)) {
+    if (!_handle_edit(ch, input, size)) {
+        if (_printable(ch)) {
             getyx(inp_win, inp_y, inp_x);
 
             // handle insert if not at end of input
-            if (inp_x < *size) {
-                winsch(inp_win, *ch);
+            if (inp_x < display_size) {
+                winsch(inp_win, ch);
                 wmove(inp_win, inp_y, inp_x+1);
 
                 for (i = *size; i > inp_x; i--)
                     input[i] = input[i-1];
-                input[inp_x] = *ch;
+                input[inp_x] = ch;
 
                 (*size)++;
 
             // otherwise just append
             } else {
-                waddch(inp_win, *ch);
-                input[(*size)++] = *ch;
+                cchar_t t = { 0, { ch, 0 } };
+                wadd_wch(inp_win, &t);
+                char bytes[5];
+                size_t utf_len = wcrtomb(bytes, ch, NULL);
+                int i;
+                for (i = 0 ; i < utf_len; i++) {
+                    int .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * $LynxId: UCDefs.h,v 1.17 2009/03/10 20:02:44 tom Exp $
 *
 * Definitions for Unicode character-translations
 */

#ifndef UCDEFS_H
#define UCDEFS_H

#ifndef HTUTILS_H
#include <HTUtils.h>
#endif

typedef struct _LYUCcharset {
    int UChndl;			/* -1 for "old" charsets, >= 0 for chartrans tables */

    const char *MIMEname;
    int enc;
    int codepage;		/* if positive, an IBM OS/2 specific number;
				   if negative, flag for no table translation */

    /* parameters below are not used by chartrans mechanism, */
    /* they describe some relationships against built-in Latin1 charset... */
    int repertoire;		/* unused */
    int codepoints;		/* subset/superset of Latin1 ? */
    int cpranges;		/* unused, obsolete by LYlowest_eightbit;
				   "which ranges have valid displayable chars
				   (including nbsp and shy)" */
    int like8859;		/* currently used for nbsp and shy only
				   (but UCT_R_8859SPECL assumed for any UCT_R_8BIT...);
				   "for which ranges is it like 8859-1" */
} LYUCcharset;

typedef enum {
    UCT_ENC_7BIT,
    UCT_ENC_8BIT,
    UCT_ENC_8859,		/* no displayable chars in 0x80-0x9F */
    UCT_ENC_8BIT_C0,		/* 8-bit + some chars in C0 control area */
    UCT_ENC_MAYBE2022,
    UCT_ENC_CJK,
    UCT_ENC_16BIT,
    UCT_ENC_UTF8
} eUCT_ENC;

#define UCT_REP_SUBSETOF_LAT1 0x01
#define UCT_REP_SUPERSETOF_LAT1 0x02
#define UCT_REP_IS_LAT1 UCT_REP_SUBSETOF_LAT1 | UCT_REP_SUPERSETOF_LAT1
/*
 *  Assume everything we deal with is included in the UCS2 reperoire,
 *  so a flag for _REP_SUBSETOF_UCS2 would be redundant.
 */

/*
 *  More general description how the code points relate to 8859-1 and UCS:
 */
#define UCT_CP_SUBSETOF_LAT1 0x01	/* implies UCT_CP_SUBSETOF_UCS2 */
#define UCT_CP_SUPERSETOF_LAT1 0x02
#define UCT_CP_SUBSETOF_UCS2 0x04

#define UCT_CP_IS_LAT1 UCT_CP_SUBSETOF_LAT1 | UCT_CP_SUPERSETOF_LAT1

/*
 *  More specific bitflags for practically important code point ranges:
 */
#define UCT_R_LOWCTRL 0x08	/* 0x00-0x1F, for completeness */
#define UCT_R_7BITINV 0x10	/* invariant???, displayable 7bit chars */
#define UCT_R_7BITNAT 0x20	/* displayable 7bit, national??? */
#define UCT_R_HIGHCTRL 0x40	/* chars in 0x80-0x9F range */
#define UCT_R_8859SPECL 0x80	/* special chars in 8859-x sets: nbsp and shy */
#define UCT_R_HIGH8BIT 0x100	/* rest of 0xA0-0xFF range */

#define UCT_R_ASCII UCT_R_7BITINV | UCT_R_7BITNAT	/* displayable US-ASCII */
#define UCT_R_LAT1  UCT_R_ASCII   | UCT_R_8859SPECL | UCT_R_HIGH8BIT
#define UCT_R_8BIT  UCT_R_LAT1    | UCT_R_HIGHCTRL	/* full 8bit range */

/*
 *  For the following some comments are in HTAnchor.c.
 */
typedef enum {
    UCT_STAGE_MIME,
    UCT_STAGE_PARSER,		/* What the parser (SGML.c) gets to see */
    UCT_STAGE_STRUCTURED,	/* What the structured stream (HTML) gets fed */
    UCT_STAGE_HTEXT,		/* What gets fed to the HText_* functions */
    UCT_STAGEMAX
} eUCT_STAGE;

typedef enum {
    UCT_SETBY_NONE,
    UCT_SETBY_DEFAULT,
    UCT_SETBY_LINK,		/* set by A or LINK CHARSET= hint */
    UCT_SETBY_STRUCTURED,	/* structured stream stage (HTML.c) */
    UCT_SETBY_PARSER,		/* set by SGML parser or similar */
    UCT_SETBY_MIME		/* set explicitly by MIME charset parameter */
} eUCT_SETBY;

typedef struct _UCStageInfo {
    int lock;			/* by what it has been set */
    int LYhndl;
    LYUCcharset C;
} UCStageInfo;

typedef struct _UCAnchorInfo {
    struct _UCStageInfo s[UCT_STAGEMAX];
} UCAnchorInfo;

#endif /* UCDEFS_H */