working on seperating main into editor fiels

This commit is contained in:
2025-11-07 18:29:07 -08:00
parent 99c46cec29
commit 3f9bd14056
4 changed files with 92 additions and 34 deletions

View File

@@ -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 <tart.h>
#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();

View File

@@ -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;

View File

@@ -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];
}
}

View File

@@ -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.
* */