mirror of
https://github.com/kiedtl/fire.git
synced 2024-12-22 06:06:40 +00:00
terminate on ctrl-c
This commit is contained in:
parent
6d2b6ffcca
commit
411e8db8a7
9
draw.c
9
draw.c
@ -67,3 +67,12 @@ dofire ( struct buffer *buf )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// free framebuffer and shutdown termbox
|
||||
void
|
||||
cleanup ( struct buffer *buf )
|
||||
{
|
||||
free(buf->buf);
|
||||
tb_shutdown();
|
||||
}
|
||||
|
1
draw.h
1
draw.h
@ -12,5 +12,6 @@ typedef struct buffer
|
||||
|
||||
void init ( struct buffer *buf );
|
||||
void dofire ( struct buffer *buf );
|
||||
void cleanup ( struct buffer *buf );
|
||||
|
||||
#endif
|
||||
|
27
main.c
27
main.c
@ -38,6 +38,7 @@ main ( int argc, char *argv[] )
|
||||
tb_select_output_mode(TB_OUTPUT_NORMAL);
|
||||
tb_clear();
|
||||
struct buffer buf;
|
||||
struct tb_event e;
|
||||
|
||||
// initialize drawing
|
||||
init(&buf);
|
||||
@ -53,13 +54,29 @@ main ( int argc, char *argv[] )
|
||||
|
||||
// draw framebuffer to terminal
|
||||
tb_present();
|
||||
|
||||
// event handling
|
||||
usize err = (usize) tb_peek_event(&e, 5);
|
||||
|
||||
if (err != 0)
|
||||
continue;
|
||||
|
||||
if (e.type == TB_EVENT_KEY)
|
||||
{
|
||||
switch (e.key)
|
||||
{
|
||||
case 0x03:
|
||||
fprintf(stdout, "exiting\n");
|
||||
cleanup(&buf);
|
||||
exit(0);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup termbox
|
||||
tb_shutdown();
|
||||
|
||||
// cleanup framebuffer
|
||||
free(buf.buf);
|
||||
// perform cleanup
|
||||
cleanup(&buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user