reset.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. //usage:#define reset_trivial_usage
  13. //usage: ""
  14. //usage:#define reset_full_usage "\n\n"
  15. //usage: "Reset the screen"
  16. #include "libbb.h"
  17. #define ESC "\033"
  18. #if ENABLE_STTY
  19. int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  20. #endif
  21. int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  22. int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  23. {
  24. static const char *const args[] = {
  25. "stty", "sane", NULL
  26. };
  27. /* no options, no getopt */
  28. if (/*isatty(STDIN_FILENO) &&*/ isatty(STDOUT_FILENO)) {
  29. /* See 'man 4 console_codes' for details:
  30. * "ESC c" -- Reset
  31. * "ESC ( B" -- Select G0 Character Set (B = US)
  32. * "ESC [ 0 m" -- Reset all display attributes
  33. * "ESC [ J" -- Erase to the end of screen
  34. * "ESC [ ? 25 h" -- Make cursor visible
  35. */
  36. printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h");
  37. /* http://bugs.busybox.net/view.php?id=1414:
  38. * people want it to reset echo etc: */
  39. #if ENABLE_STTY
  40. return stty_main(2, (char**)args);
  41. #else
  42. execvp("stty", (char**)args);
  43. #endif
  44. }
  45. return EXIT_SUCCESS;
  46. }