diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-21 19:21:21 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-21 19:21:21 +0000 |
commit | 00cdbd8fc20a4e2e2208f90a2691a3806c931b06 (patch) | |
tree | 3b68fdca42dd9fe48565c58eeefa0b14d0b2ac6c | |
parent | 5592fac30812f3ca908961cd75a08a009baa7bb6 (diff) | |
download | busybox-w32-00cdbd8fc20a4e2e2208f90a2691a3806c931b06.tar.gz busybox-w32-00cdbd8fc20a4e2e2208f90a2691a3806c931b06.tar.bz2 busybox-w32-00cdbd8fc20a4e2e2208f90a2691a3806c931b06.zip |
Introduce FEATURE_EDITING_FANCY_KEYS, so that user can disable
less-known keys (e.g. Ctrl-B/E/F)
-rw-r--r-- | scripts/defconfig | 1 | ||||
-rw-r--r-- | shell/Config.in | 8 | ||||
-rw-r--r-- | shell/cmdedit.c | 91 |
3 files changed, 38 insertions, 62 deletions
diff --git a/scripts/defconfig b/scripts/defconfig index fc43deb2d..503f12a01 100644 --- a/scripts/defconfig +++ b/scripts/defconfig | |||
@@ -632,6 +632,7 @@ CONFIG_FEATURE_SH_IS_NONE=y | |||
632 | # CONFIG_FEATURE_SH_EXTRA_QUIET is not set | 632 | # CONFIG_FEATURE_SH_EXTRA_QUIET is not set |
633 | # CONFIG_FEATURE_SH_STANDALONE_SHELL is not set | 633 | # CONFIG_FEATURE_SH_STANDALONE_SHELL is not set |
634 | # CONFIG_FEATURE_COMMAND_EDITING is not set | 634 | # CONFIG_FEATURE_COMMAND_EDITING is not set |
635 | # CONFIG_FEATURE_EDITING_FANCY_KEYS is not set | ||
635 | # CONFIG_FEATURE_COMMAND_EDITING_VI is not set | 636 | # CONFIG_FEATURE_COMMAND_EDITING_VI is not set |
636 | CONFIG_FEATURE_COMMAND_HISTORY= | 637 | CONFIG_FEATURE_COMMAND_HISTORY= |
637 | # CONFIG_FEATURE_COMMAND_SAVEHISTORY is not set | 638 | # CONFIG_FEATURE_COMMAND_SAVEHISTORY is not set |
diff --git a/shell/Config.in b/shell/Config.in index 9ac233155..15c52be54 100644 --- a/shell/Config.in +++ b/shell/Config.in | |||
@@ -247,6 +247,14 @@ config FEATURE_COMMAND_EDITING | |||
247 | help | 247 | help |
248 | Enable command editing in shell. | 248 | Enable command editing in shell. |
249 | 249 | ||
250 | config FEATURE_EDITING_FANCY_KEYS | ||
251 | bool "Additional editing keys" | ||
252 | default n | ||
253 | depends on FEATURE_COMMAND_EDITING | ||
254 | help | ||
255 | Enable additonal editing keys (Ctrl-E, Ctrl-U etc). | ||
256 | Arrow keys, Home/End/Delete and Ctrl-W work even without this option. | ||
257 | |||
250 | config FEATURE_COMMAND_EDITING_VI | 258 | config FEATURE_COMMAND_EDITING_VI |
251 | bool "vi-style line editing commands" | 259 | bool "vi-style line editing commands" |
252 | default n | 260 | default n |
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 39cab19a0..a1432af15 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
@@ -24,55 +24,10 @@ | |||
24 | 24 | ||
25 | Small bugs (simple effect): | 25 | Small bugs (simple effect): |
26 | - not true viewing if terminal size (x*y symbols) less | 26 | - not true viewing if terminal size (x*y symbols) less |
27 | size (prompt + editor`s line + 2 symbols) | 27 | size (prompt + editor's line + 2 symbols) |
28 | - not true viewing if length prompt less terminal width | 28 | - not true viewing if length prompt less terminal width |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* | ||
32 | CONFIG_FEATURE_COMMAND_EDITING=y | ||
33 | # CONFIG_FEATURE_COMMAND_EDITING_VI is not set | ||
34 | CONFIG_FEATURE_COMMAND_HISTORY=15 | ||
35 | # CONFIG_FEATURE_COMMAND_SAVEHISTORY is not set | ||
36 | # CONFIG_FEATURE_COMMAND_TAB_COMPLETION is not set | ||
37 | # CONFIG_FEATURE_COMMAND_USERNAME_COMPLETION is not set | ||
38 | # CONFIG_FEATURE_SH_FANCY_PROMPT is not set | ||
39 | Sizes with the above: | ||
40 | # size cmdedit.o | ||
41 | text data bss dec hex filename | ||
42 | 2374 4 228 2606 a2e cmdedit.o | ||
43 | # nm --size-sort cmdedit.o | ||
44 | 00000004 b cmdedit_prmt_len | ||
45 | 00000004 b cmdedit_prompt | ||
46 | 00000004 d cmdedit_termw | ||
47 | 00000004 b cmdedit_x | ||
48 | 00000004 b cmdedit_y | ||
49 | 00000004 b command_ps | ||
50 | 00000004 b cur_history | ||
51 | 00000004 b cursor | ||
52 | 00000004 b handlers_sets | ||
53 | 00000004 b len | ||
54 | 00000004 b n_history | ||
55 | 00000004 b previous_SIGWINCH_handler | ||
56 | 00000009 t beep | ||
57 | 00000017 t goto_new_line | ||
58 | 0000001a t input_end | ||
59 | 0000001b t input_backspace | ||
60 | 0000001e t input_forward | ||
61 | 00000027 t get_next_history | ||
62 | 00000036 t put_prompt | ||
63 | 00000039 t redraw | ||
64 | 0000003c b initial_settings | ||
65 | 0000003c b new_settings | ||
66 | 00000040 b history | ||
67 | 00000047 t input_delete | ||
68 | 0000004d t get_previous_history | ||
69 | 00000059 t cmdedit_reset_term | ||
70 | 0000006c t cmdedit_set_out_char | ||
71 | 00000087 t input_backward | ||
72 | 000000a1 t win_changed | ||
73 | 0000053c T cmdedit_read_input | ||
74 | */ | ||
75 | |||
76 | #include <sys/ioctl.h> | 31 | #include <sys/ioctl.h> |
77 | #include "busybox.h" | 32 | #include "busybox.h" |
78 | #include "cmdedit.h" | 33 | #include "cmdedit.h" |
@@ -969,7 +924,7 @@ void load_history(const char *fromfile) | |||
969 | cur_history = n_history = hi; | 924 | cur_history = n_history = hi; |
970 | } | 925 | } |
971 | 926 | ||
972 | void save_history (const char *tofile) | 927 | void save_history(const char *tofile) |
973 | { | 928 | { |
974 | FILE *fp = fopen(tofile, "w"); | 929 | FILE *fp = fopen(tofile, "w"); |
975 | 930 | ||
@@ -1381,6 +1336,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1381 | goto_new_line(); | 1336 | goto_new_line(); |
1382 | break_out = 1; | 1337 | break_out = 1; |
1383 | break; | 1338 | break; |
1339 | #if ENABLE_FEATURE_EDITING_FANCY_KEYS | ||
1384 | case CTRL('A'): | 1340 | case CTRL('A'): |
1385 | vi_case('0'|vbit:) | 1341 | vi_case('0'|vbit:) |
1386 | /* Control-a -- Beginning of line */ | 1342 | /* Control-a -- Beginning of line */ |
@@ -1393,6 +1349,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1393 | /* Control-b -- Move back one character */ | 1349 | /* Control-b -- Move back one character */ |
1394 | input_backward(1); | 1350 | input_backward(1); |
1395 | break; | 1351 | break; |
1352 | #endif | ||
1396 | case CTRL('C'): | 1353 | case CTRL('C'): |
1397 | vi_case(CTRL('C')|vbit:) | 1354 | vi_case(CTRL('C')|vbit:) |
1398 | /* Control-c -- stop gathering input */ | 1355 | /* Control-c -- stop gathering input */ |
@@ -1425,10 +1382,11 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1425 | break_out = len = -1; | 1382 | break_out = len = -1; |
1426 | break; | 1383 | break; |
1427 | #endif | 1384 | #endif |
1428 | } else { | ||
1429 | input_delete(0); | ||
1430 | } | 1385 | } |
1386 | input_delete(0); | ||
1431 | break; | 1387 | break; |
1388 | |||
1389 | #if ENABLE_FEATURE_EDITING_FANCY_KEYS | ||
1432 | case CTRL('E'): | 1390 | case CTRL('E'): |
1433 | vi_case('$'|vbit:) | 1391 | vi_case('$'|vbit:) |
1434 | /* Control-e -- End of line */ | 1392 | /* Control-e -- End of line */ |
@@ -1440,16 +1398,21 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1440 | /* Control-f -- Move forward one character */ | 1398 | /* Control-f -- Move forward one character */ |
1441 | input_forward(); | 1399 | input_forward(); |
1442 | break; | 1400 | break; |
1401 | #endif | ||
1402 | |||
1443 | case '\b': | 1403 | case '\b': |
1444 | case '\x7f': /* DEL */ | 1404 | case '\x7f': /* DEL */ |
1445 | /* Control-h and DEL */ | 1405 | /* Control-h and DEL */ |
1446 | input_backspace(); | 1406 | input_backspace(); |
1447 | break; | 1407 | break; |
1408 | |||
1448 | case '\t': | 1409 | case '\t': |
1449 | #if ENABLE_FEATURE_COMMAND_TAB_COMPLETION | 1410 | #if ENABLE_FEATURE_COMMAND_TAB_COMPLETION |
1450 | input_tab(&lastWasTab); | 1411 | input_tab(&lastWasTab); |
1451 | #endif | 1412 | #endif |
1452 | break; | 1413 | break; |
1414 | |||
1415 | #if ENABLE_FEATURE_EDITING_FANCY_KEYS | ||
1453 | case CTRL('K'): | 1416 | case CTRL('K'): |
1454 | /* Control-k -- clear to end of line */ | 1417 | /* Control-k -- clear to end of line */ |
1455 | command[cursor] = 0; | 1418 | command[cursor] = 0; |
@@ -1462,6 +1425,8 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1462 | printf("\033[H"); | 1425 | printf("\033[H"); |
1463 | redraw(0, len - cursor); | 1426 | redraw(0, len - cursor); |
1464 | break; | 1427 | break; |
1428 | #endif | ||
1429 | |||
1465 | #if MAX_HISTORY > 0 | 1430 | #if MAX_HISTORY > 0 |
1466 | case CTRL('N'): | 1431 | case CTRL('N'): |
1467 | vi_case(CTRL('N')|vbit:) | 1432 | vi_case(CTRL('N')|vbit:) |
@@ -1482,6 +1447,8 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1482 | } | 1447 | } |
1483 | break; | 1448 | break; |
1484 | #endif | 1449 | #endif |
1450 | |||
1451 | #if ENABLE_FEATURE_EDITING_FANCY_KEYS | ||
1485 | case CTRL('U'): | 1452 | case CTRL('U'): |
1486 | vi_case(CTRL('U')|vbit:) | 1453 | vi_case(CTRL('U')|vbit:) |
1487 | /* Control-U -- Clear line before cursor */ | 1454 | /* Control-U -- Clear line before cursor */ |
@@ -1490,14 +1457,16 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1490 | redraw(cmdedit_y, len -= cursor); | 1457 | redraw(cmdedit_y, len -= cursor); |
1491 | } | 1458 | } |
1492 | break; | 1459 | break; |
1460 | #endif | ||
1493 | case CTRL('W'): | 1461 | case CTRL('W'): |
1494 | vi_case(CTRL('W')|vbit:) | 1462 | vi_case(CTRL('W')|vbit:) |
1495 | /* Control-W -- Remove the last word */ | 1463 | /* Control-W -- Remove the last word */ |
1496 | while (cursor > 0 && isspace(command[cursor-1])) | 1464 | while (cursor > 0 && isspace(command[cursor-1])) |
1497 | input_backspace(); | 1465 | input_backspace(); |
1498 | while (cursor > 0 &&!isspace(command[cursor-1])) | 1466 | while (cursor > 0 && !isspace(command[cursor-1])) |
1499 | input_backspace(); | 1467 | input_backspace(); |
1500 | break; | 1468 | break; |
1469 | |||
1501 | #if ENABLE_FEATURE_COMMAND_EDITING_VI | 1470 | #if ENABLE_FEATURE_COMMAND_EDITING_VI |
1502 | case 'i'|vbit: | 1471 | case 'i'|vbit: |
1503 | vi_cmdmode = 0; | 1472 | vi_cmdmode = 0; |
@@ -1655,6 +1624,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1655 | if (dummy != '~') | 1624 | if (dummy != '~') |
1656 | c = '\0'; | 1625 | c = '\0'; |
1657 | } | 1626 | } |
1627 | |||
1658 | switch (c) { | 1628 | switch (c) { |
1659 | #if ENABLE_FEATURE_COMMAND_TAB_COMPLETION | 1629 | #if ENABLE_FEATURE_COMMAND_TAB_COMPLETION |
1660 | case '\t': /* Alt-Tab */ | 1630 | case '\t': /* Alt-Tab */ |
@@ -1705,7 +1675,7 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1705 | input_end(); | 1675 | input_end(); |
1706 | break; | 1676 | break; |
1707 | default: | 1677 | default: |
1708 | c = 0; | 1678 | c = '\0'; |
1709 | beep(); | 1679 | beep(); |
1710 | } | 1680 | } |
1711 | break; | 1681 | break; |
@@ -1722,36 +1692,33 @@ int cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1722 | } | 1692 | } |
1723 | } else | 1693 | } else |
1724 | #endif | 1694 | #endif |
1725 | { | 1695 | |
1726 | #if ENABLE_FEATURE_COMMAND_EDITING_VI | 1696 | #if ENABLE_FEATURE_COMMAND_EDITING_VI |
1727 | if (vi_cmdmode) /* don't self-insert */ | 1697 | if (vi_cmdmode) /* Don't self-insert */ |
1728 | break; | 1698 | break; |
1729 | #endif | 1699 | #endif |
1730 | if (!Isprint(c)) /* Skip non-printable characters */ | 1700 | if (!Isprint(c)) /* Skip non-printable characters */ |
1731 | break; | 1701 | break; |
1732 | } | ||
1733 | 1702 | ||
1734 | if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */ | 1703 | if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */ |
1735 | break; | 1704 | break; |
1736 | 1705 | ||
1737 | len++; | 1706 | len++; |
1738 | |||
1739 | if (cursor == (len - 1)) { /* Append if at the end of the line */ | 1707 | if (cursor == (len - 1)) { /* Append if at the end of the line */ |
1740 | *(command + cursor) = c; | 1708 | command[cursor] = c; |
1741 | *(command + cursor + 1) = 0; | 1709 | command[cursor+1] = '\0'; |
1742 | cmdedit_set_out_char(' '); | 1710 | cmdedit_set_out_char(' '); |
1743 | } else { /* Insert otherwise */ | 1711 | } else { /* Insert otherwise */ |
1744 | int sc = cursor; | 1712 | int sc = cursor; |
1745 | 1713 | ||
1746 | memmove(command + sc + 1, command + sc, len - sc); | 1714 | memmove(command + sc + 1, command + sc, len - sc); |
1747 | *(command + sc) = c; | 1715 | command[sc] = c; |
1748 | sc++; | 1716 | sc++; |
1749 | /* rewrite from cursor */ | 1717 | /* rewrite from cursor */ |
1750 | input_end(); | 1718 | input_end(); |
1751 | /* to prev x pos + 1 */ | 1719 | /* to prev x pos + 1 */ |
1752 | input_backward(cursor - sc); | 1720 | input_backward(cursor - sc); |
1753 | } | 1721 | } |
1754 | |||
1755 | break; | 1722 | break; |
1756 | } | 1723 | } |
1757 | if (break_out) /* Enter is the command terminator, no more input. */ | 1724 | if (break_out) /* Enter is the command terminator, no more input. */ |