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

6
draw.c
View File

@ -19,7 +19,7 @@ extern struct Options *opts;
// initialize the framebuffer
void
init ( struct buffer *buf )
init(struct buffer *buf)
{
// initialize width/height of terminal
buf->width = tb_width();
@ -45,7 +45,7 @@ init ( struct buffer *buf )
// update the framebuffer
void
dofire ( struct buffer *buf )
dofire(struct buffer *buf)
{
size_t src;
size_t random;
@ -85,7 +85,7 @@ dofire ( struct buffer *buf )
// free framebuffer and shutdown termbox
void
cleanup ( struct buffer *buf )
cleanup(struct buffer *buf)
{
free(buf->buf);
tb_shutdown();

11
draw.h
View File

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

26
main.c
View File

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