| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
| |
Commit 93a63809f9 (win32: add support for the euro currency symbol)
caused all invocations of busybox-w32 to change code page 850 to
858. This has been known to cause problems with fonts in PowerShell
(GitHub issue #207).
Delay changing the code page until an i/o operation is imminent.
Instances of PowerShell started by the `drop` applet during ssh login
thus no longer have their code page adjusted.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Allowing virtual terminal input mode to be set if available proved
to be unhelpful: cmd.exe doesn't understand such newfangled stuff
(though PowerShell does).
The allowed values of BB_TERMINAL_MODE are changed to:
0 Force console mode.
1 Force virtual terminal mode for output.
2 Force virtual terminal mode for input.
3 Force virtual terminal mode for input and output.
4 Support virtual terminal input if enabled. Don't alter mode.
5 Support virtual terminal input if enabled. Set virtual terminal
mode for output, if possible.
The default is 5.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add the environment variable BB_TERMINAL_MODE as a more general way
of controlling console/terminal mode setting. The default remains
unchanged: use virtual terminal mode for output if possible but
fall back to the console API with emulated ANSI escape sequences.
Currently valid settings are:
0 Force use of console mode
1 Force use of virtual terminal mode for output
5 Prefer virtual terminal mode for output, fall back to console
Other values won't do anything useful until code elsewhere has been
updated.
BB_SKIP_ANSI_EMULATION remains available for backwards compatibility.
If both variables are set BB_TERMINAL_MODE takes precedence.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Execute a remote command on a Windows server using ssh:
~$ ssh localhost 'echo hello'
rmy@localhost's password:
hello
If such a command is run from a busybox-w32 shell the console enters
a strange mode when the command completes.
Attempt to recover by setting the console back to a default mode.
- This doesn't work in a legacy console.
- The new mode may not be _exactly_ correct, but it's better than how
ssh leaves it.
Costs 80-96 bytes.
(GitHub issue #288)
|
|
|
|
|
| |
Rearrange code to avoid unnecessary tests when the environment
variable BB_SKIP_ANSI_EMULATION is set.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When running the busybox-w32 shell in ConEmu, if:
- ANSI emulation is disabled (which it will be, by default)
- a non-builtin command is run
there is a window of a few seconds after the command completes during
which ConEmu is in XTerm mode. During this time any attempt to use
the arrows keys will result in [A[B[C[D appearing. This appears to
be a common problem:
https://github.com/Maximus5/ConEmu/issues/2316
Try to detect if we're running under ConEmu and alter the default
behaviour to prefer ANSI emulation. The user can override this
preference by setting BB_SKIP_ANSI_EMULATION if desired.
By a quirk of fate, old MSYS2 programs (from 2021) which required
a workaround in busybox-w32 (commit 54d2ea4b4) are immune to the
problem with ConEmu.
(GitHib issue #287)
|
|
|
|
|
| |
In skip_ansi_emulation() only call SetConsoleMode() if the new
mode differs from the current mode.
|
|
|
|
|
|
|
|
| |
The grep applet was found to be rather slow. A major reason for
this is the implementation of getc(3). Using _getc_nolock() and
inlining is_console_in() speeds things up by a factor of three.
(GitHub issue #278)
|
|
|
|
|
|
|
|
|
|
|
| |
The environment variables BB_OVERRIDE_APPLETS, BB_SKIP_ANSI_EMULATION
and BB_SYSTEMROOT affect of the behaviour of the shell itself.
Setting them as shell variables is insufficient for them to affect
the current shell.
When these three variables are exported from the shell they are
now placed in the environment immediately. Conversely, when
they're unset or unexported they're removed from the environment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Detect if running under Wine by checking for the wine_get_version
function in ntdll.dll. This is how the Wine Developer FAQ suggests
doing it.
If running under Wine and not otherwise configured:
- use ANSI emulation;
- don't use alternate screen buffer in vi/less.
Explicit settings of BB_SKIP_ANSI_EMULATION and BB_ALT_BUFFER will
override the Wine defaults.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The following commands (reported in GitHub issue #201):
printf "\033[38;2;255;0;0mX\033[m\n"
printf "\033[38;2;255;0;0m;\033[m\n"
produce different results. The first correctly displays a red 'X'
while the second incorrectly displays a white ';'.
The problem is that process_24bit() overruns the extent of the
escape sequence. As a result the loop in process_escape() which
handles 'ESC[...m' sequences sees the ';' in the text as a
continuation of the escape sequence.
Fix this by:
- reworking process_24bit() so that the overrun is avoided;
- changing the test in the loop in process_escape() so that even
if an overrun happens it stops processing at the end of the escape
sequence.
Also, save a few bytes by replacing '++str' with 'str + 1' in a
few places.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Commit b0b7ab792 (winansi: code shrink) noted that combining reverse
vidoe escape sequences (e.g. ESC[7;27m) didn't work properly.
Make further changes to improve the situation:
- revert to keeping the current attributes in a static variable;
- when reverse video is enabled switch the intensity as well as the
colour components;
- move the code from set_console_attr() into its only caller,
process_escape();
- use 0xffff instead of 0 as a flag to indicate the attributes
haven't been initialised.
Saves 44 bytes and seems to work better.
|
| |
|
|
|
|
|
|
|
|
| |
The alternative console screen buffer (used by less and vi) doesn't
work in Wine.
Setting the environment variable BB_ALT_BUFFER to 0 causes a screen
reset instead.
|
|
|
|
|
|
|
|
|
|
|
|
| |
Running the test suite on Wine failed because in
seq 4 0 8 | head -n 10
'seq' didn't detect the broken pipe when 'head' terminated and
carried on forever. Fix this by adding a call to ferror(3) in
winansi_vfprintf().
Also, use xstrdup() and xmalloc() in a couple of places.
|
|
|
|
|
|
| |
Mark floating-point constants as being of type 'float'.
Saves 72 bytes.
|
|
|
|
|
|
| |
Use a more accurate technique to map RGB colours to standard
Windows console colours. Since this costs 648 bytes it's
configurable but is enabled by default.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Refactor handling of ESC[38...m and ESC[48...m:
- At lower levels deal only with the standard console foreground
colours. This makes handling of foreground and background colours
more similar.
- Many '|=' assignments (to combine attribute values) have been replaced
by simple assinments.
- Use a common routine to convert RGB to console colours; colours
in the 8-bit 6x6x6 cube are scaled up to make use of this.
- Detect invalid escape sequences to avoid setting incorrect colour
values.
Saves 296 bytes.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Modern versions of MinGW-w64 define more console modes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
Update the skip status on the first call to skip_ansi_emulation()
and whenever the BB_SKIP_ANSI_EMULATION variable changes.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Add a common function to clear a section of the screen buffer.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
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).
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
The Microsoft C runtime may include a defective version of vsnprintf.
Implement a standards-compliant replacement.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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;
|
|
|
|
|
|
|
|
| |
- 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).
|
|
|
|
|
| |
Don't treat input and output file descriptors differently: if we
aren't connected to a console GetConsoleMode will fail for either.
|
|
|
|
|
|
|
| |
write(2) is commonly used in applets like cat and tr so we should
check for broken pipes there too.
See issue #99.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Also tighten up the code slightly.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
| |
vfprintf is used in ash_vmsg. It should be passed through the
codepage conversion in winansi.c.
|
|
|
|
|
| |
If the environment variable BB_SKIP_ANSI_EMULATION is set (the value
doesn't matter) escape sequences are passed through to the terminal.
|