3
0

reset.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini reset implementation for busybox
  4. *
  5. * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6. * Written by Erik Andersen and Kent Robotti <robotti@metconnect.com>
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  9. */
  10. /* BTW, which "standard" package has this utility? It doesn't seem
  11. * to be ncurses, coreutils, console-tools... then what? */
  12. #include "libbb.h"
  13. #define ESC "\033"
  14. #if ENABLE_STTY
  15. int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  16. #endif
  17. int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  18. int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  19. {
  20. static const char *const args[] = {
  21. "stty", "sane", NULL
  22. };
  23. /* no options, no getopt */
  24. if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) {
  25. /* See 'man 4 console_codes' for details:
  26. * "ESC c" -- Reset
  27. * "ESC ( K" -- Select user mapping
  28. * "ESC [ 0 m" -- Reset all display attributes
  29. * "ESC [ J" -- Erase to the end of screen
  30. * "ESC [ ? 25 h" -- Make cursor visible
  31. */
  32. printf(ESC"c" ESC"(K" ESC"[0m" ESC"[J" ESC"[?25h");
  33. /* http://bugs.busybox.net/view.php?id=1414:
  34. * people want it to reset echo etc: */
  35. #if ENABLE_STTY
  36. return stty_main(2, (char**)args);
  37. #else
  38. execvp("stty", (char**)args);
  39. #endif
  40. }
  41. return EXIT_SUCCESS;
  42. }