aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-05-14 13:43:01 -0500
committerRob Landley <rob@landley.net>2015-05-14 13:43:01 -0500
commit5b2644cafc8a619b617ba0fbb5473667dbd634ba (patch)
treeeeec75be235b699d55875560df8595545d14fd9c /toys
parent5ea14bd1c246f7571d466d18385db22f59ac3262 (diff)
downloadtoybox-5b2644cafc8a619b617ba0fbb5473667dbd634ba.tar.gz
Promote reset (actually write a new one using the simple man 4 console_codes
terminal reset escape sequence) and add gettty() function to lib so terminal gets reset even when we redirect stdout/stderr. (This is apparently the expected behavior.)
Diffstat (limited to 'toys')
-rw-r--r--toys/other/reset.c23
-rw-r--r--toys/pending/reset.c34
2 files changed, 23 insertions, 34 deletions
diff --git a/toys/other/reset.c b/toys/other/reset.c
new file mode 100644
index 00000000..0c2089cc
--- /dev/null
+++ b/toys/other/reset.c
@@ -0,0 +1,23 @@
+/* reset.c - reset the terminal.
+ *
+ * Copyright 2015 Rob Landley <rob@landley.net>
+ *
+ * No standard.
+
+USE_RESET(NEWTOY(reset, 0, TOYFLAG_USR|TOYFLAG_BIN))
+
+config RESET
+ bool "reset"
+ default y
+ help
+ usage: reset
+
+ reset the terminal
+*/
+#include "toys.h"
+
+void reset_main(void)
+{
+ // man 4 console codes: reset terminal is ESC (no left bracket) c
+ xwrite(xgettty(), "\033c", 2);
+}
diff --git a/toys/pending/reset.c b/toys/pending/reset.c
deleted file mode 100644
index a12f0b61..00000000
--- a/toys/pending/reset.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* reset.c - A program to reset the terminal.
- *
- * Copyright 2014 Ashwini Kumar <ak.ashwini@gmail.com>
- * Copyright 2014 Kyungwan Han <asura321@gmail.com>
- *
- * No Standard.
-
-USE_RESET(NEWTOY(reset, NULL, TOYFLAG_USR|TOYFLAG_BIN))
-
-config RESET
- bool "reset"
- default n
- help
- usage: reset
-
- A program to reset the terminal.
-*/
-#define FOR_reset
-#include "toys.h"
-
-void reset_main(void)
-{
- char *args[] = {"stty", "sane", NULL};
-
- /* \033c - reset the terminal with default setting
- * \033(B - set the G0 character set (B=US)
- * \033[2J - clear the whole screen
- * \033[0m - Reset all attributes
- */
- if (isatty(1)) xprintf("\033c\033(B\033[0m\033[J\033[?25h");
- fflush(stdout);
- // set the terminal to sane settings
- xexec(args);
-}