annotate toys/pending/reset.c @ 1258:fd0a595f5486 draft

A tool to reset the terminal. This implementation depends on the _stty_ 'sane' settings.
author Ashwini Sharma <ak.ashwini1981@gmail.com>
date Sun, 13 Apr 2014 16:07:22 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1258
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
1 /* reset.c - A program to reset the terminal.
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
2 *
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
3 * Copyright 2014 Ashwini Kumar <ak.ashwini@gmail.com>
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Kyungwan Han <asura321@gmail.com>
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
5 *
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
6 * No Standard.
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
7
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
8 USE_RESET(NEWTOY(reset, NULL, TOYFLAG_USR|TOYFLAG_BIN))
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
9
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
10 config RESET
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
11 bool "reset"
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
12 default n
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
13 help
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
14 usage: reset
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
15
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
16 A program to reset the terminal.
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
17 */
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
18 #define FOR_reset
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
19 #include "toys.h"
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
20
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
21 void reset_main(void)
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
22 {
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
23 char *args[] = {"stty", "sane", NULL};
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
24
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
25 /* \033c - reset the terminal with default setting
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
26 * \033(B - set the G0 character set (B=US)
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
27 * \033[2J - clear the whole screen
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
28 * \033[0m - Reset all attributes
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
29 */
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
30 if (isatty(1)) xprintf("\033c\033(B\033[0m\033[J\033[?25h");
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
31 fflush(stdout);
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
32 // set the terminal to sane settings
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
33 xexec(args);
fd0a595f5486 A tool to reset the terminal.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff changeset
34 }