diff options
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index e5721b063..051a39b2e 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -354,7 +354,7 @@ int adjust_width_and_validate_wc(unsigned *width_adj, int wc); | |||
354 | /* Put 'command_ps[cursor]', cursor++. | 354 | /* Put 'command_ps[cursor]', cursor++. |
355 | * Advance cursor on screen. If we reached right margin, scroll text up | 355 | * Advance cursor on screen. If we reached right margin, scroll text up |
356 | * and remove terminal margin effect by printing 'next_char' */ | 356 | * and remove terminal margin effect by printing 'next_char' */ |
357 | #define HACK_FOR_WRONG_WIDTH 1 | 357 | #define HACK_FOR_WRONG_WIDTH 1 && !ENABLE_PLATFORM_MINGW32 |
358 | static void put_cur_glyph_and_inc_cursor(void) | 358 | static void put_cur_glyph_and_inc_cursor(void) |
359 | { | 359 | { |
360 | CHAR_T c = command_ps[cursor]; | 360 | CHAR_T c = command_ps[cursor]; |
@@ -417,6 +417,42 @@ static void put_cur_glyph_and_inc_cursor(void) | |||
417 | } | 417 | } |
418 | } | 418 | } |
419 | 419 | ||
420 | #if ENABLE_PLATFORM_MINGW32 | ||
421 | static void inc_cursor(void) | ||
422 | { | ||
423 | CHAR_T c = command_ps[cursor]; | ||
424 | unsigned width = 0; | ||
425 | int ofs_to_right; | ||
426 | |||
427 | /* advance cursor */ | ||
428 | cursor++; | ||
429 | if (unicode_status == UNICODE_ON) { | ||
430 | IF_UNICODE_WIDE_WCHARS(width = cmdedit_x;) | ||
431 | c = adjust_width_and_validate_wc(&cmdedit_x, c); | ||
432 | IF_UNICODE_WIDE_WCHARS(width = cmdedit_x - width;) | ||
433 | } else { | ||
434 | cmdedit_x++; | ||
435 | } | ||
436 | |||
437 | ofs_to_right = cmdedit_x - cmdedit_termw; | ||
438 | if (!ENABLE_UNICODE_WIDE_WCHARS || ofs_to_right <= 0) { | ||
439 | /* cursor remains on this line */ | ||
440 | printf(ESC"[1C"); | ||
441 | } | ||
442 | |||
443 | if (ofs_to_right >= 0) { | ||
444 | /* we go to the next line */ | ||
445 | printf(ESC"[1B"); | ||
446 | bb_putchar('\r'); | ||
447 | cmdedit_y++; | ||
448 | if (!ENABLE_UNICODE_WIDE_WCHARS || ofs_to_right == 0) { | ||
449 | width = 0; | ||
450 | } | ||
451 | cmdedit_x = width; | ||
452 | } | ||
453 | } | ||
454 | #endif | ||
455 | |||
420 | /* Move to end of line (by printing all chars till the end) */ | 456 | /* Move to end of line (by printing all chars till the end) */ |
421 | static void put_till_end_and_adv_cursor(void) | 457 | static void put_till_end_and_adv_cursor(void) |
422 | { | 458 | { |
@@ -469,6 +505,7 @@ static void input_backward(unsigned num) | |||
469 | 505 | ||
470 | if (cmdedit_x >= num) { | 506 | if (cmdedit_x >= num) { |
471 | cmdedit_x -= num; | 507 | cmdedit_x -= num; |
508 | #if !ENABLE_PLATFORM_MINGW32 | ||
472 | if (num <= 4) { | 509 | if (num <= 4) { |
473 | /* This is longer by 5 bytes on x86. | 510 | /* This is longer by 5 bytes on x86. |
474 | * Also gets miscompiled for ARM users | 511 | * Also gets miscompiled for ARM users |
@@ -481,6 +518,7 @@ static void input_backward(unsigned num) | |||
481 | } while (--num); | 518 | } while (--num); |
482 | return; | 519 | return; |
483 | } | 520 | } |
521 | #endif | ||
484 | printf(ESC"[%uD", num); | 522 | printf(ESC"[%uD", num); |
485 | return; | 523 | return; |
486 | } | 524 | } |
@@ -610,7 +648,11 @@ static void input_backspace(void) | |||
610 | static void input_forward(void) | 648 | static void input_forward(void) |
611 | { | 649 | { |
612 | if (cursor < command_len) | 650 | if (cursor < command_len) |
651 | #if !ENABLE_PLATFORM_MINGW32 | ||
613 | put_cur_glyph_and_inc_cursor(); | 652 | put_cur_glyph_and_inc_cursor(); |
653 | #else | ||
654 | inc_cursor(); | ||
655 | #endif | ||
614 | } | 656 | } |
615 | 657 | ||
616 | #if ENABLE_FEATURE_TAB_COMPLETION | 658 | #if ENABLE_FEATURE_TAB_COMPLETION |
@@ -718,7 +760,11 @@ static int path_parse(char ***p) | |||
718 | tmp = (char*)pth; | 760 | tmp = (char*)pth; |
719 | npth = 1; /* path component count */ | 761 | npth = 1; /* path component count */ |
720 | while (1) { | 762 | while (1) { |
763 | #if ENABLE_PLATFORM_MINGW32 | ||
764 | tmp = (char *)next_path_sep(tmp); | ||
765 | #else | ||
721 | tmp = strchr(tmp, ':'); | 766 | tmp = strchr(tmp, ':'); |
767 | #endif | ||
722 | if (!tmp) | 768 | if (!tmp) |
723 | break; | 769 | break; |
724 | tmp++; | 770 | tmp++; |
@@ -731,7 +777,11 @@ static int path_parse(char ***p) | |||
731 | res[0] = tmp = xstrdup(pth); | 777 | res[0] = tmp = xstrdup(pth); |
732 | npth = 1; | 778 | npth = 1; |
733 | while (1) { | 779 | while (1) { |
780 | #if ENABLE_PLATFORM_MINGW32 | ||
781 | tmp = (char *)next_path_sep(tmp); | ||
782 | #else | ||
734 | tmp = strchr(tmp, ':'); | 783 | tmp = strchr(tmp, ':'); |
784 | #endif | ||
735 | if (!tmp) | 785 | if (!tmp) |
736 | break; | 786 | break; |
737 | *tmp++ = '\0'; /* ':' -> '\0' */ | 787 | *tmp++ = '\0'; /* ':' -> '\0' */ |
@@ -817,6 +867,9 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
817 | if (stat(found, &st) && lstat(found, &st)) | 867 | if (stat(found, &st) && lstat(found, &st)) |
818 | goto cont; /* hmm, remove in progress? */ | 868 | goto cont; /* hmm, remove in progress? */ |
819 | 869 | ||
870 | if (type == FIND_EXE_ONLY && !file_is_executable(found)) | ||
871 | goto cont; | ||
872 | |||
820 | /* Save only name */ | 873 | /* Save only name */ |
821 | len = strlen(name_found); | 874 | len = strlen(name_found); |
822 | found = xrealloc(found, len + 2); /* +2: for slash and NUL */ | 875 | found = xrealloc(found, len + 2); /* +2: for slash and NUL */ |
@@ -1898,7 +1951,16 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1898 | char *after_home_user; | 1951 | char *after_home_user; |
1899 | 1952 | ||
1900 | /* /home/user[/something] -> ~[/something] */ | 1953 | /* /home/user[/something] -> ~[/something] */ |
1954 | #if !ENABLE_PLATFORM_MINGW32 | ||
1901 | after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf); | 1955 | after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf); |
1956 | #else | ||
1957 | after_home_user = NULL; | ||
1958 | l = strlen(home_pwd_buf); | ||
1959 | if (l != 0 | ||
1960 | && strncasecmp(home_pwd_buf, cwd_buf, l) == 0) { | ||
1961 | after_home_user = cwd_buf + l; | ||
1962 | } | ||
1963 | #endif | ||
1902 | if (after_home_user | 1964 | if (after_home_user |
1903 | && (*after_home_user == '/' || *after_home_user == '\0') | 1965 | && (*after_home_user == '/' || *after_home_user == '\0') |
1904 | ) { | 1966 | ) { |
@@ -2272,9 +2334,16 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2272 | 2334 | ||
2273 | INIT_S(); | 2335 | INIT_S(); |
2274 | 2336 | ||
2337 | #if ENABLE_PLATFORM_MINGW32 | ||
2338 | memset(initial_settings.c_cc, 0, sizeof(initial_settings.c_cc)); | ||
2339 | initial_settings.c_cc[VINTR] = CTRL('C'); | ||
2340 | initial_settings.c_cc[VEOF] = CTRL('D'); | ||
2341 | if (!isatty(0) || !isatty(1)) { | ||
2342 | #else | ||
2275 | if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 | 2343 | if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 |
2276 | || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON | 2344 | || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON |
2277 | ) { | 2345 | ) { |
2346 | #endif | ||
2278 | /* Happens when e.g. stty -echo was run before. | 2347 | /* Happens when e.g. stty -echo was run before. |
2279 | * But if ICANON is not set, we don't come here. | 2348 | * But if ICANON is not set, we don't come here. |
2280 | * (example: interactive python ^Z-backgrounded, | 2349 | * (example: interactive python ^Z-backgrounded, |
@@ -2383,6 +2452,11 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2383 | } | 2452 | } |
2384 | 2453 | ||
2385 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); | 2454 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); |
2455 | #if ENABLE_PLATFORM_MINGW32 | ||
2456 | /* scroll to cursor position on any keypress */ | ||
2457 | if (isatty(fileno(stdin)) && isatty(fileno(stdout))) | ||
2458 | move_cursor_row(0); | ||
2459 | #endif | ||
2386 | 2460 | ||
2387 | #if ENABLE_FEATURE_REVERSE_SEARCH | 2461 | #if ENABLE_FEATURE_REVERSE_SEARCH |
2388 | again: | 2462 | again: |