Remove infinite loop and clean up after yourself

This commit is contained in:
Joseph Ferano 2023-11-11 15:04:46 +07:00
parent 983440079a
commit 107ac6b2db
2 changed files with 107 additions and 108 deletions

View File

@ -4,7 +4,7 @@ CFLAGS=-g -Wall -Wextra -pedantic -O0
LDLIBS=-lSDL2 -lSDL2_ttf LDLIBS=-lSDL2 -lSDL2_ttf
RM=rm -vf RM=rm -vf
bt: clean build: clean
$(CC) $(CFLAGS) $(LDLIBS) $(P).c -o $(P) $(CC) $(CFLAGS) $(LDLIBS) $(P).c -o $(P)
clean: clean:

43
bt.c
View File

@ -14,6 +14,18 @@
#include <SDL2/SDL_ttf.h> #include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_keycode.h> #include <SDL2/SDL_keycode.h>
const int SCREEN_WIDTH = 900;
const int SCREEN_HEIGHT = 700;
const SDL_Color WHITE = {255, 255, 255, 255};
const SDL_Color BLACK = {0, 0, 0, 255};
const SDL_Color RED = {255, 0, 0, 255};
const SDL_Color GREEN = {0, 255, 0, 255};
const SDL_Color BLUE = {0, 0, 255, 255};
const SDL_Color YELLOW = {255, 255, 0, 255};
const SDL_Color MAGENTA = {255, 0, 255, 255};
const SDL_Color SKYBLUE = {0, 255, 255, 255};
const SDL_Color RAYWHITE = {200, 200, 200, 255};
typedef struct scrollback { typedef struct scrollback {
float height; float height;
float ypos; float ypos;
@ -45,18 +57,6 @@ void spawn(file_descriptors *fds) {
} }
} }
const int SCREEN_WIDTH = 900;
const int SCREEN_HEIGHT = 700;
const SDL_Color WHITE = {255, 255, 255, 255};
const SDL_Color BLACK = {0, 0, 0, 255};
const SDL_Color RED = {255, 0, 0, 255};
const SDL_Color GREEN = {0, 255, 0, 255};
const SDL_Color BLUE = {0, 0, 255, 255};
const SDL_Color YELLOW = {255, 255, 0, 255};
const SDL_Color MAGENTA = {255, 0, 255, 255};
const SDL_Color SKYBLUE = {0, 255, 255, 255};
const SDL_Color RAYWHITE = {200, 200, 200, 255};
int read_pty(file_descriptors *fds, scrollback *sb) { int read_pty(file_descriptors *fds, scrollback *sb) {
ssize_t nread; ssize_t nread;
char readbuf[256]; char readbuf[256];
@ -150,7 +150,9 @@ int main(void) {
char key = e.key.keysym.sym; char key = e.key.keysym.sym;
// TODO: Translate this all to SDL2 // TODO: Translate this all to SDL2
// int key = GetCharPressed(); // int key = GetCharPressed();
while (key > 0) { // TODO: Don't remember why I was doing this
// key = GetCharPressed();
// new_char = true;
if ((key >= 32) && (key <= 125)) { if ((key >= 32) && (key <= 125)) {
buf[buf_len] = (char)key; buf[buf_len] = (char)key;
buf[buf_len + 1] = '\0'; buf[buf_len + 1] = '\0';
@ -159,10 +161,6 @@ int main(void) {
sb.buf[sb.length + 1] = '\0'; sb.buf[sb.length + 1] = '\0';
sb.length++; sb.length++;
} }
// TODO: Don't remember why I was doing this
// key = GetCharPressed();
// new_char = true;
}
if (key == SDLK_RETURN) { if (key == SDLK_RETURN) {
sb.length -= buf_len; sb.length -= buf_len;
@ -213,7 +211,6 @@ int main(void) {
// Drawing // Drawing
{
int nread = read_pty(&fds, &sb); int nread = read_pty(&fds, &sb);
if (nread > 0) { if (nread > 0) {
sb.length += nread; sb.length += nread;
@ -298,14 +295,16 @@ int main(void) {
row_buf[ncol++] = sb.buf[c]; row_buf[ncol++] = sb.buf[c];
} }
} }
} SDL_RenderPresent(renderer);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surfaceMessage);
} }
// TODO: Figure out when to free this thing free(sb.buf);
// SDL_FreeSurface(texture);
TTF_CloseFont(font); TTF_CloseFont(font);
TTF_Quit(); TTF_Quit();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
} }