#include #include #include #include #include #include #include #include #include #define STB_DS_IMPLEMENTATION #include "../include/stb_ds.h" 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); } initscr(); cbreak(); noqiflush(); keypad(stdscr, TRUE); noecho(); start_color(); timeout(20); //curs_set(1); //nodelay(stdscr, TRUE); //2line for tab //1 colomn for middle sep //1 line for terminput //2 line for sep 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); 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(); return (0); }