aboutsummaryrefslogtreecommitdiff
path: root/win32/winansi.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* winansi: tweak colour mappingRon Yorston2021-02-041-19/+9
|
* winansi: extend ANSI emulationRon Yorston2021-02-031-49/+177
| | | | | | | | | | | | | | | | Extend ANSI emulation to include: ESC[38;2;R;G;Bm 24-bit foreground colour ESC[48;2;R;G;Bm 24-bit background colour ESC[38;5;Nm 8-bit foreground colour ESC[48;5;Nm 8-bit background colour The colours are selected from the 16 standard console colours. This is unlikely to be aesthetically pleasing but at least it's better than raw escape sequences. Also, add ESC[9m (strike through) as a known but unsupported sequence.
* winansi: change default 'skip ANSI emulation' settingRon Yorston2021-02-031-13/+3
| | | | | | | | | Change the default 'skip ANSI emulation' setting which is used when the environment variable BB_SKIP_ANSI_EMULATION is unset. Previously it was 0 (always emulate) now it's 2 (detect whether or not the terminal supports ANSI escape sequences and behave accordingly). The default value is also now a build-time option.
* winansi: intercept calls to fputc(3)Ron Yorston2020-12-071-1/+19
| | | | | | | | | | | | | Perform code page translation for fputc(3). It's only used in a few places but is needed to fix things like: $ echo € | dos2unix Ç $ paste -d € file1 file2 1Ç2 Unfortunately it breaks the inventive use of dos2unix in GitHub issue #203.
* winansi: suppress console flags redefinition warningBiswa962020-06-071-0/+5
| | | | Modern versions of MinGW-w64 define more console modes.
* winansi: more fine-grained control of ANSI emulationRon Yorston2020-04-131-2/+34
| | | | | | | | | | | | | | | | Change the meaning of the BB_SKIP_ANSI_EMULATION variable: - if it isn't set or if it has any value other than 1 or 2, use ANSI emulation; - if it's set to 1, always emit ANSI escape codes; - if it's set to 2, attempt to enable virtual terminal processing in the current console. If that works emit ANSI escape codes, if not revert to ANSI emulation. On all platforms I've tested (Windows 10, Windows 8.1, ReactOS 0.4.13, plus ConEmu) BB_SKIP_ANSI_EMULATION=2 does the right thing.
* ash: reset ANSI emulation when BB_SKIP_ANSI_EMULATION changesRon Yorston2020-04-131-10/+7
| | | | | Update the skip status on the first call to skip_ansi_emulation() and whenever the BB_SKIP_ANSI_EMULATION variable changes.
* winansi: fix alternate screen buffer in Windows 7Ron Yorston2020-02-061-6/+10
| | | | | | | | | | | | | Closing 'vi' in Windows 7 resulted in the console window failing to echo any output correctly until the 'reset' builtin was run. This didn't happen in Windows XP, 8 or 10. The problem is fixed by only duplicating the console handle when switching *to* the alternate screen buffer. Add sanity checks so that switching to the alternate buffer requires the cached handled to be invalid, while it must be valid when switching from the alternate buffer.
* winansi: code shrinkRon Yorston2020-01-081-37/+31
| | | | | | | | | | | | | | Rework the ANSI emulation code to reduce its size. - Fetch console attributes when required rather than caching them. The init() function is no longer required; the only remaining initialisation is now performed in is_console(). - Turning off inverse video (ESC[27m) didn't work properly. This has been improved though it still doesn't work in some unlikely cases (ESC[7;27m). These changes save 180 bytes.
* winansi: restore correct attributes after lsRon Yorston2020-01-071-1/+7
| | | | | | | | | As reported in GitHub issue #178 the last colour set by the ls command is retained in the console. This is due to the previous commit reinitialising the stored attributes more frequently than it should. Attriubutes should only be initialised once.
* winansi: fix escape processing in Windows 10 release 1809Ron Yorston2020-01-061-20/+20
| | | | | | | | | | | | | | As reported in GitHub issue #177, ANSI escape sequences don't work reliably after shell redirection. The problem appears to be due to a change in the behaviour of dup2() in Windows 10 release 1809. The escape handling code kept a copy of the console handle for internal use. Prior to Windows 10 release 1809 this worked; since then unwinding shell redirections results in the actual console handle changing from time to time for reasons that are unknowable without access to the source code. Fix this by always fetching the console handle instead of caching it.
* vi: use alternate screen bufferRon Yorston2019-04-071-6/+68
| | | | | | | Implement the "ESC[?1049h" and "ESC[?1049l" ANSI escape sequences to switch between the alternate and normal screen buffers. This allows vi to restore the original screen contents on exit.
* winansi: code shrinkRon Yorston2019-04-071-20/+13
| | | | Add a common function to clear a section of the screen buffer.
* winansi: code shrinkRon Yorston2019-04-061-46/+17
| | | | | | | | | Use INVALID_HANDLE_VALUE (not NULL) to indicate that the console and console_in handles haven't been initialised. Replace many explicit comparisons against INVALID_HANDLE_VALUE with tests on the return value of GetConsoleScreenBufferInfo() which fails for an invalid handle.
* winansi: more robust handling of invalid escape sequencesRon Yorston2019-03-191-34/+46
| | | | | | | | Commit 399b1dd64 (winansi: support escape sequence to set window title) failed to handle some invalid escape sequences correctly. Make the code more robust. Fixes GitHub issue #153.
* winansi: support escape sequence to set window titleRon Yorston2019-03-091-12/+32
| | | | | | | | To set the window title from the command line: echo -en '\e]0;Hello World\007' The same sequence can be used in the shell's prompt (PS1).
* su: change title of console windowRon Yorston2019-03-091-0/+6
|
* win32: add support for the euro currency symbolRon Yorston2019-02-021-0/+68
| | | | | | | | | | | | | | | | | | | | | | The euro currency symbol was added to some OEM code pages. See: https://www.aivosto.com/articles/charsets-codepages-dos.html Add a configuration option (enabled by default) to support this. When enabled: - The read_key() function requests wide character key events. This allows the euro symbol to be entered regardless of the console OEM code page, though it needs to be available in the ANSI code page. - Conversions between OEM and ANSI code pages in winansi.c are modified to work around a bug in the Microsoft routines. - If the OEM code page is 850 when BusyBox starts it's changed to 858. This is the only currently supported OEM code page. Also, the shell read builtin is modified to use read_key() whenever input is being taken from the console.
* win32: implement vsnprintf(2)Ron Yorston2019-01-081-0/+21
| | | | | The Microsoft C runtime may include a defective version of vsnprintf. Implement a standards-compliant replacement.
* win32: emulate SIGPIPERon Yorston2018-12-111-3/+23
| | | | | | | | | | | | | | | | | | | The code to check whether a write error is due to a broken pipe can now either: - return with error EPIPE; - cause the process to exit with code 128+SIGPIPE. The default is the latter but the behaviour can be changed by issuing signal(SIGPIPE, SIG_IGN) and signal(SIGPIPE, SIG_DFL) calls. No actual signal is involved so kill can't send SIGPIPE and handlers other than SIG_IGN and SIG_DFL aren't supported. This does, however, avoid unsightly 'broken pipe' errors from commands like the example in GitHub issue #99: dd if=/dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
* win32: improvements to get_terminal_width_heightRon Yorston2018-04-031-17/+0
| | | | | | | | - move winansi_get_terminal_width_height from winansi.c to ioctl.c, the only caller; - check both stdout and stderr for a connection to a console; - omit unnecessary code in get_terminal_width_height (because the WIN32 implementation ignores the file descriptor).
* win32: simplify isatty replacementRon Yorston2018-04-031-5/+1
| | | | | Don't treat input and output file descriptors differently: if we aren't connected to a console GetConsoleMode will fail for either.
* winansi: check for broken pipe in winansi_writeRon Yorston2018-03-091-7/+21
| | | | | | | write(2) is commonly used in applets like cat and tr so we should check for broken pipes there too. See issue #99.
* winansi: check for broken pipeRon Yorston2018-03-061-6/+29
| | | | | | | | | | | | | | Microsoft Windows doesn't support SIGPIPE and its support for the EPIPE error is somewhat inadequate. Most of the time a broken pipe leads to an EINVAL error which is misleading: $ yes hello | head -1 hello yes: Invalid argument Add a function to test for the underlying Windows error that indicates a broken pipe and set errno to EPIPE. Call this function in a few strategic places.
* winansi: changes to puts, fputs and fwriteRon Yorston2018-03-061-18/+3
| | | | | | | Rewrite winansi_puts using winansi_fputs and putchar. There's no need to use winansi_putchar. Improve error return values from winansi_fputs and winansi_fwrite.
* winansi: improve error return values in ANSI emulationRon Yorston2018-03-061-20/+23
| | | | Also tighten up the code slightly.
* winansi: create and use functions to test for consoleRon Yorston2018-03-061-51/+20
|
* win32: handle /dev/zero and /dev/urandom in open and read functionsRon Yorston2018-02-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Currently /dev/zero is handled as a special case in dd. Add hacks to the open and read functions in mingw.c to handle the zero and urandom devices. - Opening /dev/zero or /dev/urandom actually opens the special Windows file 'nul' which behaves like /dev/null. This allows manipulation of the file descriptor with things like seek and close - When /dev/zero or /dev/urandom is opened the resulting file descriptor is stored and used to override the behaviour of read. - No attempt is made to track duplicated file descriptors, so using these devices for redirections in the shell isn't going to work and won't be permitted. (Could be, but won't.) - Limited control of the special file descriptors is provided by allowing the internal variables to be changed. - The numbers from /dev/urandom aren't very random.
* mingw: accommodate for BusyBox' assumptions about isatty()Johannes Schindelin2017-08-241-0/+27
| | | | | | | | | | | | | | | On Windows, isatty(fd) determines whether the file descriptor refers to a character device. The thing is: even NUL or a printer is a character device. BusyBox thinks, however, that isatty() only returns non-zero for an interactive terminal. So let's shadow isatty() by a version that answers the question BusyBox wants to have answered. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ron Yorston <rmy@pobox.com>
* Provide vfprintf replacementRon Yorston2017-02-071-0/+1
| | | | | vfprintf is used in ash_vmsg. It should be passed through the codepage conversion in winansi.c.
* win32: allow ANSI emulation to be disabledRon Yorston2016-11-101-2/+15
| | | | | If the environment variable BB_SKIP_ANSI_EMULATION is set (the value doesn't matter) escape sequences are passed through to the terminal.
* win32: don't attempt ANSI emulation on data containing NUL charactersRon Yorston2016-08-161-4/+11
|
* win32: allow for vsnprintf returning -1Ron Yorston2016-07-081-1/+6
| | | | | | | vsnprintf can return -1. I've seen it do this when writing to a small buffer while vsnprintf(NULL, 0, ...) returns a valid length. I'd prefer not to rely on the latter working with arbitrary old Windows runtimes so just skip ANSI emulation if -1 is returned.
* winansi: revert to previous console behaviour for vi/lessRon Yorston2016-04-261-0/+18
| | | | | | | | | | | | Recent changes to make the Windows console behave more like a *nix terminal didn't work too well for vi/less. On *nix the terminal buffer can't be scrolled while such screen-based applications are running. In the Windows console this remained possible and led to confusion. Add a new routine to allow vi/less to revert to their previous behaviour where the cursor is positioned at the top of the buffer and the entire buffer is cleared.
* lineedit: move console viewport to cursor on keypressRon Yorston2016-04-261-1/+1
| | | | | | When a normal *nix terminal has been scrolled back through its buffer, any keypress will return to the cursor position. Add code to lineedit.c to do the same for the Windows console.
* winansi: speed up clearing of screenRon Yorston2016-04-261-15/+10
| | | | | | | | | | | | | | | Various tasks on the shell command line (e.g. backspace, DEL, reverse search) were found to be slow when the console screen buffer was very large. This was because the entire buffer was being cleared in erase_till_end_of_screen(). Rewrite erase_till_end_of_screen() to only clear to the end of the visible screen and to be tidier. (Based on a suggestion by GitHub user avih.) Also, modify move_cursor to use coordinates relative to the current display (as ANSI escapes expect) rather than relative to the screen buffer.
* winansi: fixes to cursor positioning, screen clearingRon Yorston2015-07-171-4/+15
| | | | | | | | | | It seems that the cursor positioning escape sequence 'ESC[n;mH' allows n and m values of 0 or 1 to represent the leftmost/topmost position. Allow for this and also fix handling of missing values. When the screen is cleared using FillConsoleOutputCharacterA it's also necessary to make explicit calls to FillConsoleOutputAttribute to reset attributes.
* Implement escape sequence for cursor downRon Yorston2014-04-091-21/+12
|
* Implement ANSI escape sequences for cursor up/forwardRon Yorston2014-04-071-0/+30
| | | | | These escape sequences are required for proper handling of line editing when the input exceeds the console width.
* Implement vprintf replacementRon Yorston2014-03-201-1/+2
|
* Implement getc replacementRon Yorston2014-03-201-0/+24
|
* Implement read replacement to handle OEM codepagesRon Yorston2014-03-201-0/+26
|
* Fixes to write replacementRon Yorston2014-03-201-2/+2
|
* Implement write replacement to handle OEM codepagesRon Yorston2014-03-201-1/+75
|
* Implement puts replacement to handle OEM codepagesRon Yorston2014-03-191-4/+24
|
* Use OEM codepage for console I/ORon Yorston2014-03-191-4/+80
| | | | | | | | | | Windows console applications use different codepages for console I/O and the rest of the API: http://msdn.microsoft.com/en-us/goglobal/bb688114.aspx#E2F Attempt to workaround this by converting characters when they're read from and written to the console. Not all possible paths are handled.
* winansi: skip DECTCEM sequence to avoid ugliness in viRon Yorston2012-10-101-0/+7
|
* win32: implement ioctlRon Yorston2012-04-231-1/+1
|
* Add code to find console dimensions in WIN32Ron Yorston2012-02-201-0/+17
|
* Fix off-by-one error in cursor positioningRon Yorston2012-02-171-1/+1
|