diff options
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 68 |
1 files changed, 5 insertions, 63 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b349bc6f2..e56dd20b0 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -59,28 +59,13 @@ | |||
59 | #define ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR \ | 59 | #define ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR \ |
60 | (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) | 60 | (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) |
61 | 61 | ||
62 | |||
63 | static line_input_t *state; | ||
64 | |||
65 | #ifdef __MINGW32__ | 62 | #ifdef __MINGW32__ |
66 | struct termios { | 63 | #include "cygwin_termios.h" |
67 | int c_lflag; | 64 | #define safe_read(fd,buf,size) wincon_read(fd,buf,size) |
68 | int c_cc[3]; | ||
69 | }; | ||
70 | #define safe_read(fd,buf,n) wincon_read(fd,buf,n) | ||
71 | /* True value does not matter because it's emulated */ | ||
72 | #define ICANON 1 | ||
73 | #define ECHO 2 | ||
74 | #define ECHONL 4 | ||
75 | #define ISIG 8 | ||
76 | |||
77 | #define VMIN 0 | ||
78 | #define VTIME 1 | ||
79 | #define VINTR 2 | ||
80 | |||
81 | static int wincon_read(int fd, char *buf, int size); | ||
82 | #endif | 65 | #endif |
83 | 66 | ||
67 | static line_input_t *state; | ||
68 | |||
84 | static struct termios initial_settings, new_settings; | 69 | static struct termios initial_settings, new_settings; |
85 | 70 | ||
86 | static volatile unsigned cmdedit_termw = 80; /* actual terminal width */ | 71 | static volatile unsigned cmdedit_termw = 80; /* actual terminal width */ |
@@ -1227,13 +1212,10 @@ static void parse_prompt(const char *prmt_ptr) | |||
1227 | } | 1212 | } |
1228 | #endif | 1213 | #endif |
1229 | 1214 | ||
1230 | #ifdef __MINGW32__ | ||
1231 | #define setTermSettings(fd, argp) | ||
1232 | #define getTermSettings(fd, argp) ((struct termios *)argp)->c_lflag = ECHO; | ||
1233 | #else | ||
1234 | #define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp) | 1215 | #define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp) |
1235 | #define getTermSettings(fd, argp) tcgetattr(fd, argp); | 1216 | #define getTermSettings(fd, argp) tcgetattr(fd, argp); |
1236 | 1217 | ||
1218 | #ifndef __MINGW32__ | ||
1237 | static sighandler_t previous_SIGWINCH_handler; | 1219 | static sighandler_t previous_SIGWINCH_handler; |
1238 | #endif | 1220 | #endif |
1239 | 1221 | ||
@@ -1770,46 +1752,6 @@ line_input_t *new_line_input_t(int flags) | |||
1770 | return n; | 1752 | return n; |
1771 | } | 1753 | } |
1772 | 1754 | ||
1773 | #ifdef __MINGW32__ | ||
1774 | #include <windef.h> | ||
1775 | #include <wincon.h> | ||
1776 | #include "strbuf.h" | ||
1777 | |||
1778 | #undef safe_read | ||
1779 | static int wincon_read(int fd, char *buf, int size) | ||
1780 | { | ||
1781 | static struct strbuf input = STRBUF_INIT; | ||
1782 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); | ||
1783 | static int initialized = 0; | ||
1784 | |||
1785 | if (fd != 0) | ||
1786 | die("wincon_read is for stdin only"); | ||
1787 | if (cin == INVALID_HANDLE_VALUE) | ||
1788 | return safe_read(fd, buf, size); | ||
1789 | if (!initialized) { | ||
1790 | SetConsoleMode(cin, ENABLE_ECHO_INPUT); | ||
1791 | initialized = 1; | ||
1792 | } | ||
1793 | while (input.len < size) { | ||
1794 | INPUT_RECORD record; | ||
1795 | DWORD nevent = 0, nevent_out; | ||
1796 | int ch; | ||
1797 | |||
1798 | if (!ReadConsoleInput(cin, &record, 1, &nevent_out)) | ||
1799 | return -1; | ||
1800 | if (record.EventType != KEY_EVENT || !record.Event.KeyEvent.bKeyDown) | ||
1801 | continue; | ||
1802 | ch = record.Event.KeyEvent.uChar.AsciiChar; | ||
1803 | /* Ctrl-X is handled by ReadConsoleInput, Alt-X is not needed anyway */ | ||
1804 | strbuf_addch(&input, ch); | ||
1805 | } | ||
1806 | memcpy(buf, input.buf, size); | ||
1807 | memcpy(input.buf, input.buf+size, input.len-size+1); | ||
1808 | strbuf_setlen(&input, input.len-size); | ||
1809 | return size; | ||
1810 | } | ||
1811 | #endif | ||
1812 | |||
1813 | #else | 1755 | #else |
1814 | 1756 | ||
1815 | #undef read_line_input | 1757 | #undef read_line_input |