summary refs log tree commit diff
path: root/curtis
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xcurtis/.bin/hnel.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/curtis/.bin/hnel.c b/curtis/.bin/hnel.c
index 2f00711a..bb087df1 100755
--- a/curtis/.bin/hnel.c
+++ b/curtis/.bin/hnel.c
@@ -2,7 +2,7 @@
 exec cc -Wall -Wextra -pedantic $@ -lutil -o $(dirname $0)/hnel $0
 #endif
 
-// Wrapper for preserving HJKL in Tarmak layouts.
+// PTY wrapper for preserving HJKL in Tarmak layouts.
 
 #include <err.h>
 #include <poll.h>
@@ -38,6 +38,7 @@ static void restoreTerm(void) {
 
 int main(int argc, char *argv[]) {
     int error;
+
     if (argc < 2) return EX_USAGE;
 
     char table[256] = {0};
@@ -46,9 +47,18 @@ int main(int argc, char *argv[]) {
     table['j'] = 'e'; table['J'] = 'E'; table[CTRL('J')] = CTRL('E');
     table['k'] = 'n'; table['K'] = 'N'; table[CTRL('K')] = CTRL('N');
 
+    error = tcgetattr(STDERR_FILENO, &saveTerm);
+    if (error) err(EX_IOERR, "tcgetattr");
+    atexit(restoreTerm);
+
+    struct termios raw;
+    cfmakeraw(&raw);
+    error = tcsetattr(STDERR_FILENO, TCSADRAIN, &raw);
+    if (error) err(EX_IOERR, "tcsetattr");
+
     struct winsize window;
     error = ioctl(STDERR_FILENO, TIOCGWINSZ, &window);
-    if (error) err(EX_IOERR, "ioctl");
+    if (error) err(EX_IOERR, "ioctl(%d, TIOCGWINSZ)", STDERR_FILENO);
 
     int master;
     pid_t pid = forkpty(&master, NULL, NULL, &window);
@@ -59,23 +69,14 @@ int main(int argc, char *argv[]) {
         err(EX_OSERR, "%s", argv[1]);
     }
 
-    error = tcgetattr(STDERR_FILENO, &saveTerm);
-    if (error) err(EX_IOERR, "tcgetattr");
-    atexit(restoreTerm);
-
-    struct termios raw;
-    cfmakeraw(&raw);
-    error = tcsetattr(STDERR_FILENO, TCSADRAIN, &raw);
-    if (error) err(EX_IOERR, "tcsetattr");
-
     struct pollfd fds[2] = {
         { .fd = STDIN_FILENO, .events = POLLIN },
         { .fd = master, .events = POLLIN },
     };
-
-    char buf[4096];
-    ssize_t len;
     while (0 < poll(fds, 2, -1)) {
+        char buf[4096];
+        ssize_t len;
+
         if (fds[0].revents) {
             len = read(STDIN_FILENO, buf, sizeof(buf));
             if (len < 0) err(EX_IOERR, "read(%d)", STDIN_FILENO);
msg'> 2019-09-28Add The Black Tides of HeavenJune McEnroe 2019-09-27Fail on HTTP failure status in titleJune McEnroe 2019-09-23Add Trail of LightningJune McEnroe 2019-09-22Revert "Enable cookies in title"June McEnroe This reverts commit 3231fe21d3b389448c9a5ca7b4c91fdd25c9e677. 2019-09-20Enable cookies in titleJune McEnroe Perhaps this will make it less suspicious to Google. Who knows. 2019-09-16Use sensitivity aliases in TF2June McEnroe 2019-09-16Add The Just CityJune McEnroe 2019-09-12Only GET the final redirect locationJune McEnroe 2019-09-12Consume entire bodyJune McEnroe Aborting the request and leaving data around may be causing intermittent errors. Just discard the rest of the data. 2019-09-10Add title -v flagJune McEnroe 2019-09-10Use curl error bufferJune McEnroe 2019-09-10Set Accept-Encoding in titleJune McEnroe Because apparently it's fine for servers to respond with Content-Encoding you didn't ask for, and curl won't decode it if you didn't ask for it. 2019-09-08Set title User-AgentJune McEnroe Some things don't like you if you don't send one. 2019-09-07Add -x flag to titleJune McEnroe 2019-09-07Ignore SIGPIPE in relayJune McEnroe Allows restarting consumers safely. 2019-09-07Add A Memory Called EmpireJune McEnroe 2019-09-05Handle lack of Content-TypeJune McEnroe 2019-09-05Use CURLINFO_CONTENT_TYPEJune McEnroe Oops, didn't see this. 2019-09-05Decode entities in titlesJune McEnroe 2019-09-05Print title as soon as it's availableJune McEnroe 2019-09-05Use CURL_PREFIX to set flagsJune McEnroe 2019-09-05Add titleJune McEnroe 2019-09-04Add Avorter n'est pas tuerJune McEnroe 2019-08-29Unset executable on shell scriptsJune McEnroe 2019-08-29Add long-missing setopt to bin.7June McEnroe 2019-08-29Add editJune McEnroe