shithub: 9pro

Download patch

ref: 2c04a0e19502f52f930a9f0cd2f05cef71e60e17
parent: 409a73bf85cb00e2e7a9bb8d6abdf9168fba9259
author: Sigrid Haflínudóttir <[email protected]>
date: Tue May 19 14:26:00 EDT 2020

9gc: add -e to disable echo

--- a/9gc.c
+++ b/9gc.c
@@ -10,6 +10,7 @@
 #include <sys/select.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <termios.h>
 #include <unistd.h>
 #include "c9.h"
 #include "parg.h"
@@ -370,11 +371,12 @@
 main(int argc, char **argv)
 {
 	struct parg_state ps;
+	struct termios t;
 	C9aux *a;
-	int c;
+	int c, noecho;
 
 	parg_init(&ps);
-
+	noecho = 0;
 	while ((c = parg_getopt(&ps, argc, argv, "dh")) >= 0) {
 		switch (c) {
 		case 1:
@@ -387,8 +389,11 @@
 		case 'j':
 			printjoin = 1;
 			break;
+		case 'e':
+			noecho = 1;
+			break;
 		case 'h':
-			fprintf(stderr, "usage: 9gc NICKNAME\n");
+			fprintf(stderr, "usage: 9gc [-j] [-e] NICKNAME\n");
 			return 0;
 			break;
 		case '?':
@@ -409,6 +414,11 @@
 
 	if ((a = registry()) == NULL)
 		return 1;
+	if (noecho && tcgetattr(0, &t) == 0) {
+		t.c_lflag &= ~ECHO;
+		tcsetattr(STDIN_FILENO, TCSANOW, &t);
+	}
+
 	while (chatrw(a) == 0 && wrsend(a) == 0);
 
 	return 0;