Browse code

Move sources into src directory

John Hawthorn authored on 21/05/2016 21:56:03
Showing 1 changed files
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
Browse code

Apply clang-format to all files

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.

John Hawthorn authored on 07/11/2015 05:45:02
Showing 1 changed files
... ...
@@ -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
Browse code

termios should be reset on successful exit.

Still needs to be fixed on an exit due to ^C

Thanks @rtandy

John Hawthorn authored on 19/10/2014 23:19:24
Showing 1 changed files
... ...
@@ -13,6 +13,7 @@ typedef struct{
13 13
 } tty_t;
14 14
 
15 15
 void tty_reset(tty_t *tty);
16
+void tty_close(tty_t *tty);
16 17
 void tty_init(tty_t *tty, const char *tty_filename);
17 18
 void tty_getwinsz(tty_t *tty);
18 19
 char tty_getchar(tty_t *tty);
Browse code

Cap max lines at terminal height

John Hawthorn authored on 17/09/2014 02:13:41
Showing 1 changed files
... ...
@@ -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
Browse code

Truncate matches at terminal width

John Hawthorn authored on 15/09/2014 07:07:18
Showing 1 changed files
... ...
@@ -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
Browse code

Add -t,--tty

John Hawthorn authored on 14/09/2014 03:55:33
Showing 1 changed files
... ...
@@ -11,7 +11,7 @@ typedef struct{
11 11
 } tty_t;
12 12
 
13 13
 void tty_reset(tty_t *tty);
14
-void tty_init(tty_t *tty);
14
+void tty_init(tty_t *tty, const char *tty_filename);
15 15
 char tty_getchar(tty_t *tty);
16 16
 
17 17
 void tty_setfg(tty_t *tty, int fg);
Browse code

Use last line of terminal

John Hawthorn authored on 31/08/2014 02:11:18
Showing 1 changed files
... ...
@@ -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
 
Browse code

tty_flush

John Hawthorn authored on 17/08/2014 03:34:16
Showing 1 changed files
... ...
@@ -38,5 +38,6 @@ void tty_moveup(tty_t *tty, int i);
38 38
 void tty_setcol(tty_t *tty, int col);
39 39
 
40 40
 void tty_printf(tty_t *tty, const char *fmt, ...);
41
+void tty_flush(tty_t *tty);
41 42
 
42 43
 #endif
Browse code

Refactor into tty_moveup

John Hawthorn authored on 17/08/2014 03:33:24
Showing 1 changed files
... ...
@@ -34,6 +34,7 @@ void tty_setnormal(tty_t *tty);
34 34
  */
35 35
 void tty_newline(tty_t *tty);
36 36
 
37
+void tty_moveup(tty_t *tty, int i);
37 38
 void tty_setcol(tty_t *tty, int col);
38 39
 
39 40
 void tty_printf(tty_t *tty, const char *fmt, ...);
Browse code

Refactor into tty_newline and tty_setcol

John Hawthorn authored on 17/08/2014 03:31:11
Showing 1 changed files
... ...
@@ -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
Browse code

Refactor into tty_printf

John Hawthorn authored on 17/08/2014 03:20:09
Showing 1 changed files
... ...
@@ -28,4 +28,6 @@ void tty_setnormal(tty_t *tty);
28 28
 #define TTY_COLOR_WHITE   7
29 29
 #define TTY_COLOR_NORMAL  9
30 30
 
31
+void tty_printf(tty_t *tty, const char *fmt, ...);
32
+
31 33
 #endif
Browse code

Define ANSI color values

John Hawthorn authored on 04/08/2014 08:01:43
Showing 1 changed files
... ...
@@ -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
Browse code

Extract ANSI CSI SGR calls into tty.c

John Hawthorn authored on 04/08/2014 07:08:10
Showing 1 changed files
... ...
@@ -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
Browse code

Split tty functions into tty.c

John Hawthorn authored on 04/08/2014 04:56:17
Showing 1 changed files
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