Skip to content

Commit

Permalink
Rename buffer type to buffer_t
Browse files Browse the repository at this point in the history
  • Loading branch information
cgmb committed Feb 25, 2020
1 parent 53fc288 commit 326cda3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ float linear_to_sRGB(float x) {
return powf(x, 1/2.2f); // approximation
}

void buffer_append_color(buffer* buf, float r, float g, float b) {
void buffer_append_color(buffer_t* buf, float r, float g, float b) {
char tmp[20];
int r_out = float_to_byte_color(linear_to_sRGB(r));
int g_out = float_to_byte_color(linear_to_sRGB(g));
Expand All @@ -1015,7 +1015,7 @@ void buffer_append_color(buffer* buf, float r, float g, float b) {
buffer_append(buf, tmp, length);
}

void draw_rows(buffer* buf) {
void draw_rows(buffer_t* buf) {
const char* symbol[4] = {" ","o","O","0"};
const uint8_t max_symbol_idx = 3;
const int y_cutoff = max_i((int)Y-1 - g_wy, 1);
Expand Down Expand Up @@ -1055,7 +1055,7 @@ void draw_rows(buffer* buf) {
}
}

void draw(buffer* buf) {
void draw(buffer_t* buf) {
buffer_clear(buf);
reposition_cursor(buf);
draw_rows(buf);
Expand Down Expand Up @@ -1161,7 +1161,7 @@ int main(int argc, char** argv) {

enable_raw_mode();
clear_screen_now();
buffer buf = { 0, 0 };
buffer_t buf = { 0, 0 };
draw(&buf);

struct timespec interval_start;
Expand Down
18 changes: 9 additions & 9 deletions misc/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ void clear_screen_now() {
write_stdinz(T_CLEAR T_REPOSITION_CURSOR);
}

void clear_screen(buffer* buf) {
void clear_screen(buffer_t* buf) {
buffer_appendz(buf, T_CLEAR T_REPOSITION_CURSOR);
}

void reposition_cursor(buffer* buf) {
void reposition_cursor(buffer_t* buf) {
buffer_appendz(buf, T_REPOSITION_CURSOR);
}

void hide_cursor(buffer* buf) {
void hide_cursor(buffer_t* buf) {
buffer_appendz(buf, T_HIDE_CURSOR);
}

void show_cursor(buffer* buf) {
void show_cursor(buffer_t* buf) {
buffer_appendz(buf, T_SHOW_CURSOR);
}

Expand Down Expand Up @@ -85,7 +85,7 @@ void enable_raw_mode() {
}
}

void buffer_append(buffer* buf, const char* s, int len) {
void buffer_append(buffer_t* buf, const char* s, int len) {
char* data = (char*)realloc(buf->data, buf->len + len);
if (!data) {
die("failed to reallocate buffer");
Expand All @@ -95,19 +95,19 @@ void buffer_append(buffer* buf, const char* s, int len) {
buf->len += len;
}

void buffer_appendz(buffer* buf, const char* s) {
void buffer_appendz(buffer_t* buf, const char* s) {
buffer_append(buf, s, strlen(s));
}

void buffer_write(buffer* buf) {
void buffer_write(buffer_t* buf) {
write_stdin(buf->data, buf->len);
}

void buffer_clear(buffer* buf) {
void buffer_clear(buffer_t* buf) {
buf->len = 0;
}

void buffer_free(buffer* buf) {
void buffer_free(buffer_t* buf) {
free(buf->data);
}

Expand Down
22 changes: 11 additions & 11 deletions misc/terminal.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#pragma once

typedef struct buffer {
typedef struct buffer_t {
char* data;
int len;
} buffer;
} buffer_t;

void buffer_append(buffer* buf, const char* s, int len);
void buffer_appendz(buffer* buf, const char* s);
void buffer_free(buffer* buf);
void buffer_write(buffer* buf);
void buffer_clear(buffer* buf);
void buffer_append(buffer_t* buf, const char* s, int len);
void buffer_appendz(buffer_t* buf, const char* s);
void buffer_free(buffer_t* buf);
void buffer_write(buffer_t* buf);
void buffer_clear(buffer_t* buf);

void die(const char* msg);

void clear_screen_now();

void clear_screen(buffer* buf);
void reposition_cursor(buffer* buf);
void hide_cursor(buffer* buf);
void show_cursor(buffer* buf);
void clear_screen(buffer_t* buf);
void reposition_cursor(buffer_t* buf);
void hide_cursor(buffer_t* buf);
void show_cursor(buffer_t* buf);
void enable_raw_mode();
void disable_raw_mode();

Expand Down

0 comments on commit 326cda3

Please sign in to comment.