aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/interestingtimes.c9
-rw-r--r--lib/lib.h1
-rw-r--r--toys/other/reset.c23
-rw-r--r--toys/pending/reset.c34
4 files changed, 33 insertions, 34 deletions
diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c
index cea5039f..85b8eb4c 100644
--- a/lib/interestingtimes.c
+++ b/lib/interestingtimes.c
@@ -5,6 +5,15 @@
#include "toys.h"
+int xgettty(void)
+{
+ int i, j;
+
+ for (i = 0; i<3; i++) if (isatty(j = (i+1)%3)) return j;
+
+ return xopen("/dev/tty", O_RDWR);
+}
+
// Quick and dirty query size of terminal, doesn't do ANSI probe fallback.
// set x=80 y=25 before calling to provide defaults. Returns 0 if couldn't
// determine size.
diff --git a/lib/lib.h b/lib/lib.h
index 03a05703..54876b6a 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -181,6 +181,7 @@ int qstrcmp(const void *a, const void *b);
int xpoll(struct pollfd *fds, int nfds, int timeout);
// interestingtimes.c
+int xgettty(void);
int terminal_size(unsigned *xx, unsigned *yy);
int set_terminal(int fd, int raw, struct termios *old);
int scan_key(char *scratch, char **seqs, int block);
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);
-}