#include <stdarg.h>
#include <inttypes.h>
#include <fcntl.h>
+#include <termios.h>
#ifndef CMDLINE_NO_SOCKET
#include <sys/socket.h>
struct cmdline *
cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt)
{
- return (cmdline_new(ctx, prompt, 0, 1));
+ struct cmdline *cl;
+#ifdef CMDLINE_TERMIOS
+ struct termios oldterm, term;
+
+ tcgetattr(0, &oldterm);
+ memcpy(&term, &oldterm, sizeof(term));
+ term.c_lflag &= ~(ICANON | ECHO | ISIG);
+ tcsetattr(0, TCSANOW, &term);
+ setbuf(stdin, NULL);
+#endif
+
+ cl = cmdline_new(ctx, prompt, 0, 1);
+
+#ifdef CMDLINE_TERMIOS
+ memcpy(&cl->oldterm, &oldterm, sizeof(term));
+#endif
+ return cl;
+}
+
+void
+cmdline_stdin_exit(struct cmdline *cl)
+{
+#ifdef CMDLINE_TERMIOS
+ tcsetattr(fileno(stdin), TCSANOW, &cl->oldterm);
+#else
+ /* silent the compiler */
+ cl = cl;
+#endif
}