reset.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 tarball for details.
  9. */
  10. #include "libbb.h"
  11. /* BTW, which "standard" package has this utility? It doesn't seem
  12. * to be ncurses, coreutils, console-tools... then what? */
  13. #if ENABLE_STTY
  14. int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  15. #endif
  16. int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  17. int reset_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
  18. {
  19. static const char *const args[] = {
  20. "stty", "sane", NULL
  21. };
  22. /* no options, no getopt */
  23. if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
  24. /* See 'man 4 console_codes' for details:
  25. * "ESC c" -- Reset
  26. * "ESC ( K" -- Select user mapping
  27. * "ESC [ J" -- Erase display
  28. * "ESC [ 0 m" -- Reset all display attributes
  29. * "ESC [ ? 25 h" -- Make cursor visible.
  30. */
  31. printf("\033c\033(K\033[J\033[0m\033[?25h");
  32. /* http://bugs.busybox.net/view.php?id=1414:
  33. * people want it to reset echo etc: */
  34. #if ENABLE_STTY
  35. return stty_main(2, (char**)args);
  36. #else
  37. execvp("stty", (char**)args);
  38. #endif
  39. }
  40. return EXIT_SUCCESS;
  41. }