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