From 3f9bd14056fcedd4ae132d22d90bffa050aa886b Mon Sep 17 00:00:00 2001 From: PreacherDHM Date: Fri, 7 Nov 2025 18:29:07 -0800 Subject: [PATCH] working on seperating main into editor fiels --- source/editor.c | 71 ++++++++++++++++++++++++++++++++++++------------- source/main.c | 43 +++++++++++++++++++----------- source/nomi.c | 10 +++++++ source/nomi.h | 2 ++ 4 files changed, 92 insertions(+), 34 deletions(-) diff --git a/source/editor.c b/source/editor.c index 6253f1d..920eb23 100644 --- a/source/editor.c +++ b/source/editor.c @@ -1,32 +1,73 @@ +/*############################################################################## + * file: editor.c + * + * editor handles everything in the editor space. That means that this will + * handle every thing form nomai and editing text with in the editor its self. + * + * The editor will handle all tart related things. so that nothing else has to + * be handled. + * + * + * Auther: PreacherDHM + * Date: 07/11/2025 + *############################################################################## + * */ + + #ifndef EDITOR_H #define EDITOR_H #include #include "editor.h" +#include "nomi.h" +#define EDITOR_EVENT_WINDOW_RESIZE 0x01 +#define EDITOR_EVENT_WINDOW_CLOSE 0x02 +#define EDITOR_EVENT_WINDOW_OPEN 0x04 +#define EDITOR_EVENT_ON_UPDATE 0x08 +#define EDITOR_EVENT_MISC_1 16 +#define EDITOR_EVENT_MISC_2 32 +#define EDITOR_EVENT_MISC_3 64 +#define EDITOR_EVENT_MISC_4 128 +struct editor_window { + struct tart_window window; + struct tart_buffer buf; + struct tart_vec2 size; + tart_byte bufId; + const char* windowTitle; +}; -struct tart_window window; +typedef int(editor_event_func)(void* editor_event); +struct editor_event { + struct editor_window* window; + unsigned char eventType; + unsigned char eventValue; + void* data; + int dataSize; + editor_event_func* evnet_func; +}; - -struct commandMode { - struct tart_cstring prompt_cstr; +struct command_mode { struct tart_cstring input_cstr; char inputBuffer[255]; int inputBufferIdx; - char* input; + char prompt[30]; }; -struct bottomBar { - struct tart_cstring mode_cstr; - struct tart_cstring file_cstr; - struct tart_cstring branch_cstr; - struct tart_cell bottomBar_cell; +struct bottom_bar { + struct tart_cstring bottomBar_cstr; + struct tart_cell backgroundCell; + struct tart_cell modeCell; + + nomi_vec2 size; }; -struct InsertMode { +struct insert_mode { + struct tart_cstring textDisplay; + struct tart_cell cell; }; void Create_commandMode(); @@ -42,13 +83,7 @@ void InitNormalMode(); void InitNomiMode(); -void CommandMode(struct commandMode cmdm) { - tart_draw_cstring_position(tart_get_buffer(&window, 0), - cmdm.input_cstr, - (struct tart_vec2){16,10}); - tart_draw_cstring_position(tart_get_buffer(&window, 0), - cmdm.prompt_cstr, - (struct tart_vec2){0,10}); +void CommandMode(struct command_mode cmdm) { } void InsertMode(); void NormalMode(); diff --git a/source/main.c b/source/main.c index af4bda0..8c80abf 100644 --- a/source/main.c +++ b/source/main.c @@ -27,6 +27,7 @@ #define COMMAND_MODE 0x01 #define NORMAL_MODE 0x02 #define INSERT_MODE 0x03 +#define NOMAI_MODE 0x04 #define MIN_LINE_COUNT_RTB 30 @@ -268,6 +269,29 @@ int main (int argc, char *argv[]) { } } + if(mode == NOMAI_MODE) { + + if(c == '\e') { + mode = NORMAL_MODE; + } + + if(c == 'n') { + unsigned int r = 102391238; + AddBranch(&tr, create_branch(GetSelectedBranch(), (nomi_vec2){0,1}, 100, rand_r(&r)%100)); + } + + //NomiNavigation(c); + branchId* ids = NomiNavigation(c); + for(int i = 0; i < MAX_BRANCHES; i++) { + str[i] = ids[i]+48; + } + str[MAX_BRANCHES] = '\n'; + ids = LocateBranch(&tr); + for(int i = 0; i < MAX_BRANCHES; i++) { + str[1+MAX_BRANCHES+i] = ids[i]+48; + } + term_handled_key(); + } // Key Events if (c == ':' && mode == NORMAL_MODE) { @@ -280,22 +304,9 @@ int main (int argc, char *argv[]) { keyPressed = 0; term_handled_key(); } - if(mode == NORMAL_MODE) { - //NomiNavigation(c); - branchId* ids = NomiNavigation(c); - for(int i = 0; i < MAX_BRANCHES; i++) { - str[i] = ids[i]+48; - } - str[MAX_BRANCHES] = '\n'; - ids = LocateBranch(&tr); - for(int i = 0; i < MAX_BRANCHES; i++) { - str[1+MAX_BRANCHES+i] = ids[i]+48; - } - str[(MAX_BRANCHES*2)+1] = '\n'; - ids = LocateBranch(&tr); - for(int i = 0; i < MAX_BRANCHES; i++) { - str[2+(MAX_BRANCHES*2)+i] = ids[i]+48; - } + if (c == 'n' && mode == NORMAL_MODE) { + mode = NOMAI_MODE; + keyPressed = 0; term_handled_key(); } keyPressed = 0; diff --git a/source/nomi.c b/source/nomi.c index 33b68a8..a161f21 100644 --- a/source/nomi.c +++ b/source/nomi.c @@ -44,6 +44,8 @@ struct nomiNavigation __nav__ = { */ void NomiInit(trunk* tr) { __nav__ = (struct nomiNavigation){ .branches = {0}, .depth = 0, .selectedBranch = &tr->branches[0] }; + __nav__.branches[0] = 1; + __nav__.depth = 1; } branchId* NomiNavigation(char input) { @@ -72,6 +74,13 @@ branchId* NomiNavigation(char input) { return __nav__.branches; } +branch* GetSelectedBranch() { + return __nav__.selectedBranch; +} +void SetSelectedBranch(branch* b) { + __nav__.selectedBranch = b; +} + /* * This will create the truk of the note. * */ @@ -100,6 +109,7 @@ void AddBranch(trunk* t, branch br) { if(t->branchCount < MAX_BRANCHES) { t->branches[t->branchCount] = br; t->branchCount++; + __nav__.selectedBranch = &t->branches[t->branchCount]; } } diff --git a/source/nomi.h b/source/nomi.h index 34dc904..c775b2d 100644 --- a/source/nomi.h +++ b/source/nomi.h @@ -68,6 +68,8 @@ typedef struct { */ void NomiInit(trunk* tr); branchId* NomiNavigation(char input); +branch* GetSelectedBranch(); +void SetSelectedBranch(branch* b); /* * This will create the truk of the note. * */