Fumofumotris/source/term/term.h

54 lines
1.1 KiB
C
Raw Normal View History

2024-03-25 05:34:59 +00:00
#pragma once
#include <iso646.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2024-04-03 23:31:47 +00:00
#include <pthread.h>
2024-03-25 05:34:59 +00:00
#include "fumotris.h"
2024-04-03 23:31:47 +00:00
struct TChar4 {
2024-03-25 05:34:59 +00:00
char ch;
u8 bg : 4;
u8 fg : 4;
};
2024-04-03 23:31:47 +00:00
struct Terminal {
2024-03-25 05:34:59 +00:00
size_t wid;
size_t hgt;
size_t area;
2024-04-03 23:31:47 +00:00
u16f refresh_rate;
2024-04-04 19:43:45 +00:00
struct TChar4 *bufs[2];
size_t buf_size;
u8f switch_read;
u8f switch_write;
2024-04-03 23:31:47 +00:00
pthread_mutex_t mutex;
2024-04-04 19:43:45 +00:00
pthread_cond_t update;
struct {
u8f is_writing : 1;
u8f resize : 1;
} flags;
2024-03-25 05:34:59 +00:00
};
2024-04-04 13:27:54 +00:00
struct Terminal NewTerm(size_t wid, size_t hgt);
2024-03-25 05:34:59 +00:00
2024-04-04 19:43:45 +00:00
void TermSetBufs(struct Terminal *term, struct TChar4 *buf0, struct TChar4 *buf1);
void TermResize(struct Terminal *term, size_t wid, size_t hgt);
void UpdateTerm(struct Terminal *term);
bool TermWaitUpdate(struct Terminal *term);
void TermSignalSafe(struct Terminal *term);
void WaitSafeTerm(struct Terminal *term);
void TermLock(struct Terminal *term);
void TermUnlock(struct Terminal *term);
2024-03-25 05:34:59 +00:00
2024-04-04 19:43:45 +00:00
size_t TermOut(struct Terminal *term, char *buf);