2 Commits

Author SHA1 Message Date
aff47d79bd working on ssh fork 2026-04-15 06:58:59 -07:00
5e8a6685dc finished with rework 2026-03-16 14:59:05 -07:00
5 changed files with 176 additions and 69 deletions

View File

@@ -25,5 +25,5 @@ add_subdirectory(externals)
# PROJECT
add_subdirectory(source)
#
add_subdirectory(test)
#add_subdirectory(test)

View File

@@ -1,6 +1,5 @@
#ifndef TART_H
#define TART_H
#include <string.h>
#define TART_UTF8
#ifdef __cplusplus
@@ -15,6 +14,7 @@ typedef unsigned int TART_FLAGS;
typedef unsigned char tart_byte;
typedef unsigned short tart_id;
#include <libssh/libssh.h>
#ifdef TART_UTF8
#include <wchar.h>
@@ -25,20 +25,37 @@ typedef char t_char;
#endif
/* tart_color
*
* Tart Color uses three bytes. Each byte reperesents a color.
* There is no alpha
* */
typedef struct {
tart_byte r;
tart_byte g;
tart_byte b;
} tart_color;
/* TART_PALET_SIZE
*
* Every Window has an amount of palettes that it is alicated to use.
* This number is what is defined here. To change this number just add a
* #define for your program.
*
* DEFALT: 32
* */
#ifndef TART_PALET_SIZE
#define TART_PALET_SIZE 32
#endif
/* tart_palette
*
* Every Palette contains a forground color and a background color.
* */
typedef struct {
tart_color forground;
tart_color background;
} tart_pallet;
} tart_palette;
typedef struct {
int x;
@@ -68,12 +85,14 @@ typedef struct {
* The tart window will have the window size and all of the buffers.
**/
typedef struct {
tart_pallet pallet[TART_PALET_SIZE];
tart_palette palette[TART_PALET_SIZE];
tart_vec2 homePosition;
tart_vec2 windowSize;
tart_vec2 terminalSize;
tart_buffer buffer;
const char* name;
ssh_channel ch;
}tart_window ;
@@ -173,12 +192,14 @@ typedef struct {
#define t_strncpy wcncpy
#endif
int tart_create_window(tart_window* w, tart_vec2 ws, const char* title);
int tart_create_window(tart_window* w, tart_vec2 ws, const char* title, ssh_channel ch);
int tart_init(tart_window* w);
int tart_close(tart_window* w);
void tart_disable_cusor();
void tart_enable_cusor();
tart_vec2 tart_window_resize(tart_window* w, tart_vec2 size);
void tart_disable_cusor(tart_window* w);
void tart_enable_cusor(tart_window* w);
int tart_draw(tart_window* w);
int tart_draw_to_buffer(tart_window* w);
int tart_jump(tart_window* w, tart_vec2 pos);
int tart_move_cursor(tart_window* w, tart_vec2 pos);

View File

@@ -12,6 +12,11 @@ add_library(${PROJECT_NAME} STATIC ${LIB_SOURCES})
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC "../includes/")
target_link_libraries(
${PROJECT_NAME}
ssh
)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_compile_definitions(${PROJECT_NAME} PUBLIC "_LINUX")
endif()

View File

@@ -7,6 +7,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <wchar.h>
#include <libssh/libssh.h>
#define BUFFER_AT_POS(W) (W->windowSize.x * W->buffer.curser.y) + W->buffer.curser.x
@@ -14,12 +15,21 @@
#define BUFFER_SIZE (w->windowSize.x * w->windowSize.y)
#define BUFFER_BUFFER_SIZE BUFFER_LINE_SIZE * w->windowSize.y
void tart_free_buffer(tart_window* w) {
for (int i = 0; i < w->windowSize.y; i++) {
free(w->buffer.buffer[i]);
}
free(w->buffer.buffer);
}
tart_vec2 GetTerminalSize(tart_window* w) {
struct winsize win;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
return (tart_vec2){win.ws_col,win.ws_row};
};
int tart_create_buffer(tart_window* w) {
w->buffer.buffer = (tart_cell**)malloc(w->windowSize.y * sizeof(tart_cell*));
if(w->buffer.buffer == NULL) {
@@ -39,9 +49,9 @@ int tart_create_buffer(tart_window* w) {
#else
"\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
#endif
w->pallet[0].forground.r,
w->pallet[0].forground.g,
w->pallet[0].forground.b,
w->palette[0].forground.r,
w->palette[0].forground.g,
w->palette[0].forground.b,
#ifdef TART_UTF8
L' '
#else
@@ -70,19 +80,26 @@ int tart_create_buffer(tart_window* w) {
return TART_OK;
}
void tart_free_buffer(tart_window* w) {
free(w->buffer.buffer);
tart_vec2 tart_window_resize(tart_window* w, tart_vec2 size) {
printf("size.x %d, size.y %d\n", size.x, size.y);
tart_free_buffer(w);
w->windowSize = size;
w->terminalSize = size;
tart_create_buffer(w);
return size;
}
int tart_create_window(tart_window* w, tart_vec2 ws, const char* title) {
w->windowSize.x = GetTerminalSize(w).x - 1;
w->windowSize.y = GetTerminalSize(w).y;
w->terminalSize = GetTerminalSize(w);
int tart_create_window(tart_window* w, tart_vec2 ws, const char* title, ssh_channel ch) {
w->windowSize.x = ws.x - 1;
w->windowSize.y = ws.y;
w->terminalSize = ws;
w->homePosition = (tart_vec2){
(w->terminalSize.x / 2) - (w->windowSize.x / 2),
(w->terminalSize.x / 2) - (w->windowSize.x / 2)
};
w->ch = ch;
tart_create_buffer(w);
return TART_OK;
@@ -97,12 +114,12 @@ int flush_buffer(tart_window* w) {
#else
"\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
#endif
w->pallet[0].background.r,
w->pallet[0].background.g,
w->pallet[0].background.b,
w->pallet[0].forground.r,
w->pallet[0].forground.g,
w->pallet[0].forground.b,
w->palette[0].background.r,
w->palette[0].background.g,
w->palette[0].background.b,
w->palette[0].forground.r,
w->palette[0].forground.g,
w->palette[0].forground.b,
#ifdef TART_UTF8
L' '
#else
@@ -110,8 +127,8 @@ int flush_buffer(tart_window* w) {
#endif
);
for(int i = 0; i < w->windowSize.y; i++) {
for(int j = 0; j < w->windowSize.x ; j++) {
bzero(w->buffer.buffer[i][j], sizeof(tart_cell));
for(int j = 0; j < w->windowSize.x + 1 ; j++) {
bzero(w->buffer.buffer[i][j], TART_CELL_SIZE);
memcpy(w->buffer.buffer[i][j], ce, sizeof(tart_cell));
}
@@ -121,12 +138,12 @@ int flush_buffer(tart_window* w) {
void flush_palets(tart_window* w) {
for(int i = 0; i < TART_PALET_SIZE; i++) {
w->pallet[i].background.r = 0;
w->pallet[i].background.g = 0;
w->pallet[i].background.b = 0;
w->pallet[i].forground.r = 254;
w->pallet[i].forground.g = 254;
w->pallet[i].forground.b = 254;
w->palette[i].background.r = 0;
w->palette[i].background.g = 0;
w->palette[i].background.b = 0;
w->palette[i].forground.r = 254;
w->palette[i].forground.g = 254;
w->palette[i].forground.b = 254;
}
}
@@ -143,22 +160,24 @@ int tart_init(tart_window* w) {
//write(STDOUT_FILENO, ce, TART_CELL_SIZE);
write(STDOUT_FILENO, "\e[?1049h", 8);
write(STDOUT_FILENO, "\e[H", 3);
write(STDOUT_FILENO, "\e[s", 3);
ssh_channel_write(w->ch, "\e[?1049h", 8);
ssh_channel_write(w->ch, "\e[H", 3);
ssh_channel_write(w->ch, "\e[s", 3);
return TART_OK;
}
void tart_disable_cusor() {
write(STDOUT_FILENO, "\e[?25l", 8);
void tart_disable_cusor(tart_window* w) {
//write(STDOUT_FILENO, "\e[?25l", 6);
ssh_channel_write(w->ch, "\e[?25l", strlen("\e[?25l"));
}
void tart_enable_cusor() {
write(STDOUT_FILENO, "\e[?25h", 8);
void tart_enable_cusor(tart_window* w) {
//write(STDOUT_FILENO, "\e[?25h", 6);
ssh_channel_write(w->ch, "\e[?25h", strlen("\e[?25h"));
}
int tart_close(tart_window* w) {
write(STDOUT_FILENO, "\e[?1049l", 8);
ssh_channel_write(w->ch, "\e[?1049l", 8);
//for(int i = 0; i < w->windowSize.y; i++) {
// free(w->buffer.buffer[i]);
//}
@@ -179,6 +198,21 @@ int tart_draw(tart_window* w) {
return TART_OK;
}
int tart_draw_to_buffer(tart_window* w) {
int bufferSize = TART_OK;
int windowBufferSize = (w->windowSize.x + 1) * w->windowSize.y * TART_CELL_SIZE;
char cusureMoveBuff[30] = "";
int index = 0;
for(int i = 0; i < w->windowSize.y; i++) {
ssh_channel_write(w->ch,w->buffer.buffer[i], TART_CELL_SIZE * (w->windowSize.x + 1));
int wrote = sprintf(cusureMoveBuff,"\e[1B\e[%dD", w->windowSize.x + 1);
ssh_channel_write(w->ch,cusureMoveBuff, wrote);
}
ssh_channel_write(w->ch,"\e[H",strlen("\e[H"));
flush_buffer(w);
return bufferSize;
}
int tart_jump(tart_window* w, tart_vec2 pos) {
w->buffer.jump = pos;
w->buffer.curser = pos;
@@ -220,12 +254,12 @@ int tart_insert_cell(tart_window* w, tart_byte p, t_char c) {
#else
"\e[48;2;%03hhu;%03hhu;%03hhum\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
#endif
w->pallet[p].background.r,
w->pallet[p].background.g,
w->pallet[p].background.b,
w->pallet[p].forground.r,
w->pallet[p].forground.g,
w->pallet[p].forground.b,
w->palette[p].background.r,
w->palette[p].background.g,
w->palette[p].background.b,
w->palette[p].forground.r,
w->palette[p].forground.g,
w->palette[p].forground.b,
c
);

View File

@@ -4,8 +4,11 @@
#include <signal.h>
#include <stdio.h>
#include <locale.h>
#include <time.h>
#define jump tart_move_cursor
#define FPS 60
#define FRAME_TIME (1000.0 / FPS)
int e = 1;
@@ -33,6 +36,24 @@ void draw_button(tart_window *w,const t_char* label, tart_vec2 position) {
}
tart_printf(w, 1, T"━━━┛");
}
void limit_fps(int fps) {
static struct timespec last_time;
struct timespec current_time;
double frame_time = 1.0 / fps;
clock_gettime(CLOCK_MONOTONIC, &current_time);
double elapsed = (current_time.tv_sec - last_time.tv_sec) +
(current_time.tv_nsec - last_time.tv_nsec) / 1e9;
if (elapsed < frame_time) {
double sleep_time = frame_time - elapsed;
struct timespec sleep = { (time_t)sleep_time, (long)(sleep_time * 1e9) };
nanosleep(&sleep, NULL);
}
last_time = current_time;
}
int main(int argc, char *argv[])
{
@@ -47,23 +68,29 @@ int main(int argc, char *argv[])
tart_init(&w);
tart_disable_cusor();
w.pallet[0].background.r = 0;
w.pallet[0].background.g = 0;
w.pallet[0].background.b = 0;
w.pallet[0].forground.r = 0;
w.pallet[0].forground.g = 0;
w.pallet[0].forground.b = 0;
w.palette[0].background.r = 0;
w.palette[0].background.g = 0;
w.palette[0].background.b = 0;
w.palette[0].forground.r = 0;
w.palette[0].forground.g = 0;
w.palette[0].forground.b = 0;
w.pallet[1].forground.r = 0xff;
w.pallet[1].forground.g = 0x00;
w.pallet[1].forground.b = 0xcc;
w.palette[1].forground.r = 0xff;
w.palette[1].forground.g = 0x00;
w.palette[1].forground.b = 0xcc;
w.pallet[2].forground.r = 0x3b;
w.pallet[2].forground.g = 0x3b;
w.pallet[2].forground.b = 0x3b;
w.palette[2].forground.r = 0x3b;
w.palette[2].forground.g = 0x3b;
w.palette[2].forground.b = 0x3b;
jump(&w, (tart_vec2){1,1});
jump(&w, (tart_vec2){1,2});
int x = 0;
float xBounce = 30.0f;
float xFlip = 0.1f;
float yBounce = 30.0f;
float yFlip = -0.40f;
clock_t last_frame_time = clock();
double frame_time_ms;
while(e != 0) {
tart_draw(&w);
@@ -75,41 +102,61 @@ int main(int argc, char *argv[])
tart_printf(&w,1, T"this is\na new line test\nyay");
tart_jump(&w, (tart_vec2){3,14});
tart_printf(&w,2, T"this is\na new line test\nyay");
if(w.pallet[1].forground.r == 254) {
tart_printf(&w,2, T"y position %f", yBounce);
if((w.windowSize.x - 2 <= xBounce && xFlip > 0.0f) || (2 > xBounce && xFlip < 0.0f)) {
xFlip *= -1 ;
}
if(((w.windowSize.y * 2) - 2 <= yBounce && yFlip > 0.0f) || (2 > yBounce && yFlip < 0.0f)) {
yFlip *= -1 ;
}
yBounce += yFlip;
xBounce += xFlip;
tart_jump(&w, (tart_vec2){xBounce, yBounce/2});
if((int)yBounce % 2 == 0){
tart_printf(&w, 1, T"");
} else {
tart_printf(&w, 1, T"");
}
if(w.palette[1].forground.r == 254) {
color0 = 0;
}
if(w.pallet[1].forground.r == 0) {
if(w.palette[1].forground.r == 0) {
color0 = 1;
}
if(w.pallet[1].forground.g == 254) {
if(w.palette[1].forground.g == 254) {
color1 = 0;
}
if(w.pallet[1].forground.g == 0) {
if(w.palette[1].forground.g == 0) {
color1 = 1;
}
if(w.pallet[1].forground.b == 254) {
if(w.palette[1].forground.b == 254) {
color2 = 0;
}
if(w.pallet[1].forground.b == 0) {
if(w.palette[1].forground.b == 0) {
color2 = 1;
}
if(color0 == 1) {
w.pallet[1].forground.r++;
w.palette[1].forground.r++;
}else {
w.pallet[1].forground.r--;
w.palette[1].forground.r--;
}
if(color1 == 1) {
w.pallet[1].forground.g++;
w.palette[1].forground.g++;
}else {
w.pallet[1].forground.g--;
w.palette[1].forground.g--;
}
if(color2 == 1) {
w.pallet[1].forground.b++;
w.palette[1].forground.b++;
}else {
w.pallet[1].forground.b--;
w.palette[1].forground.b--;
}
limit_fps(60);
}