Home | History | Annotate | Line # | Download | only in tty
main.c revision 1.1
      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  christos int main() {
      9  1.1  christos     loop = uv_default_loop();
     10  1.1  christos 
     11  1.1  christos     uv_tty_init(loop, &tty, STDOUT_FILENO, 0);
     12  1.1  christos     uv_tty_set_mode(&tty, UV_TTY_MODE_NORMAL);
     13  1.1  christos 
     14  1.1  christos     if (uv_guess_handle(1) == UV_TTY) {
     15  1.1  christos         uv_write_t req;
     16  1.1  christos         uv_buf_t buf;
     17  1.1  christos         buf.base = "\033[41;37m";
     18  1.1  christos         buf.len = strlen(buf.base);
     19  1.1  christos         uv_write(&req, (uv_stream_t*) &tty, &buf, 1, NULL);
     20  1.1  christos     }
     21  1.1  christos 
     22  1.1  christos     uv_write_t req;
     23  1.1  christos     uv_buf_t buf;
     24  1.1  christos     buf.base = "Hello TTY\n";
     25  1.1  christos     buf.len = strlen(buf.base);
     26  1.1  christos     uv_write(&req, (uv_stream_t*) &tty, &buf, 1, NULL);
     27  1.1  christos     uv_tty_reset_mode();
     28  1.1  christos     return uv_run(loop, UV_RUN_DEFAULT);
     29  1.1  christos }
     30