| ... | ... |
@@ -1,8 +1,14 @@ |
| 1 | 1 |
#ifndef TTY_H |
| 2 | 2 |
#define TTY_H TTY_H |
| 3 | 3 |
|
| 4 |
+#include <stddef.h> |
|
| 5 |
+#include <stdio.h> |
|
| 4 | 6 |
#include <termios.h> |
| 5 | 7 |
|
| 8 |
+#ifdef __cplusplus |
|
| 9 |
+extern "C" {
|
|
| 10 |
+#endif |
|
| 11 |
+ |
|
| 6 | 12 |
typedef struct {
|
| 7 | 13 |
int fdin; |
| 8 | 14 |
FILE *fout; |
| ... | ... |
@@ -57,4 +63,8 @@ void tty_flush(tty_t *tty); |
| 57 | 63 |
size_t tty_getwidth(tty_t *tty); |
| 58 | 64 |
size_t tty_getheight(tty_t *tty); |
| 59 | 65 |
|
| 66 |
+#ifdef __cplusplus |
|
| 67 |
+} |
|
| 68 |
+#endif |
|
| 69 |
+ |
|
| 60 | 70 |
#endif |
Update tty to print newline as space
Add tty_putc
| ... | ... |
@@ -17,7 +17,7 @@ void tty_close(tty_t *tty); |
| 17 | 17 |
void tty_init(tty_t *tty, const char *tty_filename); |
| 18 | 18 |
void tty_getwinsz(tty_t *tty); |
| 19 | 19 |
char tty_getchar(tty_t *tty); |
| 20 |
-int tty_input_ready(tty_t *tty, int timeout, int return_on_signal); |
|
| 20 |
+int tty_input_ready(tty_t *tty, long int timeout, int return_on_signal); |
|
| 21 | 21 |
|
| 22 | 22 |
void tty_setfg(tty_t *tty, int fg); |
| 23 | 23 |
void tty_setinvert(tty_t *tty); |
| ... | ... |
@@ -17,7 +17,7 @@ void tty_close(tty_t *tty); |
| 17 | 17 |
void tty_init(tty_t *tty, const char *tty_filename); |
| 18 | 18 |
void tty_getwinsz(tty_t *tty); |
| 19 | 19 |
char tty_getchar(tty_t *tty); |
| 20 |
-int tty_input_ready(tty_t *tty, unsigned long timeout); |
|
| 20 |
+int tty_input_ready(tty_t *tty, int timeout, int return_on_signal); |
|
| 21 | 21 |
|
| 22 | 22 |
void tty_setfg(tty_t *tty, int fg); |
| 23 | 23 |
void tty_setinvert(tty_t *tty); |
| ... | ... |
@@ -17,7 +17,7 @@ void tty_close(tty_t *tty); |
| 17 | 17 |
void tty_init(tty_t *tty, const char *tty_filename); |
| 18 | 18 |
void tty_getwinsz(tty_t *tty); |
| 19 | 19 |
char tty_getchar(tty_t *tty); |
| 20 |
-int tty_input_ready(tty_t *tty, int pending); |
|
| 20 |
+int tty_input_ready(tty_t *tty, unsigned long timeout); |
|
| 21 | 21 |
|
| 22 | 22 |
void tty_setfg(tty_t *tty, int fg); |
| 23 | 23 |
void tty_setinvert(tty_t *tty); |
| ... | ... |
@@ -23,6 +23,8 @@ void tty_setfg(tty_t *tty, int fg); |
| 23 | 23 |
void tty_setinvert(tty_t *tty); |
| 24 | 24 |
void tty_setunderline(tty_t *tty); |
| 25 | 25 |
void tty_setnormal(tty_t *tty); |
| 26 |
+void tty_setnowrap(tty_t *tty); |
|
| 27 |
+void tty_setwrap(tty_t *tty); |
|
| 26 | 28 |
|
| 27 | 29 |
#define TTY_COLOR_BLACK 0 |
| 28 | 30 |
#define TTY_COLOR_RED 1 |
| ... | ... |
@@ -17,7 +17,7 @@ void tty_close(tty_t *tty); |
| 17 | 17 |
void tty_init(tty_t *tty, const char *tty_filename); |
| 18 | 18 |
void tty_getwinsz(tty_t *tty); |
| 19 | 19 |
char tty_getchar(tty_t *tty); |
| 20 |
-int tty_input_ready(tty_t *tty); |
|
| 20 |
+int tty_input_ready(tty_t *tty, int pending); |
|
| 21 | 21 |
|
| 22 | 22 |
void tty_setfg(tty_t *tty, int fg); |
| 23 | 23 |
void tty_setinvert(tty_t *tty); |
| ... | ... |
@@ -17,6 +17,7 @@ void tty_close(tty_t *tty); |
| 17 | 17 |
void tty_init(tty_t *tty, const char *tty_filename); |
| 18 | 18 |
void tty_getwinsz(tty_t *tty); |
| 19 | 19 |
char tty_getchar(tty_t *tty); |
| 20 |
+int tty_input_ready(tty_t *tty); |
|
| 20 | 21 |
|
| 21 | 22 |
void tty_setfg(tty_t *tty, int fg); |
| 22 | 23 |
void tty_setinvert(tty_t *tty); |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,55 @@ |
| 1 |
+#ifndef TTY_H |
|
| 2 |
+#define TTY_H TTY_H |
|
| 3 |
+ |
|
| 4 |
+#include <termios.h> |
|
| 5 |
+ |
|
| 6 |
+typedef struct {
|
|
| 7 |
+ int fdin; |
|
| 8 |
+ FILE *fout; |
|
| 9 |
+ struct termios original_termios; |
|
| 10 |
+ int fgcolor; |
|
| 11 |
+ size_t maxwidth; |
|
| 12 |
+ size_t maxheight; |
|
| 13 |
+} tty_t; |
|
| 14 |
+ |
|
| 15 |
+void tty_reset(tty_t *tty); |
|
| 16 |
+void tty_close(tty_t *tty); |
|
| 17 |
+void tty_init(tty_t *tty, const char *tty_filename); |
|
| 18 |
+void tty_getwinsz(tty_t *tty); |
|
| 19 |
+char tty_getchar(tty_t *tty); |
|
| 20 |
+ |
|
| 21 |
+void tty_setfg(tty_t *tty, int fg); |
|
| 22 |
+void tty_setinvert(tty_t *tty); |
|
| 23 |
+void tty_setnormal(tty_t *tty); |
|
| 24 |
+ |
|
| 25 |
+#define TTY_COLOR_BLACK 0 |
|
| 26 |
+#define TTY_COLOR_RED 1 |
|
| 27 |
+#define TTY_COLOR_GREEN 2 |
|
| 28 |
+#define TTY_COLOR_YELLOW 3 |
|
| 29 |
+#define TTY_COLOR_BLUE 4 |
|
| 30 |
+#define TTY_COLOR_MAGENTA 5 |
|
| 31 |
+#define TTY_COLOR_CYAN 6 |
|
| 32 |
+#define TTY_COLOR_WHITE 7 |
|
| 33 |
+#define TTY_COLOR_NORMAL 9 |
|
| 34 |
+ |
|
| 35 |
+/* tty_newline |
|
| 36 |
+ * Move cursor to the beginning of the next line, clearing to the end of the |
|
| 37 |
+ * current line |
|
| 38 |
+ */ |
|
| 39 |
+void tty_newline(tty_t *tty); |
|
| 40 |
+ |
|
| 41 |
+/* tty_clearline |
|
| 42 |
+ * Clear to the end of the current line without advancing the cursor. |
|
| 43 |
+ */ |
|
| 44 |
+void tty_clearline(tty_t *tty); |
|
| 45 |
+ |
|
| 46 |
+void tty_moveup(tty_t *tty, int i); |
|
| 47 |
+void tty_setcol(tty_t *tty, int col); |
|
| 48 |
+ |
|
| 49 |
+void tty_printf(tty_t *tty, const char *fmt, ...); |
|
| 50 |
+void tty_flush(tty_t *tty); |
|
| 51 |
+ |
|
| 52 |
+size_t tty_getwidth(tty_t *tty); |
|
| 53 |
+size_t tty_getheight(tty_t *tty); |
|
| 54 |
+ |
|
| 55 |
+#endif |