IUTF8 is needed to handle line editing correctly in utf-8 mode. On virtual terminals kernel sets this flag automatically if utf8 mode is active (the default).
Unfortunately the "stty sane" will remove this flag by documentation, so add support to keep it enabled if it was set. Signed-off-by: Timo Teräs <[email protected]> --- console-tools/reset.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/console-tools/reset.c b/console-tools/reset.c index cc04e4fcc..456efac4a 100644 --- a/console-tools/reset.c +++ b/console-tools/reset.c @@ -27,17 +27,31 @@ #include "libbb.h" +#ifndef IUTF8 +# define IUTF8 0 +#endif + #define ESC "\033" #if ENABLE_STTY int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; #endif +static int is_utf8(void) +{ +#if IUTF8 + struct termios mode; + if (tcgetattr(STDIN_FILENO, &mode) == 0) + return mode.c_iflag & IUTF8; +#endif + return 0; +} + int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { - static const char *const args[] ALIGN_PTR = { - "stty", "sane", NULL + static const char * args[] ALIGN_PTR = { + "stty", "sane", "iutf8", NULL }; /* no options, no getopt */ @@ -53,11 +67,13 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h"); /* http://bugs.busybox.net/view.php?id=1414: * people want it to reset echo etc: */ + #if ENABLE_STTY - return stty_main(2, (char**)args); + return stty_main(is_utf8() ? 3 : 2, (char**)args); #else /* Make sure stdout gets drained before we execvp */ fflush_all(); + if (!is_utf8()) args[2] = NULL; execvp("stty", (char**)args); #endif } -- 2.36.0 _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
