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