aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
diff options
context:
space:
mode:
authorTomas Heinrich <heinrich.tomas@gmail.com>2010-03-18 18:35:37 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-03-18 18:35:37 +0100
commitc5c006c10c060e7f1a97250d039051b93ed390b2 (patch)
treeb281136c99e6a27a530282a0b1b7eaf938704bb2 /libbb/lineedit.c
parent98f1dc12f1554aca6c3743bec1c3d8982a077f7c (diff)
downloadbusybox-w32-c5c006c10c060e7f1a97250d039051b93ed390b2.tar.gz
busybox-w32-c5c006c10c060e7f1a97250d039051b93ed390b2.tar.bz2
busybox-w32-c5c006c10c060e7f1a97250d039051b93ed390b2.zip
lineedit: first shot at optional unicode bidi input support
function old new delta read_line_input 4886 5003 +117 in_uint16_table - 97 +97 in_interval_table - 78 +78 static.rtl_b - 68 +68 unicode_isrtl - 55 +55 isrtl_str - 51 +51 static.rtl_p - 42 +42 unicode_conv_to_printable2 633 477 -156 ------------------------------------------------------------------------------ (add/remove: 6/0 grow/shrink: 1/1 up/down: 508/-156) Total: 352 bytes Signed-off-by: Tomas Heinrich <heinrich.tomas@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r--libbb/lineedit.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 7c0eef90d..be022e8ae 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1738,6 +1738,18 @@ static int lineedit_read_key(char *read_key_buffer)
1738 return ic; 1738 return ic;
1739} 1739}
1740 1740
1741#if ENABLE_UNICODE_BIDI_SUPPORT
1742static int isrtl_str(void)
1743{
1744 int idx = cursor;
1745 while (command_ps[idx] >= ' ' && command_ps[idx] < 127 && !isalpha(command_ps[idx]))
1746 idx++;
1747 return unicode_isrtl(command_ps[idx]);
1748}
1749#else
1750# define isrtl_str() 0
1751#endif
1752
1741/* leave out the "vi-mode"-only case labels if vi editing isn't 1753/* leave out the "vi-mode"-only case labels if vi editing isn't
1742 * configured. */ 1754 * configured. */
1743#define vi_case(caselabel) IF_FEATURE_EDITING_VI(case caselabel) 1755#define vi_case(caselabel) IF_FEATURE_EDITING_VI(case caselabel)
@@ -1895,10 +1907,9 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
1895 break; 1907 break;
1896 case CTRL('B'): 1908 case CTRL('B'):
1897 vi_case('h'|VI_CMDMODE_BIT:) 1909 vi_case('h'|VI_CMDMODE_BIT:)
1898 vi_case('\b'|VI_CMDMODE_BIT:) 1910 vi_case('\b'|VI_CMDMODE_BIT:) /* ^H */
1899 vi_case('\x7f'|VI_CMDMODE_BIT:) /* DEL */ 1911 vi_case('\x7f'|VI_CMDMODE_BIT:) /* DEL */
1900 /* Control-b -- Move back one character */ 1912 input_backward(1); /* Move back one character */
1901 input_backward(1);
1902 break; 1913 break;
1903 case CTRL('E'): 1914 case CTRL('E'):
1904 vi_case('$'|VI_CMDMODE_BIT:) 1915 vi_case('$'|VI_CMDMODE_BIT:)
@@ -1908,13 +1919,20 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
1908 case CTRL('F'): 1919 case CTRL('F'):
1909 vi_case('l'|VI_CMDMODE_BIT:) 1920 vi_case('l'|VI_CMDMODE_BIT:)
1910 vi_case(' '|VI_CMDMODE_BIT:) 1921 vi_case(' '|VI_CMDMODE_BIT:)
1911 /* Control-f -- Move forward one character */ 1922 input_forward(); /* Move forward one character */
1912 input_forward();
1913 break; 1923 break;
1914 case '\b': 1924 case '\b': /* ^H */
1915 case '\x7f': /* DEL */ 1925 case '\x7f': /* DEL */
1916 /* Control-h and DEL */ 1926 if (!isrtl_str())
1917 input_backspace(); 1927 input_backspace();
1928 else
1929 input_delete(0);
1930 break;
1931 case KEYCODE_DELETE:
1932 if (!isrtl_str())
1933 input_delete(0);
1934 else
1935 input_backspace();
1918 break; 1936 break;
1919#if ENABLE_FEATURE_TAB_COMPLETION 1937#if ENABLE_FEATURE_TAB_COMPLETION
1920 case '\t': 1938 case '\t':
@@ -2137,9 +2155,6 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
2137 case KEYCODE_CTRL_RIGHT: 2155 case KEYCODE_CTRL_RIGHT:
2138 ctrl_right(); 2156 ctrl_right();
2139 break; 2157 break;
2140 case KEYCODE_DELETE:
2141 input_delete(0);
2142 break;
2143 case KEYCODE_HOME: 2158 case KEYCODE_HOME:
2144 input_backward(cursor); 2159 input_backward(cursor);
2145 break; 2160 break;
@@ -2205,14 +2220,19 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
2205 command_ps[cursor] = ic; 2220 command_ps[cursor] = ic;
2206 command_ps[cursor + 1] = BB_NUL; 2221 command_ps[cursor + 1] = BB_NUL;
2207 cmdedit_set_out_char(' '); 2222 cmdedit_set_out_char(' ');
2223 if (unicode_isrtl(ic))
2224 input_backward(1);
2208 } else { 2225 } else {
2209 /* In the middle, insert */ 2226 /* In the middle, insert */
2227 /* is char right-to-left, or "neutral" one (e.g. comma) added to rtl text? */
2228 int rtl = ENABLE_UNICODE_BIDI_SUPPORT ? (unicode_isrtl(ic) || (ic < 127 && !isalpha(ic) && isrtl_str())) : 0;
2210 int sc = cursor; 2229 int sc = cursor;
2211 2230
2212 memmove(command_ps + sc + 1, command_ps + sc, 2231 memmove(command_ps + sc + 1, command_ps + sc,
2213 (command_len - sc) * sizeof(command_ps[0])); 2232 (command_len - sc) * sizeof(command_ps[0]));
2214 command_ps[sc] = ic; 2233 command_ps[sc] = ic;
2215 sc++; 2234 if (!rtl)
2235 sc++;
2216 /* rewrite from cursor */ 2236 /* rewrite from cursor */
2217 input_end(); 2237 input_end();
2218 /* to prev x pos + 1 */ 2238 /* to prev x pos + 1 */