working on editor

This commit is contained in:
emilia 2026-03-19 21:40:57 +01:00
commit 1a917de4e9
3 changed files with 153 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
build/
obj/
include/

47
Makefile Executable file
View File

@ -0,0 +1,47 @@
NAME := sl_editor
CC := gcc
#-static -fsanitize=thread
CFLAGS := -g -ggdb -fsanitize=address -fsanitize=undefined -Og -Wall -Wextra -Werror -std=c99 -pedantic
LDFLAGS :=
LDLIBS := -lasan -lubsan -lpthread -lreadline -lncurses
SRC_DIR := source
OBJ_DIR := obj
BUILD_DIR := build
SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
all: $(NAME)
$(NAME): $(OBJ) | $(BUILD_DIR)
$(CC) $(OBJ) $(LDFLAGS) $(LDLIBS) -o $(BUILD_DIR)/$(NAME)
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c $(wildcard $(SRC_DIR)/*.h)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR):
mkdir $(OBJ_DIR)
$(BUILD_DIR):
mkdir $(BUILD_DIR)
$(OBJ): | $(OBJ_DIR)
clean:
rm -f myshell
fclean: clean
rm -rf $(OBJ_DIR)
re: fclean all
.PHONY: all clean fclean re $(NAME)

102
source/main.c Normal file
View File

@ -0,0 +1,102 @@
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <ncurses.h>
#include <locale.h>
#define STB_DS_IMPLEMENTATION
#include "../include/stb_ds.h"
int main(int ac, char** av, char** envp) {
(void)ac;
(void)av;
(void)envp;
if (!setlocale(LC_ALL, "")) {
printf("Unable to set local attributes from environment\n");
return (-1);
}
bool running = true;
WINDOW* editor = 0;
WINDOW* edit_tab = 0;
WINDOW* edit_ruler = 0;
WINDOW* term = 0;
WINDOW* document = 0;
WINDOW* doc_tab = 0;
WINDOW* doc_ruler = 0;
initscr();
cbreak();
noecho();
noqiflush();
keypad(stdscr, TRUE);
start_color();
timeout(20);
//nodelay(stdscr, TRUE);
printf("%ix%i\n", LINES, COLS);
//2line for tab
//1 colomn for middle sep
//1 line for terminput
//2 line for sep
edit_tab = subwin(stdscr, 1, COLS / 2, 0, 0);
editor = subwin(stdscr, LINES - 4, COLS / 2, 2, 0);
edit_ruler = subwin(stdscr, 1, COLS / 2, 1, 0);
doc_tab = subwin(stdscr, 1, COLS / 2, 0, COLS / 2);
document = subwin(stdscr, LINES - 7, COLS / 2, 2, COLS / 2);
doc_ruler = subwin(stdscr, 1, COLS / 2, LINES - 2, COLS / 2);
term = subwin(stdscr, 3, COLS - COLS % 2, LINES - 3, 0);
//terminfo();
rl_initialize();
rl_inhibit_completion = true;//non zero = bypasscompletion
//now need to have all my "window"
int i = 0;
while (running) {
clear();
wborder(editor, '|', '|', '-', '-', '-', '-', '-', '-');
wborder(document, '|', '|', '-', '-', '-', '-', '-', '-');
//box(editor, ACS_VLINE, ACS_HLINE);
//box(document, ACS_VLINE, ACS_HLINE);
box(term, ACS_VLINE, ACS_HLINE);
refresh();
wrefresh(edit_tab);
wrefresh(editor);
wrefresh(edit_ruler);
wrefresh(doc_tab);
wrefresh(document);
wrefresh(doc_ruler);
wrefresh(term);
//move();
int ch = getch();
if (ch != ERR) {
//process
running = false;
}
i++;
}
endwin();
/* free(editor);
free(edit_tab);
free(edit_ruler);
free(term);
free(document);
free(doc_tab);
free(doc_ruler);
*/
printf("number of loop:%i\n", i);
return (0);
}