#include <stdarg.h>
#include <inttypes.h>
#include <fcntl.h>
+#include <termios.h>
#include <netinet/in.h>
}
return i;
}
+
+void
+cmdline_interact(struct cmdline *cl)
+{
+ char c;
+
+ c = -1;
+ while (1) {
+ read(cl->s_in, &c, 1);
+ if (cmdline_in(cl, &c, 1) < 0) {
+ break;
+ }
+ }
+ cmdline_free(cl);
+}
cmdline_parse_ctx_t *ctx;
struct rdline rdl;
char prompt[RDLINE_PROMPT_SIZE];
+#ifdef CMDLINE_TERMIOS
+ struct termios oldterm;
+#endif
};
struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
void cmdline_printf(const struct cmdline *cl, const char *fmt, ...);
int cmdline_in(struct cmdline *cl, const char *buf, int size);
void cmdline_write_char(struct rdline *rdl, char c);
+void cmdline_interact(struct cmdline *cl);
#endif /* _CMDLINE_SOCKET_H_ */
#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
}
struct cmdline *cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path);
struct cmdline *cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt);
+void cmdline_stdin_exit(struct cmdline *cl);
#endif /* _CMDLINE_SOCKET_H_ */