style changes

This commit is contained in:
Kiëd Llaentenn 2020-09-17 12:04:12 +00:00
parent da742e282d
commit 6c076eb2a9
3 changed files with 26 additions and 31 deletions

5
draw.h
View File

@ -7,13 +7,12 @@
#include "stdint.h" #include "stdint.h"
#endif #endif
typedef struct buffer struct buffer {
{
size_t width; size_t width;
size_t height; size_t height;
uint8_t* buf; uint8_t* buf;
} buffer; };
void init(struct buffer *buf); void init(struct buffer *buf);
void dofire(struct buffer *buf); void dofire(struct buffer *buf);

26
main.c
View File

@ -23,14 +23,13 @@ main ( int argc, char *argv[] )
{ {
opts = (struct Options*) calloc(1, sizeof(struct Options*)); opts = (struct Options*) calloc(1, sizeof(struct Options*));
if (opts == NULL) { if (opts == NULL) {
EPRINT("fire: error: cannot "); perror("fire: error: calloc()");
perror("calloc()");
} }
// default args // default args
opts->refresh_rate = 5; opts->refresh_rate = 5;
opts->truecolor = FALSE;
size_t output_mode = TB_OUTPUT_NORMAL; size_t output_mode = TB_OUTPUT_NORMAL;
opts->truecolor = FALSE;
// argument parsing // argument parsing
argv0 = argv[0]; argv0 = argv[0];
@ -45,7 +44,7 @@ main ( int argc, char *argv[] )
break; break;
case 'V': case 'V':
printf("%s %s\n", argv0, VERSION); printf("%s %s\n", argv0, VERSION);
exit(EXIT_SUCCESS); return 0;
case 'h': case 'h':
default: default:
printf("Usage: %s [-tVh] [-r rate]\n", argv0); printf("Usage: %s [-tVh] [-r rate]\n", argv0);
@ -58,7 +57,7 @@ main ( int argc, char *argv[] )
printf("(c) Kiëd Llaentenn, nullgemm\n"); printf("(c) Kiëd Llaentenn, nullgemm\n");
printf("https://github.com/lptstr/fire\n"); printf("https://github.com/lptstr/fire\n");
exit(EXIT_SUCCESS); return 0;
} ARGEND } ARGEND
// initialize termbox // initialize termbox
@ -72,11 +71,7 @@ main ( int argc, char *argv[] )
init(&buf); init(&buf);
// animate // animate
while (TRUE) while (TRUE) {
{
// clear the screen
//tb_clear();
// update framebuffer // update framebuffer
dofire(&buf); dofire(&buf);
@ -86,11 +81,13 @@ main ( int argc, char *argv[] )
// event handling // event handling
int err = (size_t) tb_peek_event(&e, opts->refresh_rate); int err = (size_t) tb_peek_event(&e, opts->refresh_rate);
if (err < 0) if (err < 0) {
continue; continue;
}
if (e.type == TB_EVENT_KEY) // handle keypresses
{ // q, ctrl+c, ctrl+d => quit
if (e.type == TB_EVENT_KEY) {
switch (e.ch) { switch (e.ch) {
case 'q': case 'q':
goto cleanup; goto cleanup;
@ -98,8 +95,7 @@ main ( int argc, char *argv[] )
break; break;
} }
switch (e.key) switch (e.key) {
{
case TB_KEY_CTRL_C: case TB_KEY_CTRL_C:
case TB_KEY_CTRL_D: case TB_KEY_CTRL_D:
goto cleanup; goto cleanup;