| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,55 +0,0 @@ |
| 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 |
Apologies that this uses my preferred formatting style: mostly the same
as Linux, but without a break between function and brace. Adds spaces in
a few places they weren't before.
| ... | ... |
@@ -3,7 +3,7 @@ |
| 3 | 3 |
|
| 4 | 4 |
#include <termios.h> |
| 5 | 5 |
|
| 6 |
-typedef struct{
|
|
| 6 |
+typedef struct {
|
|
| 7 | 7 |
int fdin; |
| 8 | 8 |
FILE *fout; |
| 9 | 9 |
struct termios original_termios; |
| ... | ... |
@@ -22,15 +22,15 @@ void tty_setfg(tty_t *tty, int fg); |
| 22 | 22 |
void tty_setinvert(tty_t *tty); |
| 23 | 23 |
void tty_setnormal(tty_t *tty); |
| 24 | 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 |
|
| 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 | 30 |
#define TTY_COLOR_MAGENTA 5 |
| 31 |
-#define TTY_COLOR_CYAN 6 |
|
| 32 |
-#define TTY_COLOR_WHITE 7 |
|
| 33 |
-#define TTY_COLOR_NORMAL 9 |
|
| 31 |
+#define TTY_COLOR_CYAN 6 |
|
| 32 |
+#define TTY_COLOR_WHITE 7 |
|
| 33 |
+#define TTY_COLOR_NORMAL 9 |
|
| 34 | 34 |
|
| 35 | 35 |
/* tty_newline |
| 36 | 36 |
* Move cursor to the beginning of the next line, clearing to the end of the |
Still needs to be fixed on an exit due to ^C
Thanks @rtandy
| ... | ... |
@@ -9,6 +9,7 @@ typedef struct{
|
| 9 | 9 |
struct termios original_termios; |
| 10 | 10 |
int fgcolor; |
| 11 | 11 |
size_t maxwidth; |
| 12 |
+ size_t maxheight; |
|
| 12 | 13 |
} tty_t; |
| 13 | 14 |
|
| 14 | 15 |
void tty_reset(tty_t *tty); |
| ... | ... |
@@ -48,5 +49,6 @@ void tty_printf(tty_t *tty, const char *fmt, ...); |
| 48 | 49 |
void tty_flush(tty_t *tty); |
| 49 | 50 |
|
| 50 | 51 |
size_t tty_getwidth(tty_t *tty); |
| 52 |
+size_t tty_getheight(tty_t *tty); |
|
| 51 | 53 |
|
| 52 | 54 |
#endif |
| ... | ... |
@@ -8,10 +8,12 @@ typedef struct{
|
| 8 | 8 |
FILE *fout; |
| 9 | 9 |
struct termios original_termios; |
| 10 | 10 |
int fgcolor; |
| 11 |
+ size_t maxwidth; |
|
| 11 | 12 |
} tty_t; |
| 12 | 13 |
|
| 13 | 14 |
void tty_reset(tty_t *tty); |
| 14 | 15 |
void tty_init(tty_t *tty, const char *tty_filename); |
| 16 |
+void tty_getwinsz(tty_t *tty); |
|
| 15 | 17 |
char tty_getchar(tty_t *tty); |
| 16 | 18 |
|
| 17 | 19 |
void tty_setfg(tty_t *tty, int fg); |
| ... | ... |
@@ -45,4 +47,6 @@ void tty_setcol(tty_t *tty, int col); |
| 45 | 47 |
void tty_printf(tty_t *tty, const char *fmt, ...); |
| 46 | 48 |
void tty_flush(tty_t *tty); |
| 47 | 49 |
|
| 50 |
+size_t tty_getwidth(tty_t *tty); |
|
| 51 |
+ |
|
| 48 | 52 |
#endif |
| ... | ... |
@@ -34,6 +34,11 @@ void tty_setnormal(tty_t *tty); |
| 34 | 34 |
*/ |
| 35 | 35 |
void tty_newline(tty_t *tty); |
| 36 | 36 |
|
| 37 |
+/* tty_clearline |
|
| 38 |
+ * Clear to the end of the current line without advancing the cursor. |
|
| 39 |
+ */ |
|
| 40 |
+void tty_clearline(tty_t *tty); |
|
| 41 |
+ |
|
| 37 | 42 |
void tty_moveup(tty_t *tty, int i); |
| 38 | 43 |
void tty_setcol(tty_t *tty, int col); |
| 39 | 44 |
|
| ... | ... |
@@ -28,6 +28,14 @@ void tty_setnormal(tty_t *tty); |
| 28 | 28 |
#define TTY_COLOR_WHITE 7 |
| 29 | 29 |
#define TTY_COLOR_NORMAL 9 |
| 30 | 30 |
|
| 31 |
+/* tty_newline |
|
| 32 |
+ * Move cursor to the beginning of the next line, clearing to the end of the |
|
| 33 |
+ * current line |
|
| 34 |
+ */ |
|
| 35 |
+void tty_newline(tty_t *tty); |
|
| 36 |
+ |
|
| 37 |
+void tty_setcol(tty_t *tty, int col); |
|
| 38 |
+ |
|
| 31 | 39 |
void tty_printf(tty_t *tty, const char *fmt, ...); |
| 32 | 40 |
|
| 33 | 41 |
#endif |
| ... | ... |
@@ -18,5 +18,14 @@ void tty_setfg(tty_t *tty, int fg); |
| 18 | 18 |
void tty_setinvert(tty_t *tty); |
| 19 | 19 |
void tty_setnormal(tty_t *tty); |
| 20 | 20 |
|
| 21 |
+#define TTY_COLOR_BLACK 0 |
|
| 22 |
+#define TTY_COLOR_RED 1 |
|
| 23 |
+#define TTY_COLOR_GREEN 2 |
|
| 24 |
+#define TTY_COLOR_YELLOW 3 |
|
| 25 |
+#define TTY_COLOR_BLUE 4 |
|
| 26 |
+#define TTY_COLOR_MAGENTA 5 |
|
| 27 |
+#define TTY_COLOR_CYAN 6 |
|
| 28 |
+#define TTY_COLOR_WHITE 7 |
|
| 29 |
+#define TTY_COLOR_NORMAL 9 |
|
| 21 | 30 |
|
| 22 | 31 |
#endif |
| ... | ... |
@@ -7,10 +7,16 @@ typedef struct{
|
| 7 | 7 |
int fdin; |
| 8 | 8 |
FILE *fout; |
| 9 | 9 |
struct termios original_termios; |
| 10 |
+ int fgcolor; |
|
| 10 | 11 |
} tty_t; |
| 11 | 12 |
|
| 12 | 13 |
void tty_reset(tty_t *tty); |
| 13 | 14 |
void tty_init(tty_t *tty); |
| 14 | 15 |
char tty_getchar(tty_t *tty); |
| 15 | 16 |
|
| 17 |
+void tty_setfg(tty_t *tty, int fg); |
|
| 18 |
+void tty_setinvert(tty_t *tty); |
|
| 19 |
+void tty_setnormal(tty_t *tty); |
|
| 20 |
+ |
|
| 21 |
+ |
|
| 16 | 22 |
#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,16 @@ |
| 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 |
+} tty_t; |
|
| 11 |
+ |
|
| 12 |
+void tty_reset(tty_t *tty); |
|
| 13 |
+void tty_init(tty_t *tty); |
|
| 14 |
+char tty_getchar(tty_t *tty); |
|
| 15 |
+ |
|
| 16 |
+#endif |