first
This commit is contained in:
12
source/CMakeLists.txt
Normal file
12
source/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
# ADD SOURCES HERE
|
||||
set(SOURCE_FILES
|
||||
main.c
|
||||
commands.c
|
||||
commands.h
|
||||
editor.h
|
||||
editor.c
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} TartLib m)
|
||||
37
source/commands.c
Normal file
37
source/commands.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "commands.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MIN_NOM_COMMANDS 30
|
||||
|
||||
#define COMMAND_SUCCESS 0;
|
||||
#define COMMAND_NOT_FOUND 1;
|
||||
#define COMMAND_FAILER 2;
|
||||
|
||||
struct nomi_command __commands__[MIN_NOM_COMMANDS];
|
||||
int __command_count__ = 0;
|
||||
|
||||
void InitCommands() {
|
||||
for(int i = 0; i < MIN_NOM_COMMANDS; i++) {
|
||||
__commands__[i] = (struct nomi_command){0,""};
|
||||
}
|
||||
}
|
||||
|
||||
void AddCommand(nomi_command_func func, const char* command) {
|
||||
if(__command_count__ < MIN_NOM_COMMANDS) {
|
||||
__commands__[__command_count__] = (struct nomi_command) {
|
||||
.func = func,
|
||||
.command = command
|
||||
};
|
||||
__command_count__++;
|
||||
}
|
||||
}
|
||||
unsigned char CommandRun(char* command, int size) {
|
||||
for(int i = 0; i < MIN_NOM_COMMANDS; i++) {
|
||||
if(!strcmp(command, __commands__[i].command)) {
|
||||
__commands__[i].func(&__commands__[i]);
|
||||
return COMMAND_SUCCESS;
|
||||
}
|
||||
}
|
||||
return COMMAND_NOT_FOUND;
|
||||
}
|
||||
20
source/commands.h
Normal file
20
source/commands.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef COMMANDS_H
|
||||
#define COMMANDS_H
|
||||
|
||||
|
||||
typedef void (*nomi_command_func)(void* ptr);
|
||||
|
||||
|
||||
struct nomi_command {
|
||||
nomi_command_func func;
|
||||
const char* command;
|
||||
};
|
||||
|
||||
void InitCommands();
|
||||
|
||||
|
||||
void AddCommand(nomi_command_func func, const char* command);
|
||||
unsigned char CommandRun(char* command, int size);
|
||||
|
||||
|
||||
#endif // !COMMANDS_H
|
||||
56
source/editor.c
Normal file
56
source/editor.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef EDITOR_H
|
||||
#define EDITOR_H
|
||||
|
||||
#include <tart.h>
|
||||
|
||||
struct tart_window window;
|
||||
|
||||
|
||||
struct commandMode {
|
||||
struct tart_cstring prompt_cstr;
|
||||
struct tart_cstring input_cstr;
|
||||
|
||||
char inputBuffer[255];
|
||||
int inputBufferIdx;
|
||||
char* input;
|
||||
};
|
||||
|
||||
struct InsertMode {
|
||||
};
|
||||
|
||||
void Create_commandMode();
|
||||
|
||||
void CreateWindow() {
|
||||
|
||||
}
|
||||
|
||||
void InitCommandMode() {
|
||||
}
|
||||
void InitInsertMode();
|
||||
void InitNormalMode();
|
||||
void InitNomiMode();
|
||||
|
||||
|
||||
void CommandMode(struct CommandMode cmdm) {
|
||||
tart_draw_cstring_position(tart_get_buffer(&window, 0),
|
||||
commandInput_cstr,
|
||||
(struct tart_vec2){16,10});
|
||||
tart_draw_cstring_position(tart_get_buffer(&window, 0),
|
||||
commandPrompt_cstr,
|
||||
(struct tart_vec2){0,10});
|
||||
}
|
||||
void InsertMode();
|
||||
void NormalMode();
|
||||
void NomiMode();
|
||||
|
||||
void Update();
|
||||
|
||||
void UpdateBigin();
|
||||
void UpdateEnd();
|
||||
|
||||
void OnQuit();
|
||||
void OnStart();
|
||||
|
||||
void Draw();
|
||||
|
||||
#endif /* ifndef EDITOR_H */
|
||||
158
source/editor.h
Normal file
158
source/editor.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/*##############################################################################
|
||||
*
|
||||
*##############################################################################
|
||||
*/
|
||||
#ifndef EDITOR_H
|
||||
#define EDITOR_H
|
||||
|
||||
#include <tart.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
char* text;
|
||||
int len;
|
||||
int stringCount;
|
||||
struct tart_cell cell;
|
||||
struct tart_cstring textBox[30];
|
||||
struct tart_vec2 size;
|
||||
struct tart_vec2 pos;
|
||||
} richTextBox;
|
||||
|
||||
void SetRichTextBox(richTextBox* rtb, char* text, int len,
|
||||
struct tart_cell cell) {
|
||||
int lineCount = 0;
|
||||
int textOffset = 0;
|
||||
char* p = text;
|
||||
unsigned char found = 0;
|
||||
rtb->stringCount = 5;
|
||||
int sizeOfString = 0;
|
||||
for(int i = 0; i < len; i++) {
|
||||
sizeOfString = i - textOffset;
|
||||
|
||||
if(p[i] == '\n') {
|
||||
// This means that it will start splitting strings
|
||||
found = 1;
|
||||
|
||||
//p[i] = '\0'; // Sets this to be the end of the string
|
||||
|
||||
//Add the address to the cstring
|
||||
if(lineCount == 5) {
|
||||
break;
|
||||
}
|
||||
|
||||
rtb->textBox[lineCount] = tart_cstring(p + textOffset,
|
||||
sizeOfString, rtb->cell);
|
||||
textOffset = i + 1; // Sets the start of the next string.
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
tart_cstring_free(&rtb->textBox[lineCount]);
|
||||
rtb->textBox[lineCount] = tart_cstring(p + textOffset,
|
||||
strlen(p), rtb->cell);
|
||||
|
||||
}
|
||||
|
||||
void drawTextBox(struct tart_window* window, richTextBox* rtb, tart_byte id) {
|
||||
struct tart_buffer* sb = tart_get_buffer(window, id);
|
||||
// This makes sure that we dont go outside of memeery with the string count.
|
||||
for (int lineNo = 0; lineNo < rtb->stringCount; lineNo++) {
|
||||
tart_draw_cstring_position(sb,
|
||||
rtb->textBox[lineNo],
|
||||
(struct tart_vec2){rtb->pos.x,rtb->pos.y + lineNo});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Init Command Mode
|
||||
*
|
||||
* This will run when COMMAND_MODE is triggerd
|
||||
*/
|
||||
void InitCommandMode();
|
||||
/*
|
||||
* Init Insert Mode
|
||||
*
|
||||
* This will run when INSERT_MODE is triggerd
|
||||
*/
|
||||
void InitInsertMode();
|
||||
/*
|
||||
* Init Normal Mode
|
||||
*
|
||||
* This will run when NORMAL_MODE is triggerd
|
||||
*/
|
||||
void InitNormalMode();
|
||||
/*
|
||||
* Init Nomi Mode
|
||||
*
|
||||
* This will run when NOMI_MODE is triggerd
|
||||
*/
|
||||
void InitNomiMode();
|
||||
|
||||
/*
|
||||
* Command Mode
|
||||
*
|
||||
* This will run every frame when COMMAND_MODE is active
|
||||
*/
|
||||
void CommandMode();
|
||||
/*
|
||||
* Insert Mode
|
||||
*
|
||||
* This will run every frame when INSERT_MODE is active
|
||||
*/
|
||||
void InsertMode();
|
||||
/*
|
||||
* Normal Mode
|
||||
*
|
||||
* This will run every frame when NORMAL_MODE is active
|
||||
*/
|
||||
void NormalMode();
|
||||
/*
|
||||
* Nomi Mode
|
||||
*
|
||||
* This will run every frame when NOMI_MODE is active
|
||||
*/
|
||||
void NomiMode();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Update
|
||||
*
|
||||
* This will run every frame.
|
||||
*/
|
||||
void Update();
|
||||
|
||||
|
||||
/*
|
||||
* Update Bigin
|
||||
*
|
||||
* This will run on the begining of every update.
|
||||
*/
|
||||
void UpdateBigin();
|
||||
/*
|
||||
* Update End
|
||||
*
|
||||
* This will run on the ending of every update.
|
||||
*/
|
||||
void UpdateEnd();
|
||||
|
||||
/*
|
||||
* On Quit
|
||||
*
|
||||
* This will run on the quitting of the program
|
||||
*/
|
||||
void OnQuit();
|
||||
/*
|
||||
* On Start
|
||||
*
|
||||
* This will run on the start of the program
|
||||
*/
|
||||
void OnStart();
|
||||
|
||||
/*
|
||||
* Draw
|
||||
*
|
||||
* This will Draw the screen
|
||||
*/
|
||||
void Draw();
|
||||
|
||||
#endif /* ifndef EDITOR_H */
|
||||
284
source/main.c
Normal file
284
source/main.c
Normal file
@@ -0,0 +1,284 @@
|
||||
/* #############################################################################
|
||||
* # nomi
|
||||
* this is a note takeing system where the user can make notes about the nomi
|
||||
*
|
||||
* AUTHER: Preacher
|
||||
* DATE: 10/23/2025
|
||||
* #############################################################################
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <tart.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "commands.h"
|
||||
|
||||
#define KEY_BACKSPACE 127
|
||||
#define COMMAND_MODE 0x01
|
||||
#define NORMAL_MODE 0x02
|
||||
#define INSERT_MODE 0x03
|
||||
|
||||
#define MIN_LINE_COUNT_RTB 30
|
||||
|
||||
unsigned char __Close__ = 0;
|
||||
|
||||
void programClose(int sig) {
|
||||
term_threaded_input_stop();
|
||||
term_enable_cursor();
|
||||
__Close__ = 1;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char* text;
|
||||
int len;
|
||||
int stringCount;
|
||||
struct tart_cell cell;
|
||||
struct tart_cstring textBox[30];
|
||||
struct tart_vec2 size;
|
||||
struct tart_vec2 pos;
|
||||
} richTextBox;
|
||||
|
||||
unsigned char mode = NORMAL_MODE;
|
||||
|
||||
void SetRichTextBox(richTextBox* rtb, char* text, int len,
|
||||
struct tart_cell cell) {
|
||||
int lineCount = 0;
|
||||
int textOffset = 0;
|
||||
char* p = text;
|
||||
unsigned char found = 0;
|
||||
rtb->stringCount = 5;
|
||||
int sizeOfString = 0;
|
||||
for(int i = 0; i < len; i++) {
|
||||
sizeOfString = i - textOffset;
|
||||
|
||||
if(p[i] == '\n') {
|
||||
// This means that it will start splitting strings
|
||||
found = 1;
|
||||
|
||||
//p[i] = '\0'; // Sets this to be the end of the string
|
||||
|
||||
//Add the address to the cstring
|
||||
if(lineCount == 5) {
|
||||
break;
|
||||
}
|
||||
|
||||
rtb->textBox[lineCount] = tart_cstring(p + textOffset,
|
||||
sizeOfString, rtb->cell);
|
||||
textOffset = i + 1; // Sets the start of the next string.
|
||||
lineCount++;
|
||||
}
|
||||
}
|
||||
tart_cstring_free(&rtb->textBox[lineCount]);
|
||||
rtb->textBox[lineCount] = tart_cstring(p + textOffset,
|
||||
strlen(p), rtb->cell);
|
||||
|
||||
}
|
||||
|
||||
void drawTextBox(struct tart_window* window, richTextBox* rtb, tart_byte id) {
|
||||
struct tart_buffer* sb = tart_get_buffer(window, id);
|
||||
// This makes sure that we dont go outside of memeery with the string count.
|
||||
for (int lineNo = 0; lineNo < rtb->stringCount; lineNo++) {
|
||||
tart_draw_cstring_position(sb,
|
||||
rtb->textBox[lineNo],
|
||||
(struct tart_vec2){rtb->pos.x,rtb->pos.y + lineNo});
|
||||
}
|
||||
}
|
||||
|
||||
//############ Init Commands ############
|
||||
|
||||
void Command_CloseProgram(void* cmd) {
|
||||
programClose(0);
|
||||
}
|
||||
void Command_WrightToFile(void* cmd) {
|
||||
// wright to the file
|
||||
}
|
||||
void Command_New_Thought(void* cmd) {
|
||||
// Create A New Thought
|
||||
}
|
||||
|
||||
//############ Init Commands ############
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
|
||||
InitCommands();
|
||||
AddCommand(Command_CloseProgram, "q");
|
||||
AddCommand(Command_CloseProgram, "w");
|
||||
|
||||
term_disable_cursor();
|
||||
term_threaded_input_init();
|
||||
|
||||
signal(SIGINT, programClose);
|
||||
|
||||
char str[255] = "This is a test";
|
||||
char commandPromt[16] = "Enter Command: ";
|
||||
char commandInput[255] = "";
|
||||
unsigned char keyPressed = 0;
|
||||
|
||||
|
||||
// Window Createion
|
||||
struct tart_window window = tart_create_window();
|
||||
struct tart_buffer buf = tart_create_buffer(0,
|
||||
(struct tart_vec2){40,20},
|
||||
(struct tart_vec2){0,0});
|
||||
tart_add_buffer(&window, buf);
|
||||
|
||||
|
||||
//Rich TextBox init
|
||||
int inputIdx = 0;
|
||||
int commandIdx = 0;
|
||||
richTextBox inputRtb;
|
||||
inputRtb.pos = (struct tart_vec2){0,0};
|
||||
inputRtb.size = (struct tart_vec2){3,3};
|
||||
|
||||
SetRichTextBox(&inputRtb, str, 255, NULL_CELL);
|
||||
|
||||
struct tart_cstring commandPrompt_cstr = tart_cstring(commandPromt, 16, NULL_CELL);
|
||||
struct tart_cstring commandInput_cstr = tart_cstring(commandInput, 255, NULL_CELL);
|
||||
|
||||
tart_restore_window(&window);
|
||||
tart_restore_buffer(tart_get_buffer(&window, 0));
|
||||
|
||||
for (;!__Close__;) {
|
||||
// LOOP START
|
||||
|
||||
|
||||
|
||||
if(keyPressed) {
|
||||
tart_draw_window(&window, 0);
|
||||
tart_restore_window(&window);
|
||||
tart_restore_buffer(tart_get_buffer(&window, 0));
|
||||
|
||||
char c = term_tinput();
|
||||
|
||||
//Speual
|
||||
SetRichTextBox(&inputRtb, str, strlen(str), NULL_CELL);
|
||||
|
||||
if(mode == INSERT_MODE && keyPressed) {
|
||||
if(c == '\e') {
|
||||
mode = NORMAL_MODE;
|
||||
keyPressed = 0;
|
||||
term_handled_key();
|
||||
} else {
|
||||
if(c == '\t' && keyPressed && inputIdx < 255) {
|
||||
for(int i = 0; i < 4; i++) {
|
||||
str[inputIdx] = ' ';
|
||||
inputIdx++;
|
||||
}
|
||||
keyPressed = 0;
|
||||
}else if (c == KEY_BACKSPACE && keyPressed && inputIdx < 255 && inputIdx > 0) {
|
||||
inputIdx--;
|
||||
str[inputIdx] = '\0';
|
||||
} else {
|
||||
str[inputIdx] = c;
|
||||
inputIdx++;
|
||||
}
|
||||
|
||||
keyPressed = 0;
|
||||
term_handled_key();
|
||||
}
|
||||
SetRichTextBox(&inputRtb, str, strlen(str), NULL_CELL);
|
||||
}
|
||||
|
||||
if(mode == COMMAND_MODE) {
|
||||
|
||||
if(c == '\e') {
|
||||
commandIdx = 0;
|
||||
for(int i = 0; i < 255; i++) {
|
||||
commandInput[i] = '\0';
|
||||
}
|
||||
mode = NORMAL_MODE;
|
||||
keyPressed = 0;
|
||||
term_handled_key();
|
||||
} else {
|
||||
commandInput_cstr = tart_cstring(commandInput,
|
||||
strlen(commandInput),
|
||||
NULL_CELL);
|
||||
if(c == '\t' && keyPressed && commandIdx + 4 < 255) {
|
||||
for(int i = 0; i < 4; i++) {
|
||||
commandInput[commandIdx] = ' ';
|
||||
commandIdx++;
|
||||
}
|
||||
keyPressed = 0;
|
||||
}else if (c == KEY_BACKSPACE &&
|
||||
keyPressed &&
|
||||
commandIdx < 255 &&
|
||||
commandIdx > 0) {
|
||||
commandIdx--;
|
||||
commandInput[commandIdx] = '\0';
|
||||
} else if (c == '\n' && keyPressed) {
|
||||
// handle command.
|
||||
tart_cstring_free(&commandPrompt_cstr);
|
||||
commandInput_cstr = tart_cstring(commandInput,
|
||||
strlen(commandInput),
|
||||
NULL_CELL);
|
||||
|
||||
CommandRun(commandInput, commandIdx);
|
||||
for(int i = 0; i < 255; i++) {
|
||||
commandInput[i] = '\0';
|
||||
}
|
||||
keyPressed = 0;
|
||||
term_handled_key();
|
||||
commandIdx = 0;
|
||||
mode = NORMAL_MODE;
|
||||
|
||||
}else {
|
||||
commandInput[commandIdx] = c;
|
||||
commandIdx++;
|
||||
}
|
||||
|
||||
keyPressed = 0;
|
||||
term_handled_key();
|
||||
|
||||
commandInput_cstr = tart_cstring(commandInput, strlen(commandInput), NULL_CELL);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Key Events
|
||||
if (c == ':' && mode == NORMAL_MODE) {
|
||||
mode = COMMAND_MODE;
|
||||
keyPressed = 0;
|
||||
term_handled_key();
|
||||
}
|
||||
if (c == 'i' && mode == NORMAL_MODE) {
|
||||
mode = INSERT_MODE;
|
||||
keyPressed = 0;
|
||||
term_handled_key();
|
||||
}
|
||||
keyPressed = 0;
|
||||
}
|
||||
drawTextBox(&window, &inputRtb, 0);
|
||||
tart_draw_window(&window, 0);
|
||||
if(mode == COMMAND_MODE) {
|
||||
tart_draw_cstring_position(tart_get_buffer(&window, 0),
|
||||
commandInput_cstr,
|
||||
(struct tart_vec2){16,10});
|
||||
tart_draw_cstring_position(tart_get_buffer(&window, 0),
|
||||
commandPrompt_cstr,
|
||||
(struct tart_vec2){0,10});
|
||||
}
|
||||
if(mode == NORMAL_MODE) {
|
||||
}
|
||||
if(mode == INSERT_MODE) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// LOOP END
|
||||
// Draw Begin
|
||||
// Draw End
|
||||
keyPressed = term_key_pressed();
|
||||
}
|
||||
|
||||
tart_destroy_window(&window);
|
||||
return 0;
|
||||
}
|
||||
0
source/nomi.c
Normal file
0
source/nomi.c
Normal file
81
source/nomi.h
Normal file
81
source/nomi.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*##############################################################################
|
||||
* project: nomi
|
||||
* file: nomi.h
|
||||
*
|
||||
* This file handles all of the nomi spesific action like creating and handling
|
||||
* Trunks and branches. As well as the data nessary for that it to run properly.
|
||||
*
|
||||
* Auther: PreacherDHM
|
||||
* Date: 10/30/2025
|
||||
*##############################################################################
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NOMI_H
|
||||
#define NOMI_H
|
||||
|
||||
#define BRNACH 0x01
|
||||
#define TRUNK 0x00
|
||||
#define MAX_CHILDREN 5
|
||||
#define MAX_BRANCHES 30
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned int branchId;
|
||||
|
||||
// All of the different notes
|
||||
typedef struct {
|
||||
char* text; // This is the data that is in that branch
|
||||
branchId children[MAX_CHILDREN]; // holds the branchIds of its children
|
||||
void* parent; // points the the branches parent
|
||||
char type; // holds the type as in if this struct is a branch or a trunk
|
||||
branchId id; // This holds the branch id.
|
||||
} branch;
|
||||
|
||||
// The Root of the tree structure
|
||||
typedef struct {
|
||||
branch branches[MAX_BRANCHES];
|
||||
const char* title;
|
||||
char* text;
|
||||
} trunk;
|
||||
|
||||
/*
|
||||
* This will Init Nomi
|
||||
*/
|
||||
void NomiInit();
|
||||
/*
|
||||
* This will create the truk of the note.
|
||||
* */
|
||||
trunk* CreateTrunk();
|
||||
|
||||
/*
|
||||
* This is a test
|
||||
* */
|
||||
void CreaetBranch(trunk* trunk);
|
||||
|
||||
/*
|
||||
* Locate Branch
|
||||
* */
|
||||
branch* LocateBranch();
|
||||
|
||||
/*
|
||||
* Draw Branch
|
||||
*/
|
||||
void DrawBranch(branch* branch);
|
||||
|
||||
/*
|
||||
* Create Nomi File
|
||||
*
|
||||
* name: the name of the file that will be created.
|
||||
*/
|
||||
FILE CreateNomiFile(const char* name);
|
||||
|
||||
/*
|
||||
* Save Nomi File
|
||||
*
|
||||
* file: the pointer to the nomi file.
|
||||
*/
|
||||
void SaveNomiFile(FILE* file);
|
||||
|
||||
|
||||
#endif // NOMI_H
|
||||
Reference in New Issue
Block a user