This commit is contained in:
emilia 2026-03-21 19:41:13 +01:00
parent 1a917de4e9
commit f414c55608

View File

@ -15,88 +15,167 @@
#define STB_DS_IMPLEMENTATION
#include "../include/stb_ds.h"
int main(int ac, char** av, char** envp) {
(void)ac;
(void)av;
(void)envp;
typedef struct sl_insert {
char *data;
size_t lenght;
size_t index;
} sl_insert_t;
typedef struct sl_file {
FILE *file;
char *filename;
char *data;
size_t size;
int pos;//position of the cursor
sl_insert_t *ins;
size_t ins_number;//number of insert
char *ins_alloc;//buffer for all insert data;..not in position order
size_t ins_size;//total size of ins blob;
size_t ins_capacity;//total cap of ins data;
} sl_file_t;
typedef struct sl_cursor {
int x;
int y;
} sl_cursor_t;
typedef struct sl_buffer{
sl_cursor_t cursor;
WINDOW *win;
int height;
int width;
int y;
int x;
//other things to put in a focused buffer
} sl_buffer_t;
void file_save(sl_file *file) {
int size = file->ins_size + file->size;
char*new_data = calloc(size + 1);
assert(new_data);//may need to remove to not crash if an error appen
for (size_t i = 0; i < file->ins_number; i++) {
memcpy((void*)(new_data + file->ins[i].index), file->ins[i].data, file->ins[i].length);
}
//then how should i handle first file fragmenttion ?
size_t n = 0;
size_t k = 0;
for (size_t i = 0, k = 0; i < size && k < file->size; i += len) {
size_t len = file->ins[n]
memcpy(new_data + i, file->data + k += , fil);
k+= file->ins[n].index
n++
}
};
sl_buffer_t sl_buffer_create(int height, int width, int y, int x) {
sl_buffer_t ret = {0};
ret.cursor.x = 1;
ret.cursor.y = 1;
ret.height = height;
ret.width = width;
ret.y = y;
ret.x = x;
ret.win = subwin(stdscr, height, width, y, x);
return (ret);
}
void print_help() {
printf("SterlingEditor Version %i.%i\n", 0, 1);
}
int parse_args(int ac, char** av) {
for (int i = 1; i <= ac; i++) {
if (av[i]) {
return(0);
}
}
print_help();
return (-1);
}
void sl_buffer_update(sl_buffer_t *buff) {
if (buff->cursor.x < 1) buff->cursor.x = 1;
if (buff->cursor.x > COLS / 2 - 2) buff->cursor.x = COLS / 2 - 2;
if (buff->cursor.y < 1) buff->cursor.y = 1;
if (buff->cursor.y > LINES - 2) buff->cursor.y = LINES - 2;
wmove(buff->win, buff->cursor.y, buff->cursor.x);
wrefresh(buff->win);
}
void sl_buffer_set_context(sl_buffer_t *buff, int idx) {
keypad(buff[idx].win, TRUE);
wmove(buff[idx].win, buff[idx].cursor.y, buff[idx].cursor.x);
}
int main(int ac, char** av, char** envp) {
(void)envp;
bool running = true;
sl_buffer_t *buffers = NULL;
int current = 0;
if (parse_args(ac, av) == -1) {
return (-1);
}
if (!setlocale(LC_ALL, "")) {
printf("Unable to set local attributes from environment\n");
return (-1);
}
bool running = true;
WINDOW* editor = 0;
WINDOW* edit_tab = 0;
WINDOW* edit_ruler = 0;
WINDOW* term = 0;
WINDOW* document = 0;
WINDOW* doc_tab = 0;
WINDOW* doc_ruler = 0;
initscr();
cbreak();
noecho();
noqiflush();
keypad(stdscr, TRUE);
noecho();
start_color();
timeout(20);
//curs_set(1);
//nodelay(stdscr, TRUE);
printf("%ix%i\n", LINES, COLS);
//2line for tab
//1 colomn for middle sep
//1 line for terminput
//2 line for sep
edit_tab = subwin(stdscr, 1, COLS / 2, 0, 0);
editor = subwin(stdscr, LINES - 4, COLS / 2, 2, 0);
edit_ruler = subwin(stdscr, 1, COLS / 2, 1, 0);
arrpush(buffers, sl_buffer_create(LINES, COLS >> 1, 0, 0));//editor
arrpush(buffers, sl_buffer_create(LINES, COLS >> 1, 0, COLS >> 1));//document
sl_buffer_set_context(buffers, current);
doc_tab = subwin(stdscr, 1, COLS / 2, 0, COLS / 2);
document = subwin(stdscr, LINES - 7, COLS / 2, 2, COLS / 2);
doc_ruler = subwin(stdscr, 1, COLS / 2, LINES - 2, COLS / 2);
term = subwin(stdscr, 3, COLS - COLS % 2, LINES - 3, 0);
//terminfo();
rl_initialize();
rl_inhibit_completion = true;//non zero = bypasscompletion
//now need to have all my "window"
int i = 0;
while (running) {
clear();
wborder(editor, '|', '|', '-', '-', '-', '-', '-', '-');
wborder(document, '|', '|', '-', '-', '-', '-', '-', '-');
//box(editor, ACS_VLINE, ACS_HLINE);
//box(document, ACS_VLINE, ACS_HLINE);
box(term, ACS_VLINE, ACS_HLINE);
refresh();
wrefresh(edit_tab);
wrefresh(editor);
wrefresh(edit_ruler);
wrefresh(doc_tab);
wrefresh(document);
wrefresh(doc_ruler);
wrefresh(term);
//move();
int ch = getch();
if (ch != ERR) {
//process
running = false;
}
i++;
for (int i = 0; i < arrlen(buffers); i++) {
box(buffers[i].win, ACS_VLINE, ACS_HLINE);
}
refresh();
// rl_initialize();
// rl_inhibit_completion = true;//non zero = bypasscompletion
int ch = 0;
while (running) {
ch = wgetch(buffers[current].win);
box(buffers[current].win, ACS_VLINE, ACS_HLINE);
switch (ch) {
case ('q'): {
running = false;
break;
}
case (KEY_LEFT): {
buffers[current].cursor.x--;
break;
}
case (KEY_RIGHT): {
buffers[current].cursor.x++;
break;
}
case (KEY_UP): {
buffers[current].cursor.y--;
break;
}
case (KEY_DOWN): {
buffers[current].cursor.y++;
break;
}
default: break;
}
sl_buffer_update(&buffers[current]);
}
arrfree(buffers);
endwin();
/* free(editor);
free(edit_tab);
free(edit_ruler);
free(term);
free(document);
free(doc_tab);
free(doc_ruler);
*/
printf("number of loop:%i\n", i);
return (0);
}