xref: /libuv/docs/code/tty/main.c (revision e8458b24)
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <uv.h>
5 
6 uv_loop_t *loop;
7 uv_tty_t tty;
8 
main()9 int main() {
10     uv_write_t req;
11     uv_buf_t buf;
12     uv_write_t req1;
13     uv_buf_t buf1;
14 
15     loop = uv_default_loop();
16     uv_tty_init(loop, &tty, STDOUT_FILENO, 0);
17     uv_tty_set_mode(&tty, UV_TTY_MODE_NORMAL);
18 
19     if (uv_guess_handle(1) == UV_TTY) {
20         buf1.base = "\033[41;37m";
21         buf1.len = strlen(buf1.base);
22         uv_write(&req1, (uv_stream_t*) &tty, &buf1, 1, NULL);
23     }
24 
25     buf.base = "Hello TTY\n";
26     buf.len = strlen(buf.base);
27     uv_write(&req, (uv_stream_t*) &tty, &buf, 1, NULL);
28 
29     uv_tty_reset_mode();
30     return uv_run(loop, UV_RUN_DEFAULT);
31 }
32