aboutsummaryrefslogtreecommitdiffstats
path: root/pw.c
diff options
context:
space:
mode:
Diffstat (limited to 'pw.c')
-rw-r--r--pw.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/pw.c b/pw.c
index f3c4c34..eb4c425 100644
--- a/pw.c
+++ b/pw.c
@@ -13,6 +13,7 @@
#include <sys/time.h>
#include <fcntl.h>
#include <errno.h>
+#include <signal.h>
#include <regex.h>
#define ctrl(ch) ((ch) & 0x1f)
@@ -396,6 +397,18 @@ static void execute(char *cmd, unsigned *pstat)
fflush(stdout);
}
+static void ttyset(int fd, struct termios *tty)
+{
+ if (tcsetattr(fd, TCSANOW, tty) < 0)
+ panic("unable to set TTY parameters");
+}
+
+static void ttyget(int fd, struct termios *tty)
+{
+ if (tcgetattr(fd, tty) < 0)
+ panic("unable to get TTY parameters");
+}
+
int main(int argc, char **argv)
{
char *line = 0;
@@ -471,8 +484,7 @@ int main(int argc, char **argv)
columns = ws.ws_col;
}
- if (tcgetattr(ttyfd, &tty_saved) < 0)
- panic("unable to get TTY parameters");
+ ttyget(ttyfd, &tty_saved);
tty_new = tty_saved;
@@ -483,8 +495,7 @@ int main(int argc, char **argv)
tty_new.c_cc[VMIN] = 1;
tty_new.c_cc[VTIME] = 0;
- if (tcsetattr(ttyfd, TCSANOW, &tty_new) < 0)
- panic("unable to set TTY parameters");
+ ttyset(ttyfd, &tty_new);
setvbuf(tty, NULL, _IONBF, 0);
@@ -614,6 +625,17 @@ int main(int argc, char **argv)
if ((pe[0].revents)) {
int ch = getc(tty);
+ if (ch == ctrl('z')) {
+ ttyset(ttyfd, &tty_saved);
+ kill(0, SIGTSTP);
+ ttyset(ttyfd, &tty_new);
+ for (int i = 0; i < nlines; i++)
+ puts("");
+ redraw(circbuf, nlines, hpos, columns, stat, curcmd);
+ stat &= ~stat_dirty;
+ continue;
+ }
+
fakecmd:
switch (kbd_state) {
case kbd_result:
@@ -847,7 +869,6 @@ int main(int argc, char **argv)
}
}
- if (tcsetattr(ttyfd, TCSANOW, &tty_saved) < 0)
- panic("unable to restore TTY parameters");
+ ttyset(ttyfd, &tty_saved);
return exit_status;
}