mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 11:43:13 +02:00
Full UTF-8 support, auto-detection of UTF-8 usage (locale)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2005-10-18
|
||||
ChangeLog - 2005-10-21
|
||||
|
||||
|
||||
Version 0.1.6 (under dev!):
|
||||
* full UTF-8 support, auto-detection of UTF-8 usage (locale)
|
||||
* added "Day changed to [date]" message when day changes
|
||||
* new plugin interface, rewritten from scratch: now loads dynamic C
|
||||
library, and perl/python are plugin scripts
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@ ALL_LINGUAS="fr es cs"
|
||||
AM_GNU_GETTEXT
|
||||
|
||||
# Checks for libraries
|
||||
AC_CHECK_LIB(ncurses, initscr, LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
AC_CHECK_LIB(ncursesw, initscr, LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
|
||||
# Checks for header files
|
||||
AC_HEADER_STDC
|
||||
@@ -105,10 +105,10 @@ AM_CONDITIONAL(HAVE_GNUTLS, test "$enable_gnutls" = "yes")
|
||||
if test "x$enable_ncurses" = "xyes" ; then
|
||||
if test "$LIBNCURSES_FOUND" = "0" ; then
|
||||
AC_MSG_ERROR([
|
||||
*** ncurses library not found!
|
||||
*** ncursesw library not found!
|
||||
*** Please install ncurses library or run ./configure with --disable-ncurses parameter.])
|
||||
fi
|
||||
NCURSES_LIBS="-lncurses"
|
||||
NCURSES_LIBS="-lncursesw"
|
||||
AC_SUBST(NCURSES_LIBS)
|
||||
fi
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
./src/common/hotlist.h
|
||||
./src/common/log.c
|
||||
./src/common/log.h
|
||||
./src/common/utf8.c
|
||||
./src/common/utf8.h
|
||||
./src/common/weechat.c
|
||||
./src/common/weechat.h
|
||||
./src/common/weeconfig.c
|
||||
|
||||
+311
-298
File diff suppressed because it is too large
Load Diff
@@ -36,4 +36,6 @@ lib_weechat_main_a_SOURCES = weechat.c \
|
||||
log.c \
|
||||
log.h \
|
||||
fifo.c \
|
||||
fifo.h
|
||||
fifo.h \
|
||||
utf8.c \
|
||||
utf8.h
|
||||
|
||||
+14
-3
@@ -30,6 +30,7 @@
|
||||
#include "weechat.h"
|
||||
#include "completion.h"
|
||||
#include "command.h"
|
||||
#include "utf8.h"
|
||||
#include "weelist.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../irc/irc.h"
|
||||
@@ -646,7 +647,8 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
completion_stop (completion);
|
||||
else
|
||||
{
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
((t_irc_channel *)channel)->topic);
|
||||
@@ -1000,14 +1002,23 @@ completion_search (t_completion *completion, void *channel,
|
||||
if (completion->word_found)
|
||||
{
|
||||
if (old_word_found)
|
||||
{
|
||||
completion->diff_size = strlen (completion->word_found) -
|
||||
strlen (old_word_found);
|
||||
strlen (old_word_found);
|
||||
completion->diff_length = utf8_strlen (completion->word_found) -
|
||||
utf8_strlen (old_word_found);
|
||||
}
|
||||
else
|
||||
{
|
||||
completion->diff_size = strlen (completion->word_found) -
|
||||
strlen (completion->base_word);
|
||||
strlen (completion->base_word);
|
||||
completion->diff_length = utf8_strlen (completion->word_found) -
|
||||
utf8_strlen (completion->base_word);
|
||||
if (completion->context == COMPLETION_COMMAND)
|
||||
{
|
||||
completion->diff_size++;
|
||||
completion->diff_length++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ struct t_completion
|
||||
char *word_found; /* word found (to replace base word) */
|
||||
int position_replace; /* position where word has to be replaced */
|
||||
int diff_size; /* size difference (< 0 = char(s) deleted) */
|
||||
int diff_length; /* length difference (<= diff_size) */
|
||||
};
|
||||
|
||||
extern void completion_init (t_completion *);
|
||||
|
||||
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* utf8.c: UTF-8 string functions for WeeChat */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "weechat.h"
|
||||
#include "utf8.h"
|
||||
#include "weeconfig.h"
|
||||
|
||||
|
||||
int local_utf8 = 0;
|
||||
|
||||
|
||||
/*
|
||||
* utf8_init: initializes UTF-8 in WeeChat
|
||||
*/
|
||||
|
||||
void
|
||||
utf8_init ()
|
||||
{
|
||||
local_utf8 = 0;
|
||||
|
||||
if (cfg_look_charset_internal && cfg_look_charset_internal[0])
|
||||
{
|
||||
if (strstr (cfg_look_charset_internal, "UTF-8")
|
||||
|| strstr (cfg_look_charset_internal, "utf-8"))
|
||||
local_utf8 = 1;
|
||||
}
|
||||
else if ((local_charset)
|
||||
&& ((strstr (local_charset, "UTF-8")
|
||||
|| strstr (local_charset, "utf-8"))))
|
||||
local_utf8 = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_is_valid: return 1 if UTF-8 string is valid, 0 otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_is_valid (char *string)
|
||||
{
|
||||
while (string[0])
|
||||
{
|
||||
/* UTF-8, 2 bytes, should be: 110vvvvv 10vvvvvv */
|
||||
if (((unsigned char)(string[0]) & 0xE0) == 0xC0)
|
||||
{
|
||||
if (!string[1] || (((unsigned char)(string[1]) & 0xC0) != 0x80))
|
||||
return 0;
|
||||
string += 2;
|
||||
}
|
||||
/* UTF-8, 3 bytes, should be: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF0) == 0xE0)
|
||||
{
|
||||
if (!string[1] || !string[2]
|
||||
|| (((unsigned char)(string[1]) & 0xC0) != 0x80)
|
||||
|| (((unsigned char)(string[2]) & 0xC0) != 0x80))
|
||||
return 0;
|
||||
string += 3;
|
||||
}
|
||||
/* UTF-8, 4 bytes, should be: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF8) == 0xF0)
|
||||
{
|
||||
if (!string[1] || !string[2] || !string[3]
|
||||
|| (((unsigned char)(string[1]) & 0xC0) != 0x80)
|
||||
|| (((unsigned char)(string[2]) & 0xC0) != 0x80)
|
||||
|| (((unsigned char)(string[3]) & 0xC0) != 0x80))
|
||||
return 0;
|
||||
string += 4;
|
||||
}
|
||||
/* UTF-8, 1 byte, should be: 0vvvvvvv */
|
||||
else if ((unsigned char)(string[0]) >= 0x80)
|
||||
return 0;
|
||||
else
|
||||
string++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_prev_char: return previous UTF-8 char in a string
|
||||
*/
|
||||
|
||||
char *
|
||||
utf8_prev_char (char *string_start, char *string)
|
||||
{
|
||||
if (!string || (string <= string_start))
|
||||
return NULL;
|
||||
|
||||
string--;
|
||||
|
||||
if (!local_utf8)
|
||||
return string;
|
||||
|
||||
if (((unsigned char)(string[0]) & 0xC0) == 0x80)
|
||||
{
|
||||
/* UTF-8, at least 2 bytes */
|
||||
string--;
|
||||
if (string < string_start)
|
||||
return string + 1;
|
||||
if (((unsigned char)(string[0]) & 0xC0) == 0x80)
|
||||
{
|
||||
/* UTF-8, at least 3 bytes */
|
||||
string--;
|
||||
if (string < string_start)
|
||||
return string + 1;
|
||||
if (((unsigned char)(string[0]) & 0xC0) == 0x80)
|
||||
{
|
||||
/* UTF-8, 4 bytes */
|
||||
string--;
|
||||
if (string < string_start)
|
||||
return string + 1;
|
||||
return string;
|
||||
}
|
||||
else
|
||||
return string;
|
||||
}
|
||||
else
|
||||
return string;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_next_char: return next UTF-8 char in a string
|
||||
*/
|
||||
|
||||
char *
|
||||
utf8_next_char (char *string)
|
||||
{
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
if (!local_utf8)
|
||||
return string + 1;
|
||||
|
||||
/* UTF-8, 2 bytes: 110vvvvv 10vvvvvv */
|
||||
if (((unsigned char)(string[0]) & 0xE0) == 0xC0)
|
||||
{
|
||||
if (!string[1])
|
||||
return string + 1;
|
||||
return string + 2;
|
||||
}
|
||||
/* UTF-8, 3 bytes: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF0) == 0xE0)
|
||||
{
|
||||
if (!string[1])
|
||||
return string + 1;
|
||||
if (!string[2])
|
||||
return string + 2;
|
||||
return string + 3;
|
||||
}
|
||||
/* UTF-8, 4 bytes: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF8) == 0xF0)
|
||||
{
|
||||
if (!string[1])
|
||||
return string + 1;
|
||||
if (!string[2])
|
||||
return string + 2;
|
||||
if (!string[3])
|
||||
return string + 3;
|
||||
return string + 4;
|
||||
}
|
||||
/* UTF-8, 1 byte: 0vvvvvvv */
|
||||
return string + 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_char_size: return UTF-8 char size
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_char_size (char *string)
|
||||
{
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
return utf8_next_char (string) - string;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_strlen: return length of an UTF-8 string (<= strlen(string))
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_strlen (char *string)
|
||||
{
|
||||
int length;
|
||||
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
if (!local_utf8)
|
||||
return strlen (string);
|
||||
|
||||
length = 0;
|
||||
while (string[0])
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_strlen: return length of an UTF-8 string, for N bytes
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_strnlen (char *string, int bytes)
|
||||
{
|
||||
char *start;
|
||||
int length;
|
||||
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
if (!local_utf8)
|
||||
{
|
||||
length = strlen (string);
|
||||
if (bytes > length)
|
||||
return length;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
start = string;
|
||||
length = 0;
|
||||
while (string[0] && (string - start < bytes))
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_add_offset: moves forward N chars in an UTF-8 string
|
||||
*/
|
||||
|
||||
char *
|
||||
utf8_add_offset (char *string, int offset)
|
||||
{
|
||||
int count;
|
||||
|
||||
if (!string)
|
||||
return string;
|
||||
|
||||
if (!local_utf8)
|
||||
return string + offset;
|
||||
|
||||
count = 0;
|
||||
while (string[0] && (count < offset))
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
count++;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_real_pos: get real position in UTF-8
|
||||
* for example: ("aébc", 2) returns 3
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_real_pos (char *string, int pos)
|
||||
{
|
||||
int count, real_pos;
|
||||
char *next_char;
|
||||
|
||||
if (!string || !local_utf8)
|
||||
return pos;
|
||||
|
||||
count = 0;
|
||||
real_pos = 0;
|
||||
while (string[0] && (count < pos))
|
||||
{
|
||||
next_char = utf8_next_char (string);
|
||||
real_pos += (next_char - string);
|
||||
string = next_char;
|
||||
count++;
|
||||
}
|
||||
return real_pos;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_pos: get position in UTF-8
|
||||
* for example: ("aébc", 3) returns 2
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_pos (char *string, int real_pos)
|
||||
{
|
||||
int count;
|
||||
char *limit;
|
||||
|
||||
if (!string || !local_charset)
|
||||
return real_pos;
|
||||
|
||||
count = 0;
|
||||
limit = string + real_pos;
|
||||
while (string[0] && (string < limit))
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __WEECHAT_UTF8_H
|
||||
#define __WEECHAT_UTF8_H 1
|
||||
|
||||
extern int local_utf8;
|
||||
|
||||
extern void utf8_init ();
|
||||
extern int utf8_is_valid (char *);
|
||||
extern char *utf8_prev_char (char *, char *);
|
||||
extern char *utf8_next_char (char *);
|
||||
extern int utf8_char_size (char *);
|
||||
extern int utf8_strlen (char *);
|
||||
extern int utf8_strnlen (char *, int);
|
||||
extern char *utf8_add_offset (char *, int);
|
||||
extern int utf8_real_pos (char *, int);
|
||||
extern int utf8_pos (char *, int);
|
||||
|
||||
#endif /* utf8.h */
|
||||
@@ -64,6 +64,7 @@
|
||||
#include "weeconfig.h"
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@@ -413,7 +414,8 @@ void wee_display_key_functions ()
|
||||
* wee_display_keys: display WeeChat default keys
|
||||
*/
|
||||
|
||||
void wee_display_keys ()
|
||||
void
|
||||
wee_display_keys ()
|
||||
{
|
||||
t_gui_key *ptr_key;
|
||||
char *expanded_name;
|
||||
@@ -879,6 +881,7 @@ main (int argc, char *argv[])
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
utf8_init (); /* init UTF-8 in WeeChat */
|
||||
gui_init (); /* init WeeChat interface */
|
||||
weechat_welcome_message (); /* display WeeChat welcome message */
|
||||
#ifdef PLUGINS
|
||||
|
||||
+28
-9
@@ -40,6 +40,7 @@
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "log.h"
|
||||
#include "utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@@ -67,7 +68,8 @@ int cfg_look_set_title;
|
||||
int cfg_look_startup_logo;
|
||||
int cfg_look_startup_version;
|
||||
char *cfg_look_weechat_slogan;
|
||||
char *cfg_look_charset_decode;
|
||||
char *cfg_look_charset_decode_iso;
|
||||
char *cfg_look_charset_decode_utf;
|
||||
char *cfg_look_charset_encode;
|
||||
char *cfg_look_charset_internal;
|
||||
char *cfg_look_buffer_timestamp;
|
||||
@@ -112,18 +114,24 @@ t_config_option weechat_options_look[] =
|
||||
N_("WeeChat slogan (if empty, slogan is not used)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"the geekest IRC client!", NULL, NULL, &cfg_look_weechat_slogan, config_change_noop },
|
||||
{ "look_charset_decode", N_("charset for decoding messages from server"),
|
||||
N_("charset for decoding messages from server, examples: UTF-8, ISO-8859-1 (if empty, messages are not converted)"),
|
||||
{ "look_charset_decode_iso", N_("ISO charset for decoding messages from server (used only if locale is UTF-8)"),
|
||||
N_("ISO charset for decoding messages from server (used only if locale is UTF-8) "
|
||||
"(if empty, messages are not converted if locale is UTF-8"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"UTF-8", NULL, NULL, &cfg_look_charset_decode, config_change_buffer_content },
|
||||
"ISO-8859-1", NULL, NULL, &cfg_look_charset_decode_iso, config_change_charset },
|
||||
{ "look_charset_decode_utf", N_("UTF charset for decoding messages from server (used only if locale is not UTF-8)"),
|
||||
N_("UTF charset for decoding messages from server (used only if locale is not UTF-8) "
|
||||
"(if empty, messages are not converted if locale is not UTF-8"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"UTF-8", NULL, NULL, &cfg_look_charset_decode_utf, config_change_charset },
|
||||
{ "look_charset_encode", N_("charset for encoding messages sent to server"),
|
||||
N_("charset for encoding messages sent to server, examples: UFT-8, ISO-8859-1 (if empty, local charset is used)"),
|
||||
N_("charset for encoding messages sent to server, examples: UFT-8, ISO-8859-1 (if empty, messages are not converted)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"", NULL, NULL, &cfg_look_charset_encode, config_change_buffer_content },
|
||||
{ "look_charset_internal", N_("internal WeeChat charset (should be ISO)"),
|
||||
N_("internal WeeChat charset, should be ISO-xxxx even if locale is UTF-8 (if empty, local charset is used)"),
|
||||
"", NULL, NULL, &cfg_look_charset_encode, config_change_charset },
|
||||
{ "look_charset_internal", N_("forces internal WeeChat charset (should be empty in most cases)"),
|
||||
N_("forces internal WeeChat charset (should be empty in most cases, that means detected charset is used)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"ISO-8859-1", NULL, NULL, &cfg_look_charset_internal, config_change_buffer_content },
|
||||
"", NULL, NULL, &cfg_look_charset_internal, config_change_charset },
|
||||
{ "look_buffer_timestamp", N_("timestamp for buffers"),
|
||||
N_("timestamp for buffers"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
@@ -972,6 +980,17 @@ config_change_buffer_content ()
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_change_charset: called when charset changes
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_charset ()
|
||||
{
|
||||
utf8_init ();
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_change_color: called when a color is changed by /set command
|
||||
*/
|
||||
|
||||
@@ -83,7 +83,8 @@ extern int cfg_look_set_title;
|
||||
extern int cfg_look_startup_logo;
|
||||
extern int cfg_look_startup_version;
|
||||
extern char *cfg_look_weechat_slogan;
|
||||
extern char *cfg_look_charset_decode;
|
||||
extern char *cfg_look_charset_decode_iso;
|
||||
extern char *cfg_look_charset_decode_utf;
|
||||
extern char *cfg_look_charset_encode;
|
||||
extern char *cfg_look_charset_internal;
|
||||
extern char *cfg_look_buffer_timestamp;
|
||||
@@ -217,6 +218,7 @@ extern void config_change_noop ();
|
||||
extern void config_change_title ();
|
||||
extern void config_change_buffers ();
|
||||
extern void config_change_buffer_content ();
|
||||
extern void config_change_charset ();
|
||||
extern void config_change_color ();
|
||||
extern void config_change_nicks_colors ();
|
||||
extern void config_change_away_check ();
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "../../common/weeconfig.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/log.h"
|
||||
#include "../../common/utf8.h"
|
||||
#include "../../irc/irc.h"
|
||||
|
||||
|
||||
@@ -352,7 +353,8 @@ gui_draw_buffer_title (t_gui_buffer *buffer, int erase)
|
||||
{
|
||||
if (CHANNEL(buffer)->topic)
|
||||
{
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
CHANNEL(buffer)->topic);
|
||||
@@ -413,7 +415,8 @@ gui_message_get_next_char (t_gui_message **message, int *offset)
|
||||
{
|
||||
if (!(*message))
|
||||
return;
|
||||
(*offset)++;
|
||||
|
||||
(*offset) += utf8_char_size ((*message)->message + (*offset));
|
||||
if (!((*message)->message[*offset]))
|
||||
{
|
||||
*message = (*message)->next_message;
|
||||
@@ -433,7 +436,7 @@ gui_display_word (t_gui_window *window, t_gui_line *line,
|
||||
{
|
||||
char format_align[32];
|
||||
char saved_char_end, saved_char;
|
||||
int end_of_word, chars_to_display, num_displayed;
|
||||
int pos_saved_char, end_of_word, chars_to_display, num_displayed;
|
||||
|
||||
if (!message || !end_msg ||
|
||||
((!simulate) && (window->win_chat_cursor_y > window->win_chat_height - 1)))
|
||||
@@ -470,22 +473,23 @@ gui_display_word (t_gui_window *window, t_gui_line *line,
|
||||
window->win_chat_cursor_x += line->length_align;
|
||||
}
|
||||
|
||||
chars_to_display = strlen (message->message + offset);
|
||||
chars_to_display = utf8_strlen (message->message + offset);
|
||||
|
||||
/* too long for current line */
|
||||
if (window->win_chat_cursor_x + chars_to_display > window->win_chat_width)
|
||||
{
|
||||
num_displayed = window->win_chat_width - window->win_chat_cursor_x;
|
||||
saved_char = message->message[offset + num_displayed];
|
||||
message->message[offset + num_displayed] = '\0';
|
||||
pos_saved_char = utf8_real_pos (message->message + offset, num_displayed);
|
||||
saved_char = message->message[offset + pos_saved_char];
|
||||
message->message[offset + pos_saved_char] = '\0';
|
||||
if ((!simulate) &&
|
||||
((count == 0) || (*lines_displayed >= num_lines - count)))
|
||||
mvwprintw (window->win_chat,
|
||||
window->win_chat_cursor_y,
|
||||
window->win_chat_cursor_x,
|
||||
"%s", message->message + offset);
|
||||
message->message[offset + num_displayed] = saved_char;
|
||||
offset += num_displayed;
|
||||
message->message[offset + pos_saved_char] = saved_char;
|
||||
offset += pos_saved_char;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -498,10 +502,15 @@ gui_display_word (t_gui_window *window, t_gui_line *line,
|
||||
"%s", message->message + offset);
|
||||
if (message == end_msg)
|
||||
{
|
||||
offset = end_offset;
|
||||
if (end_msg)
|
||||
end_msg->message[end_offset + 1] = saved_char_end;
|
||||
gui_message_get_next_char (&message, &offset);
|
||||
if (saved_char_end == '\0')
|
||||
{
|
||||
message = message->next_message;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
offset = end_offset + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -564,9 +573,9 @@ gui_get_word_info (t_gui_message *message, int offset,
|
||||
while (message && (message->message[offset]) && (message->message[offset] != ' '))
|
||||
{
|
||||
*word_end_msg = message;
|
||||
*word_end_offset = offset;
|
||||
(*word_length_with_spaces)++;
|
||||
(*word_length)++;
|
||||
*word_end_offset = offset + utf8_char_size (message->message + offset) - 1;
|
||||
(*word_length_with_spaces) += utf8_char_size (message->message + offset);
|
||||
(*word_length) += utf8_char_size (message->message + offset);
|
||||
gui_message_get_next_char (&message, &offset);
|
||||
}
|
||||
}
|
||||
@@ -831,7 +840,8 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
mvwprintw (ptr_win->win_chat, i, 0, "%s %-16s ",
|
||||
(ptr_dcc == dcc_selected) ? "***" : " ",
|
||||
ptr_dcc->nick);
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
(DCC_IS_CHAT(ptr_dcc->type)) ?
|
||||
@@ -854,7 +864,8 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
(DCC_IS_RECV(ptr_dcc->type)) ? "-->>" : "<<--");
|
||||
gui_window_set_color (ptr_win->win_chat,
|
||||
COLOR_DCC_WAITING + ptr_dcc->status);
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_(dcc_status_string[ptr_dcc->status]));
|
||||
@@ -905,7 +916,8 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
else
|
||||
num_unit = 3;
|
||||
sprintf (format, " (%s %%s/s)", unit_format[num_unit]);
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
unit_name[num_unit]);
|
||||
@@ -1248,7 +1260,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
wprintw (ptr_win->win_status, "%s", SERVER(ptr_win->buffer)->name);
|
||||
if (SERVER(ptr_win->buffer)->is_away)
|
||||
{
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("(away)"));
|
||||
@@ -1365,7 +1378,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
wprintw (ptr_win->win_status, "<DCC> ");
|
||||
else
|
||||
{
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("[not connected]"));
|
||||
@@ -1381,7 +1395,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
COLOR_WIN_STATUS_DELIMITERS);
|
||||
wprintw (ptr_win->win_status, "[");
|
||||
gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS);
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("Act: "));
|
||||
@@ -1474,7 +1489,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
COLOR_WIN_STATUS_DELIMITERS);
|
||||
wprintw (ptr_win->win_status, "[");
|
||||
gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS);
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("Lag: %.1f"));
|
||||
@@ -1495,7 +1511,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
}
|
||||
else
|
||||
x = ptr_win->win_width - 2;
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("-MORE-"));
|
||||
@@ -1712,7 +1729,7 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
}
|
||||
else if (buffer->has_input)
|
||||
{
|
||||
if (buffer->input_buffer_size == 0)
|
||||
if (buffer->input_buffer_length == 0)
|
||||
buffer->input_buffer[0] = '\0';
|
||||
|
||||
input_width = gui_get_input_width (ptr_win);
|
||||
@@ -1750,7 +1767,8 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
snprintf (format, 32, "%%-%ds", input_width);
|
||||
if (ptr_win == gui_current_window)
|
||||
wprintw (ptr_win->win_input, format,
|
||||
buffer->input_buffer + buffer->input_buffer_1st_display);
|
||||
utf8_add_offset (buffer->input_buffer,
|
||||
buffer->input_buffer_1st_display));
|
||||
else
|
||||
wprintw (ptr_win->win_input, format,
|
||||
"");
|
||||
@@ -1776,7 +1794,8 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
snprintf (format, 32, "%%-%ds", input_width);
|
||||
if (ptr_win == gui_current_window)
|
||||
wprintw (ptr_win->win_input, format,
|
||||
buffer->input_buffer + buffer->input_buffer_1st_display);
|
||||
utf8_add_offset (buffer->input_buffer,
|
||||
buffer->input_buffer_1st_display));
|
||||
else
|
||||
wprintw (ptr_win->win_input, format,
|
||||
"");
|
||||
@@ -1789,7 +1808,8 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
}
|
||||
}
|
||||
|
||||
wnoutrefresh (ptr_win->win_input);
|
||||
doupdate ();
|
||||
wrefresh (ptr_win->win_input);
|
||||
refresh ();
|
||||
}
|
||||
}
|
||||
@@ -2713,7 +2733,7 @@ gui_add_message (t_gui_buffer *buffer, int type, int color, char *message)
|
||||
ptr_string[0] = 32;
|
||||
ptr_string++;
|
||||
}
|
||||
length = strlen (message);
|
||||
length = utf8_strlen (message);
|
||||
buffer->last_line->length += length;
|
||||
if (type & MSG_TYPE_MSG)
|
||||
buffer->last_line->line_with_message = 1;
|
||||
@@ -2836,10 +2856,14 @@ gui_printf_internal (t_gui_buffer *buffer, int display_time, int type, int color
|
||||
else
|
||||
buf2 = strdup (buf);
|
||||
|
||||
buf3 = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
buf2);
|
||||
if (!local_utf8 || !utf8_is_valid (buf2))
|
||||
buf3 = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
buf2);
|
||||
else
|
||||
buf3 = strdup (buf2);
|
||||
|
||||
if (gui_init_ok)
|
||||
{
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "../../common/command.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/fifo.h"
|
||||
#include "../../common/utf8.h"
|
||||
#include "../../irc/irc.h"
|
||||
|
||||
|
||||
@@ -163,7 +164,7 @@ gui_input_grab_end ()
|
||||
void
|
||||
gui_input_read ()
|
||||
{
|
||||
int key, i;
|
||||
int key, i, insert_ok;
|
||||
char key_str[32];
|
||||
|
||||
i = 0;
|
||||
@@ -175,6 +176,7 @@ gui_input_read ()
|
||||
gui_input_grab_end ();
|
||||
|
||||
key = getch ();
|
||||
insert_ok = 1;
|
||||
|
||||
if (key == ERR)
|
||||
{
|
||||
@@ -191,6 +193,7 @@ gui_input_read ()
|
||||
|
||||
if (key < 32)
|
||||
{
|
||||
insert_ok = 0;
|
||||
key_str[0] = '^';
|
||||
key_str[1] = (char) key + '@';
|
||||
key_str[2] = '\0';
|
||||
@@ -203,11 +206,38 @@ gui_input_read ()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (key > 0xff)
|
||||
if (local_utf8)
|
||||
{
|
||||
key_str[0] = (char) (key >> 8);
|
||||
key_str[1] = (char) (key & 0xff);
|
||||
key_str[2] = '\0';
|
||||
/* 1 char: 0vvvvvvv */
|
||||
if (key < 0x80)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 2 chars: 110vvvvv 10vvvvvv */
|
||||
else if ((key & 0xE0) == 0xC0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = (char) (getch ());
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
/* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF0) == 0xE0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = (char) (getch ());
|
||||
key_str[2] = (char) (getch ());
|
||||
key_str[3] = '\0';
|
||||
}
|
||||
/* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF8) == 0xF0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = (char) (getch ());
|
||||
key_str[2] = (char) (getch ());
|
||||
key_str[3] = (char) (getch ());
|
||||
key_str[4] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -224,8 +254,13 @@ gui_input_read ()
|
||||
|
||||
/*gui_printf (gui_current_window->buffer, "gui_input_read: key = %s (%d)\n", key_str, key);*/
|
||||
|
||||
if (gui_key_pressed (key_str) != 0)
|
||||
gui_input_insert_char (gui_current_window, key);
|
||||
if ((gui_key_pressed (key_str) != 0) && (insert_ok))
|
||||
{
|
||||
gui_input_insert_string (gui_current_window, key_str, -1);
|
||||
gui_current_window->buffer->input_buffer_pos += utf8_strlen (key_str);
|
||||
gui_draw_buffer_input (gui_current_window->buffer, 0);
|
||||
gui_current_window->buffer->completion.position = -1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
+335
-273
@@ -39,6 +39,7 @@
|
||||
#include "../common/history.h"
|
||||
#include "../common/hotlist.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
|
||||
|
||||
@@ -214,6 +215,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int dcc,
|
||||
else
|
||||
new_buffer->input_buffer = NULL;
|
||||
new_buffer->input_buffer_size = 0;
|
||||
new_buffer->input_buffer_length = 0;
|
||||
new_buffer->input_buffer_pos = 0;
|
||||
new_buffer->input_buffer_1st_display = 0;
|
||||
|
||||
@@ -324,7 +326,8 @@ gui_infobar_printf (int time_displayed, int color, char *message, ...)
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
buf2 = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf2 = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
buffer);
|
||||
@@ -604,6 +607,130 @@ gui_input_optimize_buffer_size (t_gui_buffer *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_action_dcc: execute an action on a DCC after a user input
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_action_dcc (t_gui_window *window, char action)
|
||||
{
|
||||
t_irc_dcc *dcc_selected, *ptr_dcc, *ptr_dcc_next;
|
||||
|
||||
dcc_selected = (window->dcc_selected) ?
|
||||
(t_irc_dcc *) window->dcc_selected : dcc_list;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
/* accept DCC */
|
||||
case 'a':
|
||||
case 'A':
|
||||
if (dcc_selected
|
||||
&& (DCC_IS_RECV(dcc_selected->status))
|
||||
&& (dcc_selected->status == DCC_WAITING))
|
||||
{
|
||||
dcc_accept (dcc_selected);
|
||||
}
|
||||
break;
|
||||
/* cancel DCC */
|
||||
case 'c':
|
||||
case 'C':
|
||||
if (dcc_selected
|
||||
&& (!DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
dcc_close (dcc_selected, DCC_ABORTED);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
/* purge old DCC */
|
||||
case 'p':
|
||||
case 'P':
|
||||
window->dcc_selected = NULL;
|
||||
ptr_dcc = dcc_list;
|
||||
while (ptr_dcc)
|
||||
{
|
||||
ptr_dcc_next = ptr_dcc->next_dcc;
|
||||
if (DCC_ENDED(ptr_dcc->status))
|
||||
dcc_free (ptr_dcc);
|
||||
ptr_dcc = ptr_dcc_next;
|
||||
}
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* close DCC window */
|
||||
case 'q':
|
||||
case 'Q':
|
||||
if (buffer_before_dcc)
|
||||
{
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_switch_to_buffer (window, buffer_before_dcc);
|
||||
}
|
||||
else
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* remove from DCC list */
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (dcc_selected
|
||||
&& (DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
if (dcc_selected->next_dcc)
|
||||
window->dcc_selected = dcc_selected->next_dcc;
|
||||
else
|
||||
window->dcc_selected = NULL;
|
||||
dcc_free (dcc_selected);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_insert_string: insert a string into the input buffer
|
||||
* if pos == -1, string is inserted at cursor position
|
||||
* return: number of chars inserted
|
||||
* (may be different of strlen if UTF-8 string)
|
||||
*/
|
||||
|
||||
int
|
||||
gui_input_insert_string (t_gui_window *window, char *string, int pos)
|
||||
{
|
||||
int size, length;
|
||||
char *ptr_start;
|
||||
|
||||
if (window->buffer->dcc)
|
||||
{
|
||||
while (string[0])
|
||||
{
|
||||
if (string[0] >= 32)
|
||||
gui_input_action_dcc (window, string[0]);
|
||||
string = utf8_next_char (string);
|
||||
}
|
||||
}
|
||||
else if (window->buffer->has_input)
|
||||
{
|
||||
if (pos == -1)
|
||||
pos = window->buffer->input_buffer_pos;
|
||||
|
||||
size = strlen (string);
|
||||
length = utf8_strlen (string);
|
||||
|
||||
/* increase buffer size */
|
||||
window->buffer->input_buffer_size += size;
|
||||
window->buffer->input_buffer_length += length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
|
||||
/* move end of string to the right */
|
||||
ptr_start = utf8_add_offset (window->buffer->input_buffer, pos);
|
||||
memmove (ptr_start + size, ptr_start, strlen (ptr_start));
|
||||
|
||||
/* insert new string */
|
||||
strncpy (utf8_add_offset (window->buffer->input_buffer, pos), string, size);
|
||||
return length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_clipboard_copy: copy string into clipboard
|
||||
*/
|
||||
@@ -615,13 +742,13 @@ gui_input_clipboard_copy (char *buffer, int size)
|
||||
return;
|
||||
|
||||
if (gui_input_clipboard != NULL)
|
||||
free(gui_input_clipboard);
|
||||
free (gui_input_clipboard);
|
||||
|
||||
gui_input_clipboard = (char *) malloc( (size + 1) * sizeof(*gui_input_clipboard));
|
||||
|
||||
if (gui_input_clipboard)
|
||||
{
|
||||
memcpy(gui_input_clipboard, buffer, size);
|
||||
memcpy (gui_input_clipboard, buffer, size);
|
||||
gui_input_clipboard[size] = '\0';
|
||||
}
|
||||
}
|
||||
@@ -635,138 +762,8 @@ gui_input_clipboard_paste (t_gui_window *window)
|
||||
{
|
||||
if (window->buffer->has_input && gui_input_clipboard)
|
||||
{
|
||||
gui_input_insert_string (window, gui_input_clipboard, window->buffer->input_buffer_pos);
|
||||
window->buffer->input_buffer_pos += strlen (gui_input_clipboard);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_insert_string: insert a string into the input buffer
|
||||
* if pos == -1, string is inserted at cursor position
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_insert_string (t_gui_window *window, char *string, int pos)
|
||||
{
|
||||
int i, start, end, length;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (pos == -1)
|
||||
pos = window->buffer->input_buffer_pos;
|
||||
|
||||
length = strlen (string);
|
||||
|
||||
/* increase buffer size */
|
||||
window->buffer->input_buffer_size += length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
|
||||
/* move end of string to the right */
|
||||
start = pos + length;
|
||||
end = window->buffer->input_buffer_size - 1;
|
||||
for (i = end; i >= start; i--)
|
||||
window->buffer->input_buffer[i] =
|
||||
window->buffer->input_buffer[i - length];
|
||||
|
||||
/* insert new string */
|
||||
strncpy (window->buffer->input_buffer + pos, string, length);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_insert_char: insert a char into input buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_insert_char (t_gui_window *window, int key)
|
||||
{
|
||||
char new_char[3];
|
||||
t_irc_dcc *dcc_selected, *ptr_dcc, *ptr_dcc_next;
|
||||
|
||||
if (key < 32)
|
||||
return;
|
||||
|
||||
if (window->buffer->dcc)
|
||||
{
|
||||
dcc_selected = (window->dcc_selected) ?
|
||||
(t_irc_dcc *) window->dcc_selected : dcc_list;
|
||||
switch (key)
|
||||
{
|
||||
/* accept DCC */
|
||||
case 'a':
|
||||
case 'A':
|
||||
if (dcc_selected
|
||||
&& (DCC_IS_RECV(dcc_selected->status))
|
||||
&& (dcc_selected->status == DCC_WAITING))
|
||||
{
|
||||
dcc_accept (dcc_selected);
|
||||
}
|
||||
break;
|
||||
/* cancel DCC */
|
||||
case 'c':
|
||||
case 'C':
|
||||
if (dcc_selected
|
||||
&& (!DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
dcc_close (dcc_selected, DCC_ABORTED);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
/* purge old DCC */
|
||||
case 'p':
|
||||
case 'P':
|
||||
window->dcc_selected = NULL;
|
||||
ptr_dcc = dcc_list;
|
||||
while (ptr_dcc)
|
||||
{
|
||||
ptr_dcc_next = ptr_dcc->next_dcc;
|
||||
if (DCC_ENDED(ptr_dcc->status))
|
||||
dcc_free (ptr_dcc);
|
||||
ptr_dcc = ptr_dcc_next;
|
||||
}
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* close DCC window */
|
||||
case 'q':
|
||||
case 'Q':
|
||||
if (buffer_before_dcc)
|
||||
{
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_switch_to_buffer (window, buffer_before_dcc);
|
||||
}
|
||||
else
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* remove from DCC list */
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (dcc_selected
|
||||
&& (DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
if (dcc_selected->next_dcc)
|
||||
window->dcc_selected = dcc_selected->next_dcc;
|
||||
else
|
||||
window->dcc_selected = NULL;
|
||||
dcc_free (dcc_selected);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (window->buffer->has_input)
|
||||
{
|
||||
/*gui_printf (window->buffer,
|
||||
"[Debug] key pressed = %d, hex = %02X, octal = %o\n", key, key, key);*/
|
||||
new_char[0] = key;
|
||||
new_char[1] = '\0';
|
||||
|
||||
gui_input_insert_string (window, new_char,
|
||||
window->buffer->input_buffer_pos);
|
||||
window->buffer->input_buffer_pos++;
|
||||
gui_input_insert_string (window, gui_input_clipboard, -1);
|
||||
window->buffer->input_buffer_pos += utf8_strlen (gui_input_clipboard);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
@@ -788,6 +785,7 @@ gui_input_return (t_gui_window *window)
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
history_add (window->buffer, window->buffer->input_buffer);
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
window->buffer->completion.position = -1;
|
||||
@@ -820,7 +818,8 @@ gui_input_tab (t_gui_window *window)
|
||||
CHANNEL(window->buffer),
|
||||
window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_size,
|
||||
window->buffer->input_buffer_pos);
|
||||
utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos));
|
||||
|
||||
if (window->buffer->completion.word_found)
|
||||
{
|
||||
@@ -829,6 +828,8 @@ gui_input_tab (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer_size +=
|
||||
window->buffer->completion.diff_size;
|
||||
window->buffer->input_buffer_length +=
|
||||
window->buffer->completion.diff_length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
for (i = window->buffer->input_buffer_size - 1;
|
||||
@@ -846,28 +847,33 @@ gui_input_tab (t_gui_window *window)
|
||||
window->buffer->input_buffer[i - window->buffer->completion.diff_size];
|
||||
window->buffer->input_buffer_size +=
|
||||
window->buffer->completion.diff_size;
|
||||
window->buffer->input_buffer_length +=
|
||||
window->buffer->completion.diff_length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
}
|
||||
|
||||
|
||||
strncpy (window->buffer->input_buffer + window->buffer->completion.position_replace,
|
||||
window->buffer->completion.word_found,
|
||||
strlen (window->buffer->completion.word_found));
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->completion.position_replace +
|
||||
strlen (window->buffer->completion.word_found);
|
||||
utf8_pos (window->buffer->input_buffer,
|
||||
window->buffer->completion.position_replace) +
|
||||
utf8_strlen (window->buffer->completion.word_found);
|
||||
|
||||
/* position is < 0 this means only one word was found to complete,
|
||||
so reinit to stop completion */
|
||||
if (window->buffer->completion.position >= 0)
|
||||
window->buffer->completion.position =
|
||||
window->buffer->input_buffer_pos;
|
||||
utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
|
||||
/* add space or completor to the end of completion, if needed */
|
||||
if ((window->buffer->completion.context == COMPLETION_COMMAND)
|
||||
|| (window->buffer->completion.context == COMPLETION_COMMAND_ARG))
|
||||
{
|
||||
if (window->buffer->input_buffer[window->buffer->input_buffer_pos] != ' ')
|
||||
if (window->buffer->input_buffer[utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos)] != ' ')
|
||||
gui_input_insert_string (window, " ",
|
||||
window->buffer->input_buffer_pos);
|
||||
if (window->buffer->completion.position >= 0)
|
||||
@@ -880,14 +886,16 @@ gui_input_tab (t_gui_window *window)
|
||||
if ((window->buffer->completion.base_word_pos == 0)
|
||||
&& (window->buffer->completion.context == COMPLETION_NICK))
|
||||
{
|
||||
if (strncmp (window->buffer->input_buffer + window->buffer->input_buffer_pos,
|
||||
if (strncmp (utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos),
|
||||
cfg_look_completor, strlen (cfg_look_completor)) != 0)
|
||||
gui_input_insert_string (window, cfg_look_completor,
|
||||
window->buffer->input_buffer_pos);
|
||||
if (window->buffer->completion.position >= 0)
|
||||
window->buffer->completion.position += strlen (cfg_look_completor);
|
||||
window->buffer->input_buffer_pos += strlen (cfg_look_completor);
|
||||
if (window->buffer->input_buffer[window->buffer->input_buffer_pos] != ' ')
|
||||
window->buffer->input_buffer_pos += utf8_strlen (cfg_look_completor);
|
||||
if (window->buffer->input_buffer[utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos)] != ' ')
|
||||
gui_input_insert_string (window, " ",
|
||||
window->buffer->input_buffer_pos);
|
||||
if (window->buffer->completion.position >= 0)
|
||||
@@ -907,24 +915,25 @@ gui_input_tab (t_gui_window *window)
|
||||
void
|
||||
gui_input_backspace (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
char *pos, *pos_last;
|
||||
int char_size, size_to_move;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos-1;
|
||||
while (window->buffer->input_buffer[i])
|
||||
{
|
||||
window->buffer->input_buffer[i] =
|
||||
window->buffer->input_buffer[i+1];
|
||||
i++;
|
||||
}
|
||||
window->buffer->input_buffer_size--;
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
pos_last = utf8_prev_char (window->buffer->input_buffer, pos);
|
||||
char_size = pos - pos_last;
|
||||
size_to_move = strlen (pos);
|
||||
memmove (pos_last, pos, size_to_move);
|
||||
window->buffer->input_buffer_size -= char_size;
|
||||
window->buffer->input_buffer_length--;
|
||||
window->buffer->input_buffer_pos--;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -937,24 +946,25 @@ gui_input_backspace (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
|
||||
char *pos, *pos_next;
|
||||
int char_size, size_to_move;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos;
|
||||
while (window->buffer->input_buffer[i])
|
||||
{
|
||||
window->buffer->input_buffer[i] =
|
||||
window->buffer->input_buffer[i+1];
|
||||
i++;
|
||||
}
|
||||
window->buffer->input_buffer_size--;
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
pos_next = utf8_next_char (pos);
|
||||
char_size = pos_next - pos;
|
||||
size_to_move = strlen (pos_next);
|
||||
memmove (pos, pos_next, size_to_move);
|
||||
window->buffer->input_buffer_size -= char_size;
|
||||
window->buffer->input_buffer_length--;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -967,49 +977,53 @@ gui_input_delete (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_previous_word (t_gui_window *window)
|
||||
{
|
||||
int i, j, num_char_deleted, num_char_end;
|
||||
int length_deleted, size_deleted;
|
||||
char *start, *string;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos - 1;
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i--;
|
||||
if (i >= 0)
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos - 1);
|
||||
string = start;
|
||||
while (string && (string[0] == ' '))
|
||||
{
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] != ' '))
|
||||
i--;
|
||||
if (i >= 0)
|
||||
string = utf8_prev_char (window->buffer->input_buffer, string);
|
||||
}
|
||||
if (string)
|
||||
{
|
||||
while (string && (string[0] != ' '))
|
||||
{
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i--;
|
||||
string = utf8_prev_char (window->buffer->input_buffer, string);
|
||||
}
|
||||
if (string)
|
||||
{
|
||||
while (string && (string[0] == ' '))
|
||||
{
|
||||
string = utf8_prev_char (window->buffer->input_buffer, string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 0)
|
||||
i++;
|
||||
i++;
|
||||
num_char_deleted = window->buffer->input_buffer_pos - i;
|
||||
num_char_end = window->buffer->input_buffer_size -
|
||||
window->buffer->input_buffer_pos;
|
||||
if (string)
|
||||
string = utf8_next_char (utf8_next_char (string));
|
||||
else
|
||||
string = window->buffer->input_buffer;
|
||||
|
||||
gui_input_clipboard_copy(window->buffer->input_buffer +
|
||||
window->buffer->input_buffer_pos - num_char_deleted,
|
||||
num_char_deleted);
|
||||
size_deleted = utf8_next_char (start) - string;
|
||||
length_deleted = utf8_strnlen (string, size_deleted);
|
||||
|
||||
for (j = 0; j < num_char_end; j++)
|
||||
window->buffer->input_buffer[i + j] =
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_pos + j];
|
||||
gui_input_clipboard_copy (string, size_deleted);
|
||||
|
||||
window->buffer->input_buffer_size -= num_char_deleted;
|
||||
memmove (string, string + size_deleted, size_deleted);
|
||||
|
||||
window->buffer->input_buffer_size -= size_deleted;
|
||||
window->buffer->input_buffer_length -= length_deleted;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
window->buffer->input_buffer_pos = i;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->input_buffer_pos -= length_deleted;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1022,31 +1036,33 @@ gui_input_delete_previous_word (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_next_word (t_gui_window *window)
|
||||
{
|
||||
int i, j, num_char_deleted;
|
||||
int size_deleted, length_deleted;
|
||||
char *start, *string;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos;
|
||||
while (i < window->buffer->input_buffer_size)
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
string = start;
|
||||
length_deleted = 0;
|
||||
while (string[0])
|
||||
{
|
||||
if ((window->buffer->input_buffer[i] == ' ')
|
||||
&& i != window->buffer->input_buffer_pos)
|
||||
if ((string[0] == ' ') && (string > start))
|
||||
break;
|
||||
i++;
|
||||
string = utf8_next_char (string);
|
||||
length_deleted++;
|
||||
}
|
||||
num_char_deleted = i - window->buffer->input_buffer_pos;
|
||||
size_deleted = string - start;
|
||||
|
||||
gui_input_clipboard_copy(window->buffer->input_buffer +
|
||||
window->buffer->input_buffer_pos, num_char_deleted);
|
||||
gui_input_clipboard_copy(start, size_deleted);
|
||||
|
||||
for (j = i; j < window->buffer->input_buffer_size; j++)
|
||||
window->buffer->input_buffer[j - num_char_deleted] =
|
||||
window->buffer->input_buffer[j];
|
||||
memmove (start, string, strlen (string));
|
||||
|
||||
window->buffer->input_buffer_size -= num_char_deleted;
|
||||
window->buffer->input_buffer_size -= size_deleted;
|
||||
window->buffer->input_buffer_length -= length_deleted;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1058,26 +1074,28 @@ gui_input_delete_next_word (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_begin_of_line (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
int length_deleted, size_deleted;
|
||||
char *start;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
size_deleted = start - window->buffer->input_buffer;
|
||||
length_deleted = utf8_strnlen (window->buffer->input_buffer, size_deleted);
|
||||
gui_input_clipboard_copy (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
start - window->buffer->input_buffer);
|
||||
|
||||
for (i = window->buffer->input_buffer_pos;
|
||||
i < window->buffer->input_buffer_size; i++)
|
||||
window->buffer->input_buffer[i - window->buffer->input_buffer_pos] =
|
||||
window->buffer->input_buffer[i];
|
||||
memmove (window->buffer->input_buffer, start, strlen (start));
|
||||
|
||||
window->buffer->input_buffer_size -=
|
||||
window->buffer->input_buffer_pos;
|
||||
window->buffer->input_buffer_size -= size_deleted;
|
||||
window->buffer->input_buffer_length -= length_deleted;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1090,17 +1108,21 @@ gui_input_delete_begin_of_line (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_end_of_line (t_gui_window *window)
|
||||
{
|
||||
char *start;
|
||||
int size_deleted, length_deleted;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
gui_input_clipboard_copy(window->buffer->input_buffer +
|
||||
window->buffer->input_buffer_pos,
|
||||
window->buffer->input_buffer_size -
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_pos] = ' ';
|
||||
window->buffer->input_buffer_size = window->buffer->input_buffer_pos ;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
size_deleted = strlen (start);
|
||||
length_deleted = utf8_strlen (start);
|
||||
gui_input_clipboard_copy(start, size_deleted);
|
||||
start[0] = '\0';
|
||||
window->buffer->input_buffer_size = strlen (window->buffer->input_buffer);
|
||||
window->buffer->input_buffer_length = utf8_strlen (window->buffer->input_buffer);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1116,9 +1138,10 @@ gui_input_delete_line (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1130,23 +1153,27 @@ gui_input_delete_line (t_gui_window *window)
|
||||
void
|
||||
gui_input_transpose_chars (t_gui_window *window)
|
||||
{
|
||||
char buf;
|
||||
int curpos;
|
||||
char *start, *prev_char, saved_char[4];
|
||||
int size_current_char;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
curpos = window->buffer->input_buffer_pos;
|
||||
if (curpos == window->buffer->input_buffer_size)
|
||||
curpos--;
|
||||
else
|
||||
window->buffer->input_buffer_pos++;
|
||||
if (window->buffer->input_buffer_pos == window->buffer->input_buffer_length)
|
||||
window->buffer->input_buffer_pos--;
|
||||
|
||||
buf = window->buffer->input_buffer[curpos];
|
||||
window->buffer->input_buffer[curpos] =
|
||||
window->buffer->input_buffer[curpos-1];
|
||||
window->buffer->input_buffer[curpos-1] = buf;
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
prev_char = utf8_prev_char (window->buffer->input_buffer,
|
||||
start);
|
||||
size_current_char = start - prev_char;
|
||||
memcpy (saved_char, prev_char, size_current_char);
|
||||
memcpy (prev_char, start, utf8_char_size (start));
|
||||
start = utf8_next_char (prev_char);
|
||||
memcpy (start, saved_char, size_current_char);
|
||||
|
||||
window->buffer->input_buffer_pos++;
|
||||
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
@@ -1181,10 +1208,10 @@ gui_input_end (t_gui_window *window)
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
}
|
||||
}
|
||||
@@ -1214,25 +1241,34 @@ gui_input_left (t_gui_window *window)
|
||||
void
|
||||
gui_input_previous_word (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
char *pos;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos - 1;
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i--;
|
||||
if (i < 0)
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
else
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos - 1);
|
||||
while (pos && (pos[0] == ' '))
|
||||
{
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] != ' '))
|
||||
i--;
|
||||
window->buffer->input_buffer_pos = i + 1;
|
||||
pos = utf8_prev_char (window->buffer->input_buffer, pos);
|
||||
}
|
||||
if (pos)
|
||||
{
|
||||
while (pos && (pos[0] != ' '))
|
||||
{
|
||||
pos = utf8_prev_char (window->buffer->input_buffer, pos);
|
||||
}
|
||||
if (pos)
|
||||
pos = utf8_next_char (pos);
|
||||
else
|
||||
pos = window->buffer->input_buffer;
|
||||
window->buffer->input_buffer_pos = utf8_pos (window->buffer->input_buffer,
|
||||
pos - window->buffer->input_buffer);
|
||||
}
|
||||
else
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
}
|
||||
}
|
||||
@@ -1248,7 +1284,7 @@ gui_input_right (t_gui_window *window)
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
window->buffer->input_buffer_pos++;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
@@ -1263,31 +1299,38 @@ gui_input_right (t_gui_window *window)
|
||||
void
|
||||
gui_input_next_word (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
char *pos;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size + 1)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos;
|
||||
while ((i <= window->buffer->input_buffer_size) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i++;
|
||||
if (i > window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_pos = i - 1;
|
||||
else
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
while (pos[0] && (pos[0] == ' '))
|
||||
{
|
||||
while ((i <= window->buffer->input_buffer_size) &&
|
||||
(window->buffer->input_buffer[i] != ' '))
|
||||
i++;
|
||||
if (i > window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
else
|
||||
window->buffer->input_buffer_pos = i;
|
||||
|
||||
pos = utf8_next_char (pos);
|
||||
}
|
||||
if (pos[0])
|
||||
{
|
||||
while (pos[0] && (pos[0] != ' '))
|
||||
{
|
||||
pos = utf8_next_char (pos);
|
||||
}
|
||||
if (pos[0])
|
||||
window->buffer->input_buffer_pos =
|
||||
utf8_pos (window->buffer->input_buffer,
|
||||
pos - window->buffer->input_buffer);
|
||||
else
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_length;
|
||||
}
|
||||
else
|
||||
window->buffer->input_buffer_pos =
|
||||
utf8_pos (window->buffer->input_buffer,
|
||||
utf8_prev_char (window->buffer->input_buffer, pos) - window->buffer->input_buffer);
|
||||
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
}
|
||||
}
|
||||
@@ -1335,9 +1378,11 @@ gui_input_up (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (window->buffer->ptr_history->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (window->buffer->ptr_history->text);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
strcpy (window->buffer->input_buffer,
|
||||
window->buffer->ptr_history->text);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
@@ -1366,9 +1411,11 @@ gui_input_up_global (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (history_global_ptr->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (history_global_ptr->text);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
strcpy (window->buffer->input_buffer,
|
||||
history_global_ptr->text);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
@@ -1419,13 +1466,20 @@ gui_input_down (t_gui_window *window)
|
||||
window->buffer->ptr_history =
|
||||
window->buffer->ptr_history->prev_history;
|
||||
if (window->buffer->ptr_history)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (window->buffer->ptr_history->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (window->buffer->ptr_history->text);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
}
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
if (window->buffer->ptr_history)
|
||||
strcpy (window->buffer->input_buffer,
|
||||
window->buffer->ptr_history->text);
|
||||
@@ -1447,13 +1501,20 @@ gui_input_down_global (t_gui_window *window)
|
||||
{
|
||||
history_global_ptr = history_global_ptr->prev_history;
|
||||
if (history_global_ptr)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (history_global_ptr->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (history_global_ptr->text);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
}
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
if (history_global_ptr)
|
||||
strcpy (window->buffer->input_buffer,
|
||||
history_global_ptr->text);
|
||||
@@ -1916,6 +1977,7 @@ gui_buffer_print_log (t_gui_buffer *buffer)
|
||||
wee_log_printf (" input_buffer . . . . : '%s'\n", buffer->input_buffer);
|
||||
wee_log_printf (" input_buffer_alloc . : %d\n", buffer->input_buffer_alloc);
|
||||
wee_log_printf (" input_buffer_size. . : %d\n", buffer->input_buffer_size);
|
||||
wee_log_printf (" input_buffer_length. : %d\n", buffer->input_buffer_length);
|
||||
wee_log_printf (" input_buffer_pos . . : %d\n", buffer->input_buffer_pos);
|
||||
wee_log_printf (" input_buffer_1st_disp: %d\n", buffer->input_buffer_1st_display);
|
||||
wee_log_printf (" history. . . . . . . : 0x%X\n", buffer->history);
|
||||
|
||||
+3
-3
@@ -196,7 +196,8 @@ struct t_gui_buffer
|
||||
int has_input; /* = 1 if buffer has input (DCC has not)*/
|
||||
char *input_buffer; /* input buffer */
|
||||
int input_buffer_alloc; /* input buffer: allocated size in mem */
|
||||
int input_buffer_size; /* buffer size (user input length) */
|
||||
int input_buffer_size; /* buffer size in bytes */
|
||||
int input_buffer_length; /* number of chars in buffer */
|
||||
int input_buffer_pos; /* position into buffer */
|
||||
int input_buffer_1st_display; /* first char displayed on screen */
|
||||
|
||||
@@ -330,8 +331,7 @@ extern t_gui_line *gui_new_line (t_gui_buffer *);
|
||||
extern t_gui_message *gui_new_message (t_gui_buffer *);
|
||||
extern void gui_input_clipboard_copy (char *, int);
|
||||
extern void gui_input_clipboard_paste (t_gui_window *);
|
||||
extern void gui_input_insert_string (t_gui_window *, char *, int);
|
||||
extern void gui_input_insert_char (t_gui_window *, int);
|
||||
extern int gui_input_insert_string (t_gui_window *, char *, int);
|
||||
extern void gui_input_return (t_gui_window *);
|
||||
extern void gui_input_tab (t_gui_window *);
|
||||
extern void gui_input_backspace (t_gui_window *);
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2005-10-18
|
||||
ChangeLog - 2005-10-21
|
||||
|
||||
|
||||
Version 0.1.6 (under dev!):
|
||||
* full UTF-8 support, auto-detection of UTF-8 usage (locale)
|
||||
* added "Day changed to [date]" message when day changes
|
||||
* new plugin interface, rewritten from scratch: now loads dynamic C
|
||||
library, and perl/python are plugin scripts
|
||||
|
||||
@@ -34,7 +34,7 @@ ALL_LINGUAS="fr es cs"
|
||||
AM_GNU_GETTEXT
|
||||
|
||||
# Checks for libraries
|
||||
AC_CHECK_LIB(ncurses, initscr, LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
AC_CHECK_LIB(ncursesw, initscr, LIBNCURSES_FOUND=1, LIBNCURSES_FOUND=0)
|
||||
|
||||
# Checks for header files
|
||||
AC_HEADER_STDC
|
||||
@@ -105,10 +105,10 @@ AM_CONDITIONAL(HAVE_GNUTLS, test "$enable_gnutls" = "yes")
|
||||
if test "x$enable_ncurses" = "xyes" ; then
|
||||
if test "$LIBNCURSES_FOUND" = "0" ; then
|
||||
AC_MSG_ERROR([
|
||||
*** ncurses library not found!
|
||||
*** ncursesw library not found!
|
||||
*** Please install ncurses library or run ./configure with --disable-ncurses parameter.])
|
||||
fi
|
||||
NCURSES_LIBS="-lncurses"
|
||||
NCURSES_LIBS="-lncursesw"
|
||||
AC_SUBST(NCURSES_LIBS)
|
||||
fi
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
./src/common/hotlist.h
|
||||
./src/common/log.c
|
||||
./src/common/log.h
|
||||
./src/common/utf8.c
|
||||
./src/common/utf8.h
|
||||
./src/common/weechat.c
|
||||
./src/common/weechat.h
|
||||
./src/common/weeconfig.c
|
||||
|
||||
+307
-300
File diff suppressed because it is too large
Load Diff
+307
-302
File diff suppressed because it is too large
Load Diff
+324
-304
File diff suppressed because it is too large
Load Diff
+311
-298
File diff suppressed because it is too large
Load Diff
@@ -36,4 +36,6 @@ lib_weechat_main_a_SOURCES = weechat.c \
|
||||
log.c \
|
||||
log.h \
|
||||
fifo.c \
|
||||
fifo.h
|
||||
fifo.h \
|
||||
utf8.c \
|
||||
utf8.h
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "weechat.h"
|
||||
#include "completion.h"
|
||||
#include "command.h"
|
||||
#include "utf8.h"
|
||||
#include "weelist.h"
|
||||
#include "weeconfig.h"
|
||||
#include "../irc/irc.h"
|
||||
@@ -646,7 +647,8 @@ completion_build_list (t_completion *completion, void *channel)
|
||||
completion_stop (completion);
|
||||
else
|
||||
{
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
((t_irc_channel *)channel)->topic);
|
||||
@@ -1000,14 +1002,23 @@ completion_search (t_completion *completion, void *channel,
|
||||
if (completion->word_found)
|
||||
{
|
||||
if (old_word_found)
|
||||
{
|
||||
completion->diff_size = strlen (completion->word_found) -
|
||||
strlen (old_word_found);
|
||||
strlen (old_word_found);
|
||||
completion->diff_length = utf8_strlen (completion->word_found) -
|
||||
utf8_strlen (old_word_found);
|
||||
}
|
||||
else
|
||||
{
|
||||
completion->diff_size = strlen (completion->word_found) -
|
||||
strlen (completion->base_word);
|
||||
strlen (completion->base_word);
|
||||
completion->diff_length = utf8_strlen (completion->word_found) -
|
||||
utf8_strlen (completion->base_word);
|
||||
if (completion->context == COMPLETION_COMMAND)
|
||||
{
|
||||
completion->diff_size++;
|
||||
completion->diff_length++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ struct t_completion
|
||||
char *word_found; /* word found (to replace base word) */
|
||||
int position_replace; /* position where word has to be replaced */
|
||||
int diff_size; /* size difference (< 0 = char(s) deleted) */
|
||||
int diff_length; /* length difference (<= diff_size) */
|
||||
};
|
||||
|
||||
extern void completion_init (t_completion *);
|
||||
|
||||
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* utf8.c: UTF-8 string functions for WeeChat */
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "weechat.h"
|
||||
#include "utf8.h"
|
||||
#include "weeconfig.h"
|
||||
|
||||
|
||||
int local_utf8 = 0;
|
||||
|
||||
|
||||
/*
|
||||
* utf8_init: initializes UTF-8 in WeeChat
|
||||
*/
|
||||
|
||||
void
|
||||
utf8_init ()
|
||||
{
|
||||
local_utf8 = 0;
|
||||
|
||||
if (cfg_look_charset_internal && cfg_look_charset_internal[0])
|
||||
{
|
||||
if (strstr (cfg_look_charset_internal, "UTF-8")
|
||||
|| strstr (cfg_look_charset_internal, "utf-8"))
|
||||
local_utf8 = 1;
|
||||
}
|
||||
else if ((local_charset)
|
||||
&& ((strstr (local_charset, "UTF-8")
|
||||
|| strstr (local_charset, "utf-8"))))
|
||||
local_utf8 = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_is_valid: return 1 if UTF-8 string is valid, 0 otherwise
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_is_valid (char *string)
|
||||
{
|
||||
while (string[0])
|
||||
{
|
||||
/* UTF-8, 2 bytes, should be: 110vvvvv 10vvvvvv */
|
||||
if (((unsigned char)(string[0]) & 0xE0) == 0xC0)
|
||||
{
|
||||
if (!string[1] || (((unsigned char)(string[1]) & 0xC0) != 0x80))
|
||||
return 0;
|
||||
string += 2;
|
||||
}
|
||||
/* UTF-8, 3 bytes, should be: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF0) == 0xE0)
|
||||
{
|
||||
if (!string[1] || !string[2]
|
||||
|| (((unsigned char)(string[1]) & 0xC0) != 0x80)
|
||||
|| (((unsigned char)(string[2]) & 0xC0) != 0x80))
|
||||
return 0;
|
||||
string += 3;
|
||||
}
|
||||
/* UTF-8, 4 bytes, should be: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF8) == 0xF0)
|
||||
{
|
||||
if (!string[1] || !string[2] || !string[3]
|
||||
|| (((unsigned char)(string[1]) & 0xC0) != 0x80)
|
||||
|| (((unsigned char)(string[2]) & 0xC0) != 0x80)
|
||||
|| (((unsigned char)(string[3]) & 0xC0) != 0x80))
|
||||
return 0;
|
||||
string += 4;
|
||||
}
|
||||
/* UTF-8, 1 byte, should be: 0vvvvvvv */
|
||||
else if ((unsigned char)(string[0]) >= 0x80)
|
||||
return 0;
|
||||
else
|
||||
string++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_prev_char: return previous UTF-8 char in a string
|
||||
*/
|
||||
|
||||
char *
|
||||
utf8_prev_char (char *string_start, char *string)
|
||||
{
|
||||
if (!string || (string <= string_start))
|
||||
return NULL;
|
||||
|
||||
string--;
|
||||
|
||||
if (!local_utf8)
|
||||
return string;
|
||||
|
||||
if (((unsigned char)(string[0]) & 0xC0) == 0x80)
|
||||
{
|
||||
/* UTF-8, at least 2 bytes */
|
||||
string--;
|
||||
if (string < string_start)
|
||||
return string + 1;
|
||||
if (((unsigned char)(string[0]) & 0xC0) == 0x80)
|
||||
{
|
||||
/* UTF-8, at least 3 bytes */
|
||||
string--;
|
||||
if (string < string_start)
|
||||
return string + 1;
|
||||
if (((unsigned char)(string[0]) & 0xC0) == 0x80)
|
||||
{
|
||||
/* UTF-8, 4 bytes */
|
||||
string--;
|
||||
if (string < string_start)
|
||||
return string + 1;
|
||||
return string;
|
||||
}
|
||||
else
|
||||
return string;
|
||||
}
|
||||
else
|
||||
return string;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_next_char: return next UTF-8 char in a string
|
||||
*/
|
||||
|
||||
char *
|
||||
utf8_next_char (char *string)
|
||||
{
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
if (!local_utf8)
|
||||
return string + 1;
|
||||
|
||||
/* UTF-8, 2 bytes: 110vvvvv 10vvvvvv */
|
||||
if (((unsigned char)(string[0]) & 0xE0) == 0xC0)
|
||||
{
|
||||
if (!string[1])
|
||||
return string + 1;
|
||||
return string + 2;
|
||||
}
|
||||
/* UTF-8, 3 bytes: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF0) == 0xE0)
|
||||
{
|
||||
if (!string[1])
|
||||
return string + 1;
|
||||
if (!string[2])
|
||||
return string + 2;
|
||||
return string + 3;
|
||||
}
|
||||
/* UTF-8, 4 bytes: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if (((unsigned char)(string[0]) & 0xF8) == 0xF0)
|
||||
{
|
||||
if (!string[1])
|
||||
return string + 1;
|
||||
if (!string[2])
|
||||
return string + 2;
|
||||
if (!string[3])
|
||||
return string + 3;
|
||||
return string + 4;
|
||||
}
|
||||
/* UTF-8, 1 byte: 0vvvvvvv */
|
||||
return string + 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_char_size: return UTF-8 char size
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_char_size (char *string)
|
||||
{
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
return utf8_next_char (string) - string;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_strlen: return length of an UTF-8 string (<= strlen(string))
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_strlen (char *string)
|
||||
{
|
||||
int length;
|
||||
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
if (!local_utf8)
|
||||
return strlen (string);
|
||||
|
||||
length = 0;
|
||||
while (string[0])
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_strlen: return length of an UTF-8 string, for N bytes
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_strnlen (char *string, int bytes)
|
||||
{
|
||||
char *start;
|
||||
int length;
|
||||
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
if (!local_utf8)
|
||||
{
|
||||
length = strlen (string);
|
||||
if (bytes > length)
|
||||
return length;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
start = string;
|
||||
length = 0;
|
||||
while (string[0] && (string - start < bytes))
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_add_offset: moves forward N chars in an UTF-8 string
|
||||
*/
|
||||
|
||||
char *
|
||||
utf8_add_offset (char *string, int offset)
|
||||
{
|
||||
int count;
|
||||
|
||||
if (!string)
|
||||
return string;
|
||||
|
||||
if (!local_utf8)
|
||||
return string + offset;
|
||||
|
||||
count = 0;
|
||||
while (string[0] && (count < offset))
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
count++;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_real_pos: get real position in UTF-8
|
||||
* for example: ("aébc", 2) returns 3
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_real_pos (char *string, int pos)
|
||||
{
|
||||
int count, real_pos;
|
||||
char *next_char;
|
||||
|
||||
if (!string || !local_utf8)
|
||||
return pos;
|
||||
|
||||
count = 0;
|
||||
real_pos = 0;
|
||||
while (string[0] && (count < pos))
|
||||
{
|
||||
next_char = utf8_next_char (string);
|
||||
real_pos += (next_char - string);
|
||||
string = next_char;
|
||||
count++;
|
||||
}
|
||||
return real_pos;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_pos: get position in UTF-8
|
||||
* for example: ("aébc", 3) returns 2
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_pos (char *string, int real_pos)
|
||||
{
|
||||
int count;
|
||||
char *limit;
|
||||
|
||||
if (!string || !local_charset)
|
||||
return real_pos;
|
||||
|
||||
count = 0;
|
||||
limit = string + real_pos;
|
||||
while (string[0] && (string < limit))
|
||||
{
|
||||
string = utf8_next_char (string);
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __WEECHAT_UTF8_H
|
||||
#define __WEECHAT_UTF8_H 1
|
||||
|
||||
extern int local_utf8;
|
||||
|
||||
extern void utf8_init ();
|
||||
extern int utf8_is_valid (char *);
|
||||
extern char *utf8_prev_char (char *, char *);
|
||||
extern char *utf8_next_char (char *);
|
||||
extern int utf8_char_size (char *);
|
||||
extern int utf8_strlen (char *);
|
||||
extern int utf8_strnlen (char *, int);
|
||||
extern char *utf8_add_offset (char *, int);
|
||||
extern int utf8_real_pos (char *, int);
|
||||
extern int utf8_pos (char *, int);
|
||||
|
||||
#endif /* utf8.h */
|
||||
@@ -64,6 +64,7 @@
|
||||
#include "weeconfig.h"
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@@ -413,7 +414,8 @@ void wee_display_key_functions ()
|
||||
* wee_display_keys: display WeeChat default keys
|
||||
*/
|
||||
|
||||
void wee_display_keys ()
|
||||
void
|
||||
wee_display_keys ()
|
||||
{
|
||||
t_gui_key *ptr_key;
|
||||
char *expanded_name;
|
||||
@@ -879,6 +881,7 @@ main (int argc, char *argv[])
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
utf8_init (); /* init UTF-8 in WeeChat */
|
||||
gui_init (); /* init WeeChat interface */
|
||||
weechat_welcome_message (); /* display WeeChat welcome message */
|
||||
#ifdef PLUGINS
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "command.h"
|
||||
#include "fifo.h"
|
||||
#include "log.h"
|
||||
#include "utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
#include "../gui/gui.h"
|
||||
|
||||
@@ -67,7 +68,8 @@ int cfg_look_set_title;
|
||||
int cfg_look_startup_logo;
|
||||
int cfg_look_startup_version;
|
||||
char *cfg_look_weechat_slogan;
|
||||
char *cfg_look_charset_decode;
|
||||
char *cfg_look_charset_decode_iso;
|
||||
char *cfg_look_charset_decode_utf;
|
||||
char *cfg_look_charset_encode;
|
||||
char *cfg_look_charset_internal;
|
||||
char *cfg_look_buffer_timestamp;
|
||||
@@ -112,18 +114,24 @@ t_config_option weechat_options_look[] =
|
||||
N_("WeeChat slogan (if empty, slogan is not used)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"the geekest IRC client!", NULL, NULL, &cfg_look_weechat_slogan, config_change_noop },
|
||||
{ "look_charset_decode", N_("charset for decoding messages from server"),
|
||||
N_("charset for decoding messages from server, examples: UTF-8, ISO-8859-1 (if empty, messages are not converted)"),
|
||||
{ "look_charset_decode_iso", N_("ISO charset for decoding messages from server (used only if locale is UTF-8)"),
|
||||
N_("ISO charset for decoding messages from server (used only if locale is UTF-8) "
|
||||
"(if empty, messages are not converted if locale is UTF-8"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"UTF-8", NULL, NULL, &cfg_look_charset_decode, config_change_buffer_content },
|
||||
"ISO-8859-1", NULL, NULL, &cfg_look_charset_decode_iso, config_change_charset },
|
||||
{ "look_charset_decode_utf", N_("UTF charset for decoding messages from server (used only if locale is not UTF-8)"),
|
||||
N_("UTF charset for decoding messages from server (used only if locale is not UTF-8) "
|
||||
"(if empty, messages are not converted if locale is not UTF-8"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"UTF-8", NULL, NULL, &cfg_look_charset_decode_utf, config_change_charset },
|
||||
{ "look_charset_encode", N_("charset for encoding messages sent to server"),
|
||||
N_("charset for encoding messages sent to server, examples: UFT-8, ISO-8859-1 (if empty, local charset is used)"),
|
||||
N_("charset for encoding messages sent to server, examples: UFT-8, ISO-8859-1 (if empty, messages are not converted)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"", NULL, NULL, &cfg_look_charset_encode, config_change_buffer_content },
|
||||
{ "look_charset_internal", N_("internal WeeChat charset (should be ISO)"),
|
||||
N_("internal WeeChat charset, should be ISO-xxxx even if locale is UTF-8 (if empty, local charset is used)"),
|
||||
"", NULL, NULL, &cfg_look_charset_encode, config_change_charset },
|
||||
{ "look_charset_internal", N_("forces internal WeeChat charset (should be empty in most cases)"),
|
||||
N_("forces internal WeeChat charset (should be empty in most cases, that means detected charset is used)"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
"ISO-8859-1", NULL, NULL, &cfg_look_charset_internal, config_change_buffer_content },
|
||||
"", NULL, NULL, &cfg_look_charset_internal, config_change_charset },
|
||||
{ "look_buffer_timestamp", N_("timestamp for buffers"),
|
||||
N_("timestamp for buffers"),
|
||||
OPTION_TYPE_STRING, 0, 0, 0,
|
||||
@@ -972,6 +980,17 @@ config_change_buffer_content ()
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_change_charset: called when charset changes
|
||||
*/
|
||||
|
||||
void
|
||||
config_change_charset ()
|
||||
{
|
||||
utf8_init ();
|
||||
gui_redraw_buffer (gui_current_window->buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* config_change_color: called when a color is changed by /set command
|
||||
*/
|
||||
|
||||
@@ -83,7 +83,8 @@ extern int cfg_look_set_title;
|
||||
extern int cfg_look_startup_logo;
|
||||
extern int cfg_look_startup_version;
|
||||
extern char *cfg_look_weechat_slogan;
|
||||
extern char *cfg_look_charset_decode;
|
||||
extern char *cfg_look_charset_decode_iso;
|
||||
extern char *cfg_look_charset_decode_utf;
|
||||
extern char *cfg_look_charset_encode;
|
||||
extern char *cfg_look_charset_internal;
|
||||
extern char *cfg_look_buffer_timestamp;
|
||||
@@ -217,6 +218,7 @@ extern void config_change_noop ();
|
||||
extern void config_change_title ();
|
||||
extern void config_change_buffers ();
|
||||
extern void config_change_buffer_content ();
|
||||
extern void config_change_charset ();
|
||||
extern void config_change_color ();
|
||||
extern void config_change_nicks_colors ();
|
||||
extern void config_change_away_check ();
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "../../common/weeconfig.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/log.h"
|
||||
#include "../../common/utf8.h"
|
||||
#include "../../irc/irc.h"
|
||||
|
||||
|
||||
@@ -352,7 +353,8 @@ gui_draw_buffer_title (t_gui_buffer *buffer, int erase)
|
||||
{
|
||||
if (CHANNEL(buffer)->topic)
|
||||
{
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
CHANNEL(buffer)->topic);
|
||||
@@ -413,7 +415,8 @@ gui_message_get_next_char (t_gui_message **message, int *offset)
|
||||
{
|
||||
if (!(*message))
|
||||
return;
|
||||
(*offset)++;
|
||||
|
||||
(*offset) += utf8_char_size ((*message)->message + (*offset));
|
||||
if (!((*message)->message[*offset]))
|
||||
{
|
||||
*message = (*message)->next_message;
|
||||
@@ -433,7 +436,7 @@ gui_display_word (t_gui_window *window, t_gui_line *line,
|
||||
{
|
||||
char format_align[32];
|
||||
char saved_char_end, saved_char;
|
||||
int end_of_word, chars_to_display, num_displayed;
|
||||
int pos_saved_char, end_of_word, chars_to_display, num_displayed;
|
||||
|
||||
if (!message || !end_msg ||
|
||||
((!simulate) && (window->win_chat_cursor_y > window->win_chat_height - 1)))
|
||||
@@ -470,22 +473,23 @@ gui_display_word (t_gui_window *window, t_gui_line *line,
|
||||
window->win_chat_cursor_x += line->length_align;
|
||||
}
|
||||
|
||||
chars_to_display = strlen (message->message + offset);
|
||||
chars_to_display = utf8_strlen (message->message + offset);
|
||||
|
||||
/* too long for current line */
|
||||
if (window->win_chat_cursor_x + chars_to_display > window->win_chat_width)
|
||||
{
|
||||
num_displayed = window->win_chat_width - window->win_chat_cursor_x;
|
||||
saved_char = message->message[offset + num_displayed];
|
||||
message->message[offset + num_displayed] = '\0';
|
||||
pos_saved_char = utf8_real_pos (message->message + offset, num_displayed);
|
||||
saved_char = message->message[offset + pos_saved_char];
|
||||
message->message[offset + pos_saved_char] = '\0';
|
||||
if ((!simulate) &&
|
||||
((count == 0) || (*lines_displayed >= num_lines - count)))
|
||||
mvwprintw (window->win_chat,
|
||||
window->win_chat_cursor_y,
|
||||
window->win_chat_cursor_x,
|
||||
"%s", message->message + offset);
|
||||
message->message[offset + num_displayed] = saved_char;
|
||||
offset += num_displayed;
|
||||
message->message[offset + pos_saved_char] = saved_char;
|
||||
offset += pos_saved_char;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -498,10 +502,15 @@ gui_display_word (t_gui_window *window, t_gui_line *line,
|
||||
"%s", message->message + offset);
|
||||
if (message == end_msg)
|
||||
{
|
||||
offset = end_offset;
|
||||
if (end_msg)
|
||||
end_msg->message[end_offset + 1] = saved_char_end;
|
||||
gui_message_get_next_char (&message, &offset);
|
||||
if (saved_char_end == '\0')
|
||||
{
|
||||
message = message->next_message;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
offset = end_offset + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -564,9 +573,9 @@ gui_get_word_info (t_gui_message *message, int offset,
|
||||
while (message && (message->message[offset]) && (message->message[offset] != ' '))
|
||||
{
|
||||
*word_end_msg = message;
|
||||
*word_end_offset = offset;
|
||||
(*word_length_with_spaces)++;
|
||||
(*word_length)++;
|
||||
*word_end_offset = offset + utf8_char_size (message->message + offset) - 1;
|
||||
(*word_length_with_spaces) += utf8_char_size (message->message + offset);
|
||||
(*word_length) += utf8_char_size (message->message + offset);
|
||||
gui_message_get_next_char (&message, &offset);
|
||||
}
|
||||
}
|
||||
@@ -831,7 +840,8 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
mvwprintw (ptr_win->win_chat, i, 0, "%s %-16s ",
|
||||
(ptr_dcc == dcc_selected) ? "***" : " ",
|
||||
ptr_dcc->nick);
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
(DCC_IS_CHAT(ptr_dcc->type)) ?
|
||||
@@ -854,7 +864,8 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
(DCC_IS_RECV(ptr_dcc->type)) ? "-->>" : "<<--");
|
||||
gui_window_set_color (ptr_win->win_chat,
|
||||
COLOR_DCC_WAITING + ptr_dcc->status);
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_(dcc_status_string[ptr_dcc->status]));
|
||||
@@ -905,7 +916,8 @@ gui_draw_buffer_chat (t_gui_buffer *buffer, int erase)
|
||||
else
|
||||
num_unit = 3;
|
||||
sprintf (format, " (%s %%s/s)", unit_format[num_unit]);
|
||||
buf = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
unit_name[num_unit]);
|
||||
@@ -1248,7 +1260,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
wprintw (ptr_win->win_status, "%s", SERVER(ptr_win->buffer)->name);
|
||||
if (SERVER(ptr_win->buffer)->is_away)
|
||||
{
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("(away)"));
|
||||
@@ -1365,7 +1378,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
wprintw (ptr_win->win_status, "<DCC> ");
|
||||
else
|
||||
{
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("[not connected]"));
|
||||
@@ -1381,7 +1395,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
COLOR_WIN_STATUS_DELIMITERS);
|
||||
wprintw (ptr_win->win_status, "[");
|
||||
gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS);
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("Act: "));
|
||||
@@ -1474,7 +1489,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
COLOR_WIN_STATUS_DELIMITERS);
|
||||
wprintw (ptr_win->win_status, "[");
|
||||
gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS);
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("Lag: %.1f"));
|
||||
@@ -1495,7 +1511,8 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase)
|
||||
}
|
||||
else
|
||||
x = ptr_win->win_width - 2;
|
||||
string = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
string = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
_("-MORE-"));
|
||||
@@ -1712,7 +1729,7 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
}
|
||||
else if (buffer->has_input)
|
||||
{
|
||||
if (buffer->input_buffer_size == 0)
|
||||
if (buffer->input_buffer_length == 0)
|
||||
buffer->input_buffer[0] = '\0';
|
||||
|
||||
input_width = gui_get_input_width (ptr_win);
|
||||
@@ -1750,7 +1767,8 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
snprintf (format, 32, "%%-%ds", input_width);
|
||||
if (ptr_win == gui_current_window)
|
||||
wprintw (ptr_win->win_input, format,
|
||||
buffer->input_buffer + buffer->input_buffer_1st_display);
|
||||
utf8_add_offset (buffer->input_buffer,
|
||||
buffer->input_buffer_1st_display));
|
||||
else
|
||||
wprintw (ptr_win->win_input, format,
|
||||
"");
|
||||
@@ -1776,7 +1794,8 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
snprintf (format, 32, "%%-%ds", input_width);
|
||||
if (ptr_win == gui_current_window)
|
||||
wprintw (ptr_win->win_input, format,
|
||||
buffer->input_buffer + buffer->input_buffer_1st_display);
|
||||
utf8_add_offset (buffer->input_buffer,
|
||||
buffer->input_buffer_1st_display));
|
||||
else
|
||||
wprintw (ptr_win->win_input, format,
|
||||
"");
|
||||
@@ -1789,7 +1808,8 @@ gui_draw_buffer_input (t_gui_buffer *buffer, int erase)
|
||||
}
|
||||
}
|
||||
|
||||
wnoutrefresh (ptr_win->win_input);
|
||||
doupdate ();
|
||||
wrefresh (ptr_win->win_input);
|
||||
refresh ();
|
||||
}
|
||||
}
|
||||
@@ -2713,7 +2733,7 @@ gui_add_message (t_gui_buffer *buffer, int type, int color, char *message)
|
||||
ptr_string[0] = 32;
|
||||
ptr_string++;
|
||||
}
|
||||
length = strlen (message);
|
||||
length = utf8_strlen (message);
|
||||
buffer->last_line->length += length;
|
||||
if (type & MSG_TYPE_MSG)
|
||||
buffer->last_line->line_with_message = 1;
|
||||
@@ -2836,10 +2856,14 @@ gui_printf_internal (t_gui_buffer *buffer, int display_time, int type, int color
|
||||
else
|
||||
buf2 = strdup (buf);
|
||||
|
||||
buf3 = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
buf2);
|
||||
if (!local_utf8 || !utf8_is_valid (buf2))
|
||||
buf3 = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
buf2);
|
||||
else
|
||||
buf3 = strdup (buf2);
|
||||
|
||||
if (gui_init_ok)
|
||||
{
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "../../common/command.h"
|
||||
#include "../../common/hotlist.h"
|
||||
#include "../../common/fifo.h"
|
||||
#include "../../common/utf8.h"
|
||||
#include "../../irc/irc.h"
|
||||
|
||||
|
||||
@@ -163,7 +164,7 @@ gui_input_grab_end ()
|
||||
void
|
||||
gui_input_read ()
|
||||
{
|
||||
int key, i;
|
||||
int key, i, insert_ok;
|
||||
char key_str[32];
|
||||
|
||||
i = 0;
|
||||
@@ -175,6 +176,7 @@ gui_input_read ()
|
||||
gui_input_grab_end ();
|
||||
|
||||
key = getch ();
|
||||
insert_ok = 1;
|
||||
|
||||
if (key == ERR)
|
||||
{
|
||||
@@ -191,6 +193,7 @@ gui_input_read ()
|
||||
|
||||
if (key < 32)
|
||||
{
|
||||
insert_ok = 0;
|
||||
key_str[0] = '^';
|
||||
key_str[1] = (char) key + '@';
|
||||
key_str[2] = '\0';
|
||||
@@ -203,11 +206,38 @@ gui_input_read ()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (key > 0xff)
|
||||
if (local_utf8)
|
||||
{
|
||||
key_str[0] = (char) (key >> 8);
|
||||
key_str[1] = (char) (key & 0xff);
|
||||
key_str[2] = '\0';
|
||||
/* 1 char: 0vvvvvvv */
|
||||
if (key < 0x80)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = '\0';
|
||||
}
|
||||
/* 2 chars: 110vvvvv 10vvvvvv */
|
||||
else if ((key & 0xE0) == 0xC0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = (char) (getch ());
|
||||
key_str[2] = '\0';
|
||||
}
|
||||
/* 3 chars: 1110vvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF0) == 0xE0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = (char) (getch ());
|
||||
key_str[2] = (char) (getch ());
|
||||
key_str[3] = '\0';
|
||||
}
|
||||
/* 4 chars: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
|
||||
else if ((key & 0xF8) == 0xF0)
|
||||
{
|
||||
key_str[0] = (char) key;
|
||||
key_str[1] = (char) (getch ());
|
||||
key_str[2] = (char) (getch ());
|
||||
key_str[3] = (char) (getch ());
|
||||
key_str[4] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -224,8 +254,13 @@ gui_input_read ()
|
||||
|
||||
/*gui_printf (gui_current_window->buffer, "gui_input_read: key = %s (%d)\n", key_str, key);*/
|
||||
|
||||
if (gui_key_pressed (key_str) != 0)
|
||||
gui_input_insert_char (gui_current_window, key);
|
||||
if ((gui_key_pressed (key_str) != 0) && (insert_ok))
|
||||
{
|
||||
gui_input_insert_string (gui_current_window, key_str, -1);
|
||||
gui_current_window->buffer->input_buffer_pos += utf8_strlen (key_str);
|
||||
gui_draw_buffer_input (gui_current_window->buffer, 0);
|
||||
gui_current_window->buffer->completion.position = -1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
+335
-273
@@ -39,6 +39,7 @@
|
||||
#include "../common/history.h"
|
||||
#include "../common/hotlist.h"
|
||||
#include "../common/log.h"
|
||||
#include "../common/utf8.h"
|
||||
#include "../irc/irc.h"
|
||||
|
||||
|
||||
@@ -214,6 +215,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int dcc,
|
||||
else
|
||||
new_buffer->input_buffer = NULL;
|
||||
new_buffer->input_buffer_size = 0;
|
||||
new_buffer->input_buffer_length = 0;
|
||||
new_buffer->input_buffer_pos = 0;
|
||||
new_buffer->input_buffer_1st_display = 0;
|
||||
|
||||
@@ -324,7 +326,8 @@ gui_infobar_printf (int time_displayed, int color, char *message, ...)
|
||||
vsnprintf (buffer, sizeof (buffer) - 1, message, argptr);
|
||||
va_end (argptr);
|
||||
|
||||
buf2 = weechat_convert_encoding (cfg_look_charset_decode,
|
||||
buf2 = weechat_convert_encoding ((local_utf8) ?
|
||||
cfg_look_charset_decode_iso : cfg_look_charset_decode_utf,
|
||||
(cfg_look_charset_internal && cfg_look_charset_internal[0]) ?
|
||||
cfg_look_charset_internal : local_charset,
|
||||
buffer);
|
||||
@@ -604,6 +607,130 @@ gui_input_optimize_buffer_size (t_gui_buffer *buffer)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_action_dcc: execute an action on a DCC after a user input
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_action_dcc (t_gui_window *window, char action)
|
||||
{
|
||||
t_irc_dcc *dcc_selected, *ptr_dcc, *ptr_dcc_next;
|
||||
|
||||
dcc_selected = (window->dcc_selected) ?
|
||||
(t_irc_dcc *) window->dcc_selected : dcc_list;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
/* accept DCC */
|
||||
case 'a':
|
||||
case 'A':
|
||||
if (dcc_selected
|
||||
&& (DCC_IS_RECV(dcc_selected->status))
|
||||
&& (dcc_selected->status == DCC_WAITING))
|
||||
{
|
||||
dcc_accept (dcc_selected);
|
||||
}
|
||||
break;
|
||||
/* cancel DCC */
|
||||
case 'c':
|
||||
case 'C':
|
||||
if (dcc_selected
|
||||
&& (!DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
dcc_close (dcc_selected, DCC_ABORTED);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
/* purge old DCC */
|
||||
case 'p':
|
||||
case 'P':
|
||||
window->dcc_selected = NULL;
|
||||
ptr_dcc = dcc_list;
|
||||
while (ptr_dcc)
|
||||
{
|
||||
ptr_dcc_next = ptr_dcc->next_dcc;
|
||||
if (DCC_ENDED(ptr_dcc->status))
|
||||
dcc_free (ptr_dcc);
|
||||
ptr_dcc = ptr_dcc_next;
|
||||
}
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* close DCC window */
|
||||
case 'q':
|
||||
case 'Q':
|
||||
if (buffer_before_dcc)
|
||||
{
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_switch_to_buffer (window, buffer_before_dcc);
|
||||
}
|
||||
else
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* remove from DCC list */
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (dcc_selected
|
||||
&& (DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
if (dcc_selected->next_dcc)
|
||||
window->dcc_selected = dcc_selected->next_dcc;
|
||||
else
|
||||
window->dcc_selected = NULL;
|
||||
dcc_free (dcc_selected);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_insert_string: insert a string into the input buffer
|
||||
* if pos == -1, string is inserted at cursor position
|
||||
* return: number of chars inserted
|
||||
* (may be different of strlen if UTF-8 string)
|
||||
*/
|
||||
|
||||
int
|
||||
gui_input_insert_string (t_gui_window *window, char *string, int pos)
|
||||
{
|
||||
int size, length;
|
||||
char *ptr_start;
|
||||
|
||||
if (window->buffer->dcc)
|
||||
{
|
||||
while (string[0])
|
||||
{
|
||||
if (string[0] >= 32)
|
||||
gui_input_action_dcc (window, string[0]);
|
||||
string = utf8_next_char (string);
|
||||
}
|
||||
}
|
||||
else if (window->buffer->has_input)
|
||||
{
|
||||
if (pos == -1)
|
||||
pos = window->buffer->input_buffer_pos;
|
||||
|
||||
size = strlen (string);
|
||||
length = utf8_strlen (string);
|
||||
|
||||
/* increase buffer size */
|
||||
window->buffer->input_buffer_size += size;
|
||||
window->buffer->input_buffer_length += length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
|
||||
/* move end of string to the right */
|
||||
ptr_start = utf8_add_offset (window->buffer->input_buffer, pos);
|
||||
memmove (ptr_start + size, ptr_start, strlen (ptr_start));
|
||||
|
||||
/* insert new string */
|
||||
strncpy (utf8_add_offset (window->buffer->input_buffer, pos), string, size);
|
||||
return length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_clipboard_copy: copy string into clipboard
|
||||
*/
|
||||
@@ -615,13 +742,13 @@ gui_input_clipboard_copy (char *buffer, int size)
|
||||
return;
|
||||
|
||||
if (gui_input_clipboard != NULL)
|
||||
free(gui_input_clipboard);
|
||||
free (gui_input_clipboard);
|
||||
|
||||
gui_input_clipboard = (char *) malloc( (size + 1) * sizeof(*gui_input_clipboard));
|
||||
|
||||
if (gui_input_clipboard)
|
||||
{
|
||||
memcpy(gui_input_clipboard, buffer, size);
|
||||
memcpy (gui_input_clipboard, buffer, size);
|
||||
gui_input_clipboard[size] = '\0';
|
||||
}
|
||||
}
|
||||
@@ -635,138 +762,8 @@ gui_input_clipboard_paste (t_gui_window *window)
|
||||
{
|
||||
if (window->buffer->has_input && gui_input_clipboard)
|
||||
{
|
||||
gui_input_insert_string (window, gui_input_clipboard, window->buffer->input_buffer_pos);
|
||||
window->buffer->input_buffer_pos += strlen (gui_input_clipboard);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_insert_string: insert a string into the input buffer
|
||||
* if pos == -1, string is inserted at cursor position
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_insert_string (t_gui_window *window, char *string, int pos)
|
||||
{
|
||||
int i, start, end, length;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (pos == -1)
|
||||
pos = window->buffer->input_buffer_pos;
|
||||
|
||||
length = strlen (string);
|
||||
|
||||
/* increase buffer size */
|
||||
window->buffer->input_buffer_size += length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
|
||||
/* move end of string to the right */
|
||||
start = pos + length;
|
||||
end = window->buffer->input_buffer_size - 1;
|
||||
for (i = end; i >= start; i--)
|
||||
window->buffer->input_buffer[i] =
|
||||
window->buffer->input_buffer[i - length];
|
||||
|
||||
/* insert new string */
|
||||
strncpy (window->buffer->input_buffer + pos, string, length);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_input_insert_char: insert a char into input buffer
|
||||
*/
|
||||
|
||||
void
|
||||
gui_input_insert_char (t_gui_window *window, int key)
|
||||
{
|
||||
char new_char[3];
|
||||
t_irc_dcc *dcc_selected, *ptr_dcc, *ptr_dcc_next;
|
||||
|
||||
if (key < 32)
|
||||
return;
|
||||
|
||||
if (window->buffer->dcc)
|
||||
{
|
||||
dcc_selected = (window->dcc_selected) ?
|
||||
(t_irc_dcc *) window->dcc_selected : dcc_list;
|
||||
switch (key)
|
||||
{
|
||||
/* accept DCC */
|
||||
case 'a':
|
||||
case 'A':
|
||||
if (dcc_selected
|
||||
&& (DCC_IS_RECV(dcc_selected->status))
|
||||
&& (dcc_selected->status == DCC_WAITING))
|
||||
{
|
||||
dcc_accept (dcc_selected);
|
||||
}
|
||||
break;
|
||||
/* cancel DCC */
|
||||
case 'c':
|
||||
case 'C':
|
||||
if (dcc_selected
|
||||
&& (!DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
dcc_close (dcc_selected, DCC_ABORTED);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
/* purge old DCC */
|
||||
case 'p':
|
||||
case 'P':
|
||||
window->dcc_selected = NULL;
|
||||
ptr_dcc = dcc_list;
|
||||
while (ptr_dcc)
|
||||
{
|
||||
ptr_dcc_next = ptr_dcc->next_dcc;
|
||||
if (DCC_ENDED(ptr_dcc->status))
|
||||
dcc_free (ptr_dcc);
|
||||
ptr_dcc = ptr_dcc_next;
|
||||
}
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* close DCC window */
|
||||
case 'q':
|
||||
case 'Q':
|
||||
if (buffer_before_dcc)
|
||||
{
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_switch_to_buffer (window, buffer_before_dcc);
|
||||
}
|
||||
else
|
||||
gui_buffer_free (window->buffer, 1);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
break;
|
||||
/* remove from DCC list */
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (dcc_selected
|
||||
&& (DCC_ENDED(dcc_selected->status)))
|
||||
{
|
||||
if (dcc_selected->next_dcc)
|
||||
window->dcc_selected = dcc_selected->next_dcc;
|
||||
else
|
||||
window->dcc_selected = NULL;
|
||||
dcc_free (dcc_selected);
|
||||
gui_redraw_buffer (window->buffer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (window->buffer->has_input)
|
||||
{
|
||||
/*gui_printf (window->buffer,
|
||||
"[Debug] key pressed = %d, hex = %02X, octal = %o\n", key, key, key);*/
|
||||
new_char[0] = key;
|
||||
new_char[1] = '\0';
|
||||
|
||||
gui_input_insert_string (window, new_char,
|
||||
window->buffer->input_buffer_pos);
|
||||
window->buffer->input_buffer_pos++;
|
||||
gui_input_insert_string (window, gui_input_clipboard, -1);
|
||||
window->buffer->input_buffer_pos += utf8_strlen (gui_input_clipboard);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
@@ -788,6 +785,7 @@ gui_input_return (t_gui_window *window)
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
history_add (window->buffer, window->buffer->input_buffer);
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
window->buffer->input_buffer_1st_display = 0;
|
||||
window->buffer->completion.position = -1;
|
||||
@@ -820,7 +818,8 @@ gui_input_tab (t_gui_window *window)
|
||||
CHANNEL(window->buffer),
|
||||
window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_size,
|
||||
window->buffer->input_buffer_pos);
|
||||
utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos));
|
||||
|
||||
if (window->buffer->completion.word_found)
|
||||
{
|
||||
@@ -829,6 +828,8 @@ gui_input_tab (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer_size +=
|
||||
window->buffer->completion.diff_size;
|
||||
window->buffer->input_buffer_length +=
|
||||
window->buffer->completion.diff_length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
for (i = window->buffer->input_buffer_size - 1;
|
||||
@@ -846,28 +847,33 @@ gui_input_tab (t_gui_window *window)
|
||||
window->buffer->input_buffer[i - window->buffer->completion.diff_size];
|
||||
window->buffer->input_buffer_size +=
|
||||
window->buffer->completion.diff_size;
|
||||
window->buffer->input_buffer_length +=
|
||||
window->buffer->completion.diff_length;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
}
|
||||
|
||||
|
||||
strncpy (window->buffer->input_buffer + window->buffer->completion.position_replace,
|
||||
window->buffer->completion.word_found,
|
||||
strlen (window->buffer->completion.word_found));
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->completion.position_replace +
|
||||
strlen (window->buffer->completion.word_found);
|
||||
utf8_pos (window->buffer->input_buffer,
|
||||
window->buffer->completion.position_replace) +
|
||||
utf8_strlen (window->buffer->completion.word_found);
|
||||
|
||||
/* position is < 0 this means only one word was found to complete,
|
||||
so reinit to stop completion */
|
||||
if (window->buffer->completion.position >= 0)
|
||||
window->buffer->completion.position =
|
||||
window->buffer->input_buffer_pos;
|
||||
utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
|
||||
/* add space or completor to the end of completion, if needed */
|
||||
if ((window->buffer->completion.context == COMPLETION_COMMAND)
|
||||
|| (window->buffer->completion.context == COMPLETION_COMMAND_ARG))
|
||||
{
|
||||
if (window->buffer->input_buffer[window->buffer->input_buffer_pos] != ' ')
|
||||
if (window->buffer->input_buffer[utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos)] != ' ')
|
||||
gui_input_insert_string (window, " ",
|
||||
window->buffer->input_buffer_pos);
|
||||
if (window->buffer->completion.position >= 0)
|
||||
@@ -880,14 +886,16 @@ gui_input_tab (t_gui_window *window)
|
||||
if ((window->buffer->completion.base_word_pos == 0)
|
||||
&& (window->buffer->completion.context == COMPLETION_NICK))
|
||||
{
|
||||
if (strncmp (window->buffer->input_buffer + window->buffer->input_buffer_pos,
|
||||
if (strncmp (utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos),
|
||||
cfg_look_completor, strlen (cfg_look_completor)) != 0)
|
||||
gui_input_insert_string (window, cfg_look_completor,
|
||||
window->buffer->input_buffer_pos);
|
||||
if (window->buffer->completion.position >= 0)
|
||||
window->buffer->completion.position += strlen (cfg_look_completor);
|
||||
window->buffer->input_buffer_pos += strlen (cfg_look_completor);
|
||||
if (window->buffer->input_buffer[window->buffer->input_buffer_pos] != ' ')
|
||||
window->buffer->input_buffer_pos += utf8_strlen (cfg_look_completor);
|
||||
if (window->buffer->input_buffer[utf8_real_pos (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos)] != ' ')
|
||||
gui_input_insert_string (window, " ",
|
||||
window->buffer->input_buffer_pos);
|
||||
if (window->buffer->completion.position >= 0)
|
||||
@@ -907,24 +915,25 @@ gui_input_tab (t_gui_window *window)
|
||||
void
|
||||
gui_input_backspace (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
char *pos, *pos_last;
|
||||
int char_size, size_to_move;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos-1;
|
||||
while (window->buffer->input_buffer[i])
|
||||
{
|
||||
window->buffer->input_buffer[i] =
|
||||
window->buffer->input_buffer[i+1];
|
||||
i++;
|
||||
}
|
||||
window->buffer->input_buffer_size--;
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
pos_last = utf8_prev_char (window->buffer->input_buffer, pos);
|
||||
char_size = pos - pos_last;
|
||||
size_to_move = strlen (pos);
|
||||
memmove (pos_last, pos, size_to_move);
|
||||
window->buffer->input_buffer_size -= char_size;
|
||||
window->buffer->input_buffer_length--;
|
||||
window->buffer->input_buffer_pos--;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -937,24 +946,25 @@ gui_input_backspace (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
|
||||
char *pos, *pos_next;
|
||||
int char_size, size_to_move;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos;
|
||||
while (window->buffer->input_buffer[i])
|
||||
{
|
||||
window->buffer->input_buffer[i] =
|
||||
window->buffer->input_buffer[i+1];
|
||||
i++;
|
||||
}
|
||||
window->buffer->input_buffer_size--;
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
pos_next = utf8_next_char (pos);
|
||||
char_size = pos_next - pos;
|
||||
size_to_move = strlen (pos_next);
|
||||
memmove (pos, pos_next, size_to_move);
|
||||
window->buffer->input_buffer_size -= char_size;
|
||||
window->buffer->input_buffer_length--;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -967,49 +977,53 @@ gui_input_delete (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_previous_word (t_gui_window *window)
|
||||
{
|
||||
int i, j, num_char_deleted, num_char_end;
|
||||
int length_deleted, size_deleted;
|
||||
char *start, *string;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos - 1;
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i--;
|
||||
if (i >= 0)
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos - 1);
|
||||
string = start;
|
||||
while (string && (string[0] == ' '))
|
||||
{
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] != ' '))
|
||||
i--;
|
||||
if (i >= 0)
|
||||
string = utf8_prev_char (window->buffer->input_buffer, string);
|
||||
}
|
||||
if (string)
|
||||
{
|
||||
while (string && (string[0] != ' '))
|
||||
{
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i--;
|
||||
string = utf8_prev_char (window->buffer->input_buffer, string);
|
||||
}
|
||||
if (string)
|
||||
{
|
||||
while (string && (string[0] == ' '))
|
||||
{
|
||||
string = utf8_prev_char (window->buffer->input_buffer, string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 0)
|
||||
i++;
|
||||
i++;
|
||||
num_char_deleted = window->buffer->input_buffer_pos - i;
|
||||
num_char_end = window->buffer->input_buffer_size -
|
||||
window->buffer->input_buffer_pos;
|
||||
if (string)
|
||||
string = utf8_next_char (utf8_next_char (string));
|
||||
else
|
||||
string = window->buffer->input_buffer;
|
||||
|
||||
gui_input_clipboard_copy(window->buffer->input_buffer +
|
||||
window->buffer->input_buffer_pos - num_char_deleted,
|
||||
num_char_deleted);
|
||||
size_deleted = utf8_next_char (start) - string;
|
||||
length_deleted = utf8_strnlen (string, size_deleted);
|
||||
|
||||
for (j = 0; j < num_char_end; j++)
|
||||
window->buffer->input_buffer[i + j] =
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_pos + j];
|
||||
gui_input_clipboard_copy (string, size_deleted);
|
||||
|
||||
window->buffer->input_buffer_size -= num_char_deleted;
|
||||
memmove (string, string + size_deleted, size_deleted);
|
||||
|
||||
window->buffer->input_buffer_size -= size_deleted;
|
||||
window->buffer->input_buffer_length -= length_deleted;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
window->buffer->input_buffer_pos = i;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->input_buffer_pos -= length_deleted;
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1022,31 +1036,33 @@ gui_input_delete_previous_word (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_next_word (t_gui_window *window)
|
||||
{
|
||||
int i, j, num_char_deleted;
|
||||
int size_deleted, length_deleted;
|
||||
char *start, *string;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos;
|
||||
while (i < window->buffer->input_buffer_size)
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
string = start;
|
||||
length_deleted = 0;
|
||||
while (string[0])
|
||||
{
|
||||
if ((window->buffer->input_buffer[i] == ' ')
|
||||
&& i != window->buffer->input_buffer_pos)
|
||||
if ((string[0] == ' ') && (string > start))
|
||||
break;
|
||||
i++;
|
||||
string = utf8_next_char (string);
|
||||
length_deleted++;
|
||||
}
|
||||
num_char_deleted = i - window->buffer->input_buffer_pos;
|
||||
size_deleted = string - start;
|
||||
|
||||
gui_input_clipboard_copy(window->buffer->input_buffer +
|
||||
window->buffer->input_buffer_pos, num_char_deleted);
|
||||
gui_input_clipboard_copy(start, size_deleted);
|
||||
|
||||
for (j = i; j < window->buffer->input_buffer_size; j++)
|
||||
window->buffer->input_buffer[j - num_char_deleted] =
|
||||
window->buffer->input_buffer[j];
|
||||
memmove (start, string, strlen (string));
|
||||
|
||||
window->buffer->input_buffer_size -= num_char_deleted;
|
||||
window->buffer->input_buffer_size -= size_deleted;
|
||||
window->buffer->input_buffer_length -= length_deleted;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1058,26 +1074,28 @@ gui_input_delete_next_word (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_begin_of_line (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
int length_deleted, size_deleted;
|
||||
char *start;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
size_deleted = start - window->buffer->input_buffer;
|
||||
length_deleted = utf8_strnlen (window->buffer->input_buffer, size_deleted);
|
||||
gui_input_clipboard_copy (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
start - window->buffer->input_buffer);
|
||||
|
||||
for (i = window->buffer->input_buffer_pos;
|
||||
i < window->buffer->input_buffer_size; i++)
|
||||
window->buffer->input_buffer[i - window->buffer->input_buffer_pos] =
|
||||
window->buffer->input_buffer[i];
|
||||
memmove (window->buffer->input_buffer, start, strlen (start));
|
||||
|
||||
window->buffer->input_buffer_size -=
|
||||
window->buffer->input_buffer_pos;
|
||||
window->buffer->input_buffer_size -= size_deleted;
|
||||
window->buffer->input_buffer_length -= length_deleted;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1090,17 +1108,21 @@ gui_input_delete_begin_of_line (t_gui_window *window)
|
||||
void
|
||||
gui_input_delete_end_of_line (t_gui_window *window)
|
||||
{
|
||||
char *start;
|
||||
int size_deleted, length_deleted;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
gui_input_clipboard_copy(window->buffer->input_buffer +
|
||||
window->buffer->input_buffer_pos,
|
||||
window->buffer->input_buffer_size -
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_pos] = ' ';
|
||||
window->buffer->input_buffer_size = window->buffer->input_buffer_pos ;
|
||||
window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0';
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
size_deleted = strlen (start);
|
||||
length_deleted = utf8_strlen (start);
|
||||
gui_input_clipboard_copy(start, size_deleted);
|
||||
start[0] = '\0';
|
||||
window->buffer->input_buffer_size = strlen (window->buffer->input_buffer);
|
||||
window->buffer->input_buffer_length = utf8_strlen (window->buffer->input_buffer);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1116,9 +1138,10 @@ gui_input_delete_line (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer[0] = '\0';
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
}
|
||||
}
|
||||
@@ -1130,23 +1153,27 @@ gui_input_delete_line (t_gui_window *window)
|
||||
void
|
||||
gui_input_transpose_chars (t_gui_window *window)
|
||||
{
|
||||
char buf;
|
||||
int curpos;
|
||||
char *start, *prev_char, saved_char[4];
|
||||
int size_current_char;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
curpos = window->buffer->input_buffer_pos;
|
||||
if (curpos == window->buffer->input_buffer_size)
|
||||
curpos--;
|
||||
else
|
||||
window->buffer->input_buffer_pos++;
|
||||
if (window->buffer->input_buffer_pos == window->buffer->input_buffer_length)
|
||||
window->buffer->input_buffer_pos--;
|
||||
|
||||
buf = window->buffer->input_buffer[curpos];
|
||||
window->buffer->input_buffer[curpos] =
|
||||
window->buffer->input_buffer[curpos-1];
|
||||
window->buffer->input_buffer[curpos-1] = buf;
|
||||
start = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
prev_char = utf8_prev_char (window->buffer->input_buffer,
|
||||
start);
|
||||
size_current_char = start - prev_char;
|
||||
memcpy (saved_char, prev_char, size_current_char);
|
||||
memcpy (prev_char, start, utf8_char_size (start));
|
||||
start = utf8_next_char (prev_char);
|
||||
memcpy (start, saved_char, size_current_char);
|
||||
|
||||
window->buffer->input_buffer_pos++;
|
||||
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
window->buffer->completion.position = -1;
|
||||
@@ -1181,10 +1208,10 @@ gui_input_end (t_gui_window *window)
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
}
|
||||
}
|
||||
@@ -1214,25 +1241,34 @@ gui_input_left (t_gui_window *window)
|
||||
void
|
||||
gui_input_previous_word (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
char *pos;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos > 0)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos - 1;
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i--;
|
||||
if (i < 0)
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
else
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos - 1);
|
||||
while (pos && (pos[0] == ' '))
|
||||
{
|
||||
while ((i >= 0) &&
|
||||
(window->buffer->input_buffer[i] != ' '))
|
||||
i--;
|
||||
window->buffer->input_buffer_pos = i + 1;
|
||||
pos = utf8_prev_char (window->buffer->input_buffer, pos);
|
||||
}
|
||||
if (pos)
|
||||
{
|
||||
while (pos && (pos[0] != ' '))
|
||||
{
|
||||
pos = utf8_prev_char (window->buffer->input_buffer, pos);
|
||||
}
|
||||
if (pos)
|
||||
pos = utf8_next_char (pos);
|
||||
else
|
||||
pos = window->buffer->input_buffer;
|
||||
window->buffer->input_buffer_pos = utf8_pos (window->buffer->input_buffer,
|
||||
pos - window->buffer->input_buffer);
|
||||
}
|
||||
else
|
||||
window->buffer->input_buffer_pos = 0;
|
||||
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
}
|
||||
}
|
||||
@@ -1248,7 +1284,7 @@ gui_input_right (t_gui_window *window)
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
window->buffer->input_buffer_pos++;
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
@@ -1263,31 +1299,38 @@ gui_input_right (t_gui_window *window)
|
||||
void
|
||||
gui_input_next_word (t_gui_window *window)
|
||||
{
|
||||
int i;
|
||||
char *pos;
|
||||
|
||||
if (window->buffer->has_input)
|
||||
{
|
||||
if (window->buffer->input_buffer_pos <
|
||||
window->buffer->input_buffer_size + 1)
|
||||
window->buffer->input_buffer_length)
|
||||
{
|
||||
i = window->buffer->input_buffer_pos;
|
||||
while ((i <= window->buffer->input_buffer_size) &&
|
||||
(window->buffer->input_buffer[i] == ' '))
|
||||
i++;
|
||||
if (i > window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_pos = i - 1;
|
||||
else
|
||||
pos = utf8_add_offset (window->buffer->input_buffer,
|
||||
window->buffer->input_buffer_pos);
|
||||
while (pos[0] && (pos[0] == ' '))
|
||||
{
|
||||
while ((i <= window->buffer->input_buffer_size) &&
|
||||
(window->buffer->input_buffer[i] != ' '))
|
||||
i++;
|
||||
if (i > window->buffer->input_buffer_size)
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
else
|
||||
window->buffer->input_buffer_pos = i;
|
||||
|
||||
pos = utf8_next_char (pos);
|
||||
}
|
||||
if (pos[0])
|
||||
{
|
||||
while (pos[0] && (pos[0] != ' '))
|
||||
{
|
||||
pos = utf8_next_char (pos);
|
||||
}
|
||||
if (pos[0])
|
||||
window->buffer->input_buffer_pos =
|
||||
utf8_pos (window->buffer->input_buffer,
|
||||
pos - window->buffer->input_buffer);
|
||||
else
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_length;
|
||||
}
|
||||
else
|
||||
window->buffer->input_buffer_pos =
|
||||
utf8_pos (window->buffer->input_buffer,
|
||||
utf8_prev_char (window->buffer->input_buffer, pos) - window->buffer->input_buffer);
|
||||
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
}
|
||||
}
|
||||
@@ -1335,9 +1378,11 @@ gui_input_up (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (window->buffer->ptr_history->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (window->buffer->ptr_history->text);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
strcpy (window->buffer->input_buffer,
|
||||
window->buffer->ptr_history->text);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
@@ -1366,9 +1411,11 @@ gui_input_up_global (t_gui_window *window)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (history_global_ptr->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (history_global_ptr->text);
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
strcpy (window->buffer->input_buffer,
|
||||
history_global_ptr->text);
|
||||
gui_draw_buffer_input (window->buffer, 0);
|
||||
@@ -1419,13 +1466,20 @@ gui_input_down (t_gui_window *window)
|
||||
window->buffer->ptr_history =
|
||||
window->buffer->ptr_history->prev_history;
|
||||
if (window->buffer->ptr_history)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (window->buffer->ptr_history->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (window->buffer->ptr_history->text);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
}
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
if (window->buffer->ptr_history)
|
||||
strcpy (window->buffer->input_buffer,
|
||||
window->buffer->ptr_history->text);
|
||||
@@ -1447,13 +1501,20 @@ gui_input_down_global (t_gui_window *window)
|
||||
{
|
||||
history_global_ptr = history_global_ptr->prev_history;
|
||||
if (history_global_ptr)
|
||||
{
|
||||
window->buffer->input_buffer_size =
|
||||
strlen (history_global_ptr->text);
|
||||
window->buffer->input_buffer_length =
|
||||
utf8_strlen (history_global_ptr->text);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->buffer->input_buffer_size = 0;
|
||||
window->buffer->input_buffer_length = 0;
|
||||
}
|
||||
gui_input_optimize_buffer_size (window->buffer);
|
||||
window->buffer->input_buffer_pos =
|
||||
window->buffer->input_buffer_size;
|
||||
window->buffer->input_buffer_length;
|
||||
if (history_global_ptr)
|
||||
strcpy (window->buffer->input_buffer,
|
||||
history_global_ptr->text);
|
||||
@@ -1916,6 +1977,7 @@ gui_buffer_print_log (t_gui_buffer *buffer)
|
||||
wee_log_printf (" input_buffer . . . . : '%s'\n", buffer->input_buffer);
|
||||
wee_log_printf (" input_buffer_alloc . : %d\n", buffer->input_buffer_alloc);
|
||||
wee_log_printf (" input_buffer_size. . : %d\n", buffer->input_buffer_size);
|
||||
wee_log_printf (" input_buffer_length. : %d\n", buffer->input_buffer_length);
|
||||
wee_log_printf (" input_buffer_pos . . : %d\n", buffer->input_buffer_pos);
|
||||
wee_log_printf (" input_buffer_1st_disp: %d\n", buffer->input_buffer_1st_display);
|
||||
wee_log_printf (" history. . . . . . . : 0x%X\n", buffer->history);
|
||||
|
||||
@@ -196,7 +196,8 @@ struct t_gui_buffer
|
||||
int has_input; /* = 1 if buffer has input (DCC has not)*/
|
||||
char *input_buffer; /* input buffer */
|
||||
int input_buffer_alloc; /* input buffer: allocated size in mem */
|
||||
int input_buffer_size; /* buffer size (user input length) */
|
||||
int input_buffer_size; /* buffer size in bytes */
|
||||
int input_buffer_length; /* number of chars in buffer */
|
||||
int input_buffer_pos; /* position into buffer */
|
||||
int input_buffer_1st_display; /* first char displayed on screen */
|
||||
|
||||
@@ -330,8 +331,7 @@ extern t_gui_line *gui_new_line (t_gui_buffer *);
|
||||
extern t_gui_message *gui_new_message (t_gui_buffer *);
|
||||
extern void gui_input_clipboard_copy (char *, int);
|
||||
extern void gui_input_clipboard_paste (t_gui_window *);
|
||||
extern void gui_input_insert_string (t_gui_window *, char *, int);
|
||||
extern void gui_input_insert_char (t_gui_window *, int);
|
||||
extern int gui_input_insert_string (t_gui_window *, char *, int);
|
||||
extern void gui_input_return (t_gui_window *);
|
||||
extern void gui_input_tab (t_gui_window *);
|
||||
extern void gui_input_backspace (t_gui_window *);
|
||||
|
||||
Reference in New Issue
Block a user