291 lines
8.5 KiB
C
291 lines
8.5 KiB
C
/* #############################################################################
|
|
* # 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"
|
|
#include "nomi.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();
|
|
__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;
|
|
rtb->text = text;
|
|
int sizeOfString = 0;
|
|
}
|
|
|
|
void drawTextBox(struct tart_window* window, richTextBox* rtb, tart_byte id) {
|
|
struct tart_buffer* sb = tart_get_buffer(window, id);
|
|
int lineNo = 0;
|
|
int lineStart = 0;
|
|
for(int i = 0; i < strlen(rtb->text); i++) {
|
|
if(rtb->text[i] == '\n') {
|
|
rtb->textBox[0] = tart_cstring(
|
|
&rtb->text[0]+lineStart,
|
|
i - lineStart,
|
|
NULL_CELL);
|
|
tart_draw_cstring_position(sb,
|
|
rtb->textBox[0],
|
|
(struct tart_vec2){rtb->pos.x, rtb->pos.y+lineNo});
|
|
tart_cstring_free(&rtb->textBox[0]);
|
|
lineNo++;
|
|
lineStart = i + 1;
|
|
}
|
|
}
|
|
rtb->textBox[0] = tart_cstring(
|
|
&rtb->text[0]+lineStart,
|
|
strlen(rtb->text) - lineStart,
|
|
NULL_CELL);
|
|
tart_draw_cstring_position(sb,
|
|
rtb->textBox[0],
|
|
(struct tart_vec2){rtb->pos.x, rtb->pos.y+lineNo});
|
|
tart_cstring_free(&rtb->textBox[0]);
|
|
}
|
|
|
|
//############ 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;
|
|
|
|
branch b = create_branch(NULL, (nomi_vec2){0,1});
|
|
branch b1 = create_branch(&b,(nomi_vec2){1,1});
|
|
|
|
// Window Createion
|
|
struct tart_window window = tart_create_window();
|
|
struct tart_buffer buf = tart_create_buffer(0,
|
|
term_current_size(),
|
|
(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
|
|
|
|
tart_restore_window(&window);
|
|
tart_restore_buffer(tart_get_buffer(&window, 0));
|
|
|
|
b = create_branch(NULL, (nomi_vec2){0,1});
|
|
b1 = create_branch(&b,(nomi_vec2){1,4*2});
|
|
|
|
if(keyPressed) {
|
|
tart_draw_window(&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);
|
|
|
|
|
|
|
|
DrawBranch(&b, &window, 0);
|
|
DrawBranch(&b1, &window, 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);
|
|
term_enable_cursor();
|
|
return 0;
|
|
}
|