aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/interestingtimes.c17
-rw-r--r--lib/lib.h1
-rw-r--r--toys/pending/watch.c17
-rw-r--r--toys/posix/ps.c7
4 files changed, 19 insertions, 23 deletions
diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c
index c3ed9f9a..9cf84041 100644
--- a/lib/interestingtimes.c
+++ b/lib/interestingtimes.c
@@ -258,3 +258,20 @@ void tty_sigreset(int i)
tty_reset();
_exit(i ? 128+i : 0);
}
+
+void start_redraw(unsigned *width, unsigned *height)
+{
+ // If never signaled, do raw mode setup.
+ if (!toys.signal) {
+ *width = 80;
+ *height = 25;
+ set_terminal(0, 1, 0, 0);
+ sigatexit(tty_sigreset);
+ xsignal(SIGWINCH, generic_signal);
+ }
+ if (toys.signal != -1) {
+ toys.signal = -1;
+ terminal_probesize(width, height);
+ }
+ xprintf("\033[H\033[J");
+}
diff --git a/lib/lib.h b/lib/lib.h
index 136cdab5..98c042c7 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -293,6 +293,7 @@ void tty_esc(char *s);
void tty_jump(int x, int y);
void tty_reset(void);
void tty_sigreset(int i);
+void start_redraw(unsigned *width, unsigned *height);
// net.c
int xsocket(int domain, int type, int protocol);
diff --git a/toys/pending/watch.c b/toys/pending/watch.c
index f360ac7c..41fb020e 100644
--- a/toys/pending/watch.c
+++ b/toys/pending/watch.c
@@ -32,23 +32,6 @@ GLOBALS(
pid_t pid, oldpid;
)
-void start_redraw(unsigned *width, unsigned *height)
-{
- // If never signaled, do raw mode setup.
- if (!toys.signal) {
- *width = 80;
- *height = 25;
- set_terminal(0, 1, 0, 0);
- sigatexit(tty_sigreset);
- xsignal(SIGWINCH, generic_signal);
- }
- if (toys.signal != -1) {
- toys.signal = -1;
- terminal_probesize(width, height);
- }
- xprintf("\033[H\033[J");
-}
-
// When a child process exits, stop tracking them. Handle errors for -be
void watch_child(int sig)
{
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 27dc63c5..d8f54862 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1709,12 +1709,7 @@ static void top_setup(char *defo, char *defk)
// Grab starting time, make terminal raw, switch off cursor,
// set signal handler to put terminal/cursor back to normal at exit.
TT.time = millitime();
- set_terminal(0, 1, 0, 0);
- sigatexit(tty_sigreset);
- xsignal(SIGWINCH, generic_signal);
- printf("\033[?25l\033[0m");
- TT.width = 80;
- TT.height = 25;
+ start_redraw(&TT.width, &TT.height);
}
comma_args(TT.top.u, &TT.uu, "bad -u", parse_rest);