summaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r--libbb/lineedit.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 720a4951e..3d96a8e9f 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -346,7 +346,7 @@ int adjust_width_and_validate_wc(unsigned *width_adj, int wc);
346/* Put 'command_ps[cursor]', cursor++. 346/* Put 'command_ps[cursor]', cursor++.
347 * Advance cursor on screen. If we reached right margin, scroll text up 347 * Advance cursor on screen. If we reached right margin, scroll text up
348 * and remove terminal margin effect by printing 'next_char' */ 348 * and remove terminal margin effect by printing 'next_char' */
349#define HACK_FOR_WRONG_WIDTH 1 349#define HACK_FOR_WRONG_WIDTH 1 && !ENABLE_PLATFORM_MINGW32
350static void put_cur_glyph_and_inc_cursor(void) 350static void put_cur_glyph_and_inc_cursor(void)
351{ 351{
352 CHAR_T c = command_ps[cursor]; 352 CHAR_T c = command_ps[cursor];
@@ -409,6 +409,42 @@ static void put_cur_glyph_and_inc_cursor(void)
409 } 409 }
410} 410}
411 411
412#if ENABLE_PLATFORM_MINGW32
413static void inc_cursor(void)
414{
415 CHAR_T c = command_ps[cursor];
416 unsigned width = 0;
417 int ofs_to_right;
418
419 /* advance cursor */
420 cursor++;
421 if (unicode_status == UNICODE_ON) {
422 IF_UNICODE_WIDE_WCHARS(width = cmdedit_x;)
423 c = adjust_width_and_validate_wc(&cmdedit_x, c);
424 IF_UNICODE_WIDE_WCHARS(width = cmdedit_x - width;)
425 } else {
426 cmdedit_x++;
427 }
428
429 ofs_to_right = cmdedit_x - cmdedit_termw;
430 if (!ENABLE_UNICODE_WIDE_WCHARS || ofs_to_right <= 0) {
431 /* cursor remains on this line */
432 printf(ESC"[1C");
433 }
434
435 if (ofs_to_right >= 0) {
436 /* we go to the next line */
437 printf(ESC"[1B");
438 bb_putchar('\r');
439 cmdedit_y++;
440 if (!ENABLE_UNICODE_WIDE_WCHARS || ofs_to_right == 0) {
441 width = 0;
442 }
443 cmdedit_x = width;
444 }
445}
446#endif
447
412/* Move to end of line (by printing all chars till the end) */ 448/* Move to end of line (by printing all chars till the end) */
413static void put_till_end_and_adv_cursor(void) 449static void put_till_end_and_adv_cursor(void)
414{ 450{
@@ -465,6 +501,7 @@ static void input_backward(unsigned num)
465 501
466 if (cmdedit_x >= num) { 502 if (cmdedit_x >= num) {
467 cmdedit_x -= num; 503 cmdedit_x -= num;
504#if !ENABLE_PLATFORM_MINGW32
468 if (num <= 4) { 505 if (num <= 4) {
469 /* This is longer by 5 bytes on x86. 506 /* This is longer by 5 bytes on x86.
470 * Also gets miscompiled for ARM users 507 * Also gets miscompiled for ARM users
@@ -477,6 +514,7 @@ static void input_backward(unsigned num)
477 } while (--num); 514 } while (--num);
478 return; 515 return;
479 } 516 }
517#endif
480 printf(ESC"[%uD", num); 518 printf(ESC"[%uD", num);
481 return; 519 return;
482 } 520 }
@@ -608,7 +646,11 @@ static void input_backspace(void)
608static void input_forward(void) 646static void input_forward(void)
609{ 647{
610 if (cursor < command_len) 648 if (cursor < command_len)
649#if !ENABLE_PLATFORM_MINGW32
611 put_cur_glyph_and_inc_cursor(); 650 put_cur_glyph_and_inc_cursor();
651#else
652 inc_cursor();
653#endif
612} 654}
613 655
614#if ENABLE_FEATURE_TAB_COMPLETION 656#if ENABLE_FEATURE_TAB_COMPLETION
@@ -719,7 +761,11 @@ static int path_parse(char ***p)
719 tmp = (char*)pth; 761 tmp = (char*)pth;
720 npth = 1; /* path component count */ 762 npth = 1; /* path component count */
721 while (1) { 763 while (1) {
764#if ENABLE_PLATFORM_MINGW32
765 tmp = next_path_sep(tmp);
766#else
722 tmp = strchr(tmp, ':'); 767 tmp = strchr(tmp, ':');
768#endif
723 if (!tmp) 769 if (!tmp)
724 break; 770 break;
725 tmp++; 771 tmp++;
@@ -732,7 +778,11 @@ static int path_parse(char ***p)
732 res[0] = tmp = xstrdup(pth); 778 res[0] = tmp = xstrdup(pth);
733 npth = 1; 779 npth = 1;
734 while (1) { 780 while (1) {
781#if ENABLE_PLATFORM_MINGW32
782 tmp = next_path_sep(tmp);
783#else
735 tmp = strchr(tmp, ':'); 784 tmp = strchr(tmp, ':');
785#endif
736 if (!tmp) 786 if (!tmp)
737 break; 787 break;
738 *tmp++ = '\0'; /* ':' -> '\0' */ 788 *tmp++ = '\0'; /* ':' -> '\0' */
@@ -1886,7 +1936,11 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1886 /* /home/user[/something] -> ~[/something] */ 1936 /* /home/user[/something] -> ~[/something] */
1887 l = strlen(home_pwd_buf); 1937 l = strlen(home_pwd_buf);
1888 if (l != 0 1938 if (l != 0
1939#if !ENABLE_PLATFORM_MINGW32
1889 && strncmp(home_pwd_buf, cwd_buf, l) == 0 1940 && strncmp(home_pwd_buf, cwd_buf, l) == 0
1941#else
1942 && strncasecmp(home_pwd_buf, cwd_buf, l) == 0
1943#endif
1890 && (cwd_buf[l] == '/' || cwd_buf[l] == '\0') 1944 && (cwd_buf[l] == '/' || cwd_buf[l] == '\0')
1891 ) { 1945 ) {
1892 cwd_buf[0] = '~'; 1946 cwd_buf[0] = '~';
@@ -2255,9 +2309,16 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2255 2309
2256 INIT_S(); 2310 INIT_S();
2257 2311
2312#if ENABLE_PLATFORM_MINGW32
2313 memset(initial_settings.c_cc, sizeof(initial_settings.c_cc), 0);
2314 initial_settings.c_cc[VINTR] = CTRL('C');
2315 initial_settings.c_cc[VEOF] = CTRL('D');
2316 if (!isatty(0) || !isatty(1)) {
2317#else
2258 if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 2318 if (tcgetattr(STDIN_FILENO, &initial_settings) < 0
2259 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON 2319 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON
2260 ) { 2320 ) {
2321#endif
2261 /* Happens when e.g. stty -echo was run before. 2322 /* Happens when e.g. stty -echo was run before.
2262 * But if ICANON is not set, we don't come here. 2323 * But if ICANON is not set, we don't come here.
2263 * (example: interactive python ^Z-backgrounded, 2324 * (example: interactive python ^Z-backgrounded,
@@ -2611,7 +2672,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2611 * standard readline bindings (IOW: bash) do. 2672 * standard readline bindings (IOW: bash) do.
2612 * Often, Alt-<key> generates ESC-<key>. 2673 * Often, Alt-<key> generates ESC-<key>.
2613 */ 2674 */
2614 ic = lineedit_read_key(read_key_buffer, 50); 2675 ic = lineedit_read_key(read_key_buffer, 20);
2615 switch (ic) { 2676 switch (ic) {
2616 //case KEYCODE_LEFT: - bash doesn't do this 2677 //case KEYCODE_LEFT: - bash doesn't do this
2617 case 'b': 2678 case 'b':