Rizin
unix-like reverse engineering framework and cli tools
main.c
Go to the documentation of this file.
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
uv_timer_t
tick
;
9
uv_write_t
write_req
;
10
int
width
,
height
;
11
int
pos
= 0;
12
char
*
message
=
" Hello TTY "
;
13
14
void
update
(
uv_timer_t
*
req
) {
15
char
data[500];
16
17
uv_buf_t
buf
;
18
buf
.base = data;
19
buf
.len =
sprintf
(data,
"\033[2J\033[H\033[%dB\033[%luC\033[42;37m%s"
,
20
pos
,
21
(
unsigned
long
) (
width
-strlen(
message
))/2,
22
message
);
23
uv_write
(&
write_req
, (
uv_stream_t
*) &
tty
, &
buf
, 1,
NULL
);
24
25
pos
++;
26
if
(
pos
>
height
) {
27
uv_tty_reset_mode
();
28
uv_timer_stop
(&
tick
);
29
}
30
}
31
32
int
main
() {
33
loop
=
uv_default_loop
();
34
35
uv_tty_init
(
loop
, &
tty
,
STDOUT_FILENO
, 0);
36
uv_tty_set_mode
(&
tty
, 0);
37
38
if
(
uv_tty_get_winsize
(&
tty
, &
width
, &
height
)) {
39
fprintf(stderr,
"Could not get TTY information\n"
);
40
uv_tty_reset_mode
();
41
return
1;
42
}
43
44
fprintf(stderr,
"Width %d, height %d\n"
,
width
,
height
);
45
uv_timer_init
(
loop
, &
tick
);
46
uv_timer_start
(&
tick
,
update
, 200, 200);
47
return
uv_run
(
loop
,
UV_RUN_DEFAULT
);
48
}
NULL
#define NULL
Definition:
cris-opc.c:27
req
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition:
sflib.h:128
buf
voidpf void * buf
Definition:
ioapi.h:138
sprintf
sprintf
Definition:
kernel.h:365
main
int main(int argc, const char **argv)
Definition:
main.c:340
uv_buf_t
Definition:
unix.h:123
uv_loop_s
Definition:
uv.h:1780
uv_stream_s
Definition:
uv.h:494
uv_timer_s
Definition:
uv.h:860
uv_tty_s
Definition:
uv.h:714
uv_write_s
Definition:
uv.h:525
loop
uv_loop_t * loop
Definition:
main.c:7
message
char * message
Definition:
main.c:12
pos
int pos
Definition:
main.c:11
write_req
uv_write_t write_req
Definition:
main.c:9
width
int width
Definition:
main.c:10
tick
uv_timer_t tick
Definition:
main.c:8
update
void update(uv_timer_t *req)
Definition:
main.c:14
height
int height
Definition:
main.c:10
tty
uv_tty_t tty
Definition:
main.c:7
STDOUT_FILENO
#define STDOUT_FILENO
Definition:
private.h:41
uv.h
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition:
uv.h:255
uv_timer_start
UV_EXTERN int uv_timer_start(uv_timer_t *handle, uv_timer_cb cb, uint64_t timeout, uint64_t repeat)
Definition:
timer.c:66
uv_timer_init
UV_EXTERN int uv_timer_init(uv_loop_t *, uv_timer_t *handle)
Definition:
timer.c:58
uv_write
UV_EXTERN int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition:
stream.c:1492
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition:
core.c:365
uv_tty_set_mode
UV_EXTERN int uv_tty_set_mode(uv_tty_t *, uv_tty_mode_t mode)
Definition:
tty.c:250
uv_timer_stop
UV_EXTERN int uv_timer_stop(uv_timer_t *handle)
Definition:
timer.c:97
uv_tty_reset_mode
UV_EXTERN int uv_tty_reset_mode(void)
Definition:
tty.c:378
uv_tty_get_winsize
UV_EXTERN int uv_tty_get_winsize(uv_tty_t *, int *width, int *height)
Definition:
tty.c:297
uv_tty_init
UV_EXTERN int uv_tty_init(uv_loop_t *, uv_tty_t *, uv_file fd, int readable)
Definition:
tty.c:123
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition:
uv-common.c:763
subprojects
libuv-v1.40.0
docs
code
tty-gravity
main.c
Generated by
1.9.1