Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c06c820dfb | |||
| 5588b0a8d7 | |||
| 419e924650 | |||
| 6a201b3ebc | |||
| 1d253e51ef | |||
| 42f82e2e0d | |||
| fa32f4b177 | |||
| 65f997e964 | |||
| 7eaf6913cb | |||
| 8f7dcf3534 | |||
| d8c6b9ace3 | |||
| d0173d7308 | |||
| 40fc234eeb |
@@ -6,7 +6,7 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: home-1
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
# Beluga
|
||||
|
||||
Beluga is a project of CLI text editor that will fit perfectly with your azerty keyboard.
|
||||
Beluga is a project of CLI text editor that uses lisp as configuration language.
|
||||
It's abviously only working for **Linux**.
|
||||
|
||||
## Requirements
|
||||
|
||||
You will only need **cmake** and **clang** to compile the editor.
|
||||
You will only need **meson** and a **C compiler** to compile the editor.
|
||||
|
||||
## Installation
|
||||
|
||||
### From source
|
||||
Here is the installation line for development version:
|
||||
|
||||
```git clone --recurse-submodules https://github.com/le-cocotier/beluga.git ~/.beluga && cd ~/.beluga && mkdir build && cd build && cmake ../ && make beluga```
|
||||
```git clone https://homelinuxserver.ddns.net/git/arthur/beluga.git ~/.beluga && cd ~/.beluga && meson setup build && meson compile -C build```
|
||||
|
||||
The executable file will be in `bin/beluga`. Feel free to add it to your path.
|
||||
The executable file will be `build/beluga`. Feel free to add it to your path.
|
||||
|
||||
You can either run `make all` or `make doc_doxygen` if you're interested by the doxygen documentation.
|
||||
### From installation script ( prefered )
|
||||
|
||||
Just clone the repo and execute the script `install.sh`. It will automatically add beluga to your path.
|
||||
|
||||
## Getting start
|
||||
|
||||
To open an existing file just type :
|
||||
```beluga path_to_my_file```
|
||||
```./build/beluga path_to_my_file```
|
||||
|
||||
The only keybinds that you will need will be :
|
||||
- Ctrl-Q : leave the editor
|
||||
- Ctrl-S : Save a file
|
||||
Here is some few command that you will need :
|
||||
|
||||
| keybind| command |
|
||||
|--------|------------------|
|
||||
| Ctrl-Q | leave the editor |
|
||||
| Ctrl-S | Save a file |
|
||||
| Ctrl-O | open file |
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
;; KEY MAPPING
|
||||
|
||||
(map-key "CTRL-q" editor-quit)
|
||||
(map-key "CTRL-s" editor-save)
|
||||
(map-key "CTRL-d" editor-save)
|
||||
(map-key "ARROW-UP" '(move-cursor "up"))
|
||||
(map-key "ARROW-DOWN" '(move-cursor "down"))
|
||||
(map-key "ARROW-RIGHT" '(move-cursor "right"))
|
||||
@@ -29,6 +29,6 @@
|
||||
(map-key "PAGE-UP" move-cursor-page-up)
|
||||
(map-key "PAGE-DOWN" move-cursor-page-down)
|
||||
(map-key "CTRL-o" editor-open-file)
|
||||
|
||||
|
||||
(map-key "CTRL-k" editor-del-row)
|
||||
(map-key "CTRL-s" editor-find)
|
||||
|
||||
|
||||
@@ -29,4 +29,12 @@ Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp addPackage(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorReadChar_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,4 +17,6 @@ void editorOpen(char *filename);
|
||||
|
||||
void editorSave();
|
||||
|
||||
void editorFind();
|
||||
|
||||
#endif // FILE_IO_H_
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
// END \x1b[4~ || <esc>[8~ || <esc>[F || <esc>OF
|
||||
// DELETE \x1b[3~
|
||||
|
||||
char *editorPrompt(char *prompt);
|
||||
char *editorPrompt(char *prompt, char * PlaceHolder, char bPathMode);
|
||||
|
||||
char *key_to_string(int key);
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
int editorRowCxToRx(erow *row, int cursor_x);
|
||||
|
||||
int editorRowRxToCx(erow *row, int rx);
|
||||
|
||||
void editorUpdateRow(erow *row);
|
||||
|
||||
void editorInsertRow(int at, char *s, size_t len);
|
||||
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
echo "--- Welcome to Beluga installer ---"
|
||||
read -p "Do you want to start the installation ? (Y/n)" confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
|
||||
|
||||
# Check dependencies
|
||||
|
||||
if ! command -v "meson" &>/dev/null; then
|
||||
echo "❌ Error: meson not found. Please install it first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Create config files
|
||||
|
||||
echo "Create config files ..."
|
||||
mkdir -pv ~/.beluga/
|
||||
cp -rv ./assets/ ~/.beluga/
|
||||
mkdir -pv ~/.beluga/packages/
|
||||
|
||||
read -p "Do you want to replace your config file or keep it (init.lisp.bak) / (init.lisp.new) ? (Y/n)" confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
mv ~/.beluga/config/init.lisp ~/.beluga/config/init.lisp.bak
|
||||
cp -rv ./config/init.lisp ~/.beluga/config/
|
||||
else
|
||||
cp -rv ./config/init.lisp ~/.beluga/config/init.lisp.new
|
||||
fi
|
||||
|
||||
|
||||
# Compile the project
|
||||
|
||||
echo "Start compilation ..."
|
||||
meson setup build/
|
||||
meson compile -C build/
|
||||
|
||||
# Add to path
|
||||
echo "Adding beluga to the path"
|
||||
sudo cp -f ./build/beluga /usr/local/bin/
|
||||
|
||||
echo "Installation finish"
|
||||
echo "Check ~/.beluga/config/init.lisp for customization"
|
||||
@@ -5,6 +5,9 @@
|
||||
* interactions. \version 0.1 \date 21 septembre 2024
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
@@ -22,14 +25,20 @@ struct editorConfig E;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
char * splash_screen = (char *) calloc(256, sizeof(char));
|
||||
|
||||
enableRawMode();
|
||||
initEditor();
|
||||
if (argc >= 2) {
|
||||
E.state = READ_AND_WRITE;
|
||||
editorOpen(argv[1]);
|
||||
} else {
|
||||
editorOpen("assets/beluga.txt");
|
||||
strcat(splash_screen, getenv("HOME"));
|
||||
strcat(splash_screen, "/.beluga/assets/beluga.txt");
|
||||
fprintf(stderr, "%s\n", splash_screen);
|
||||
editorOpen(splash_screen);
|
||||
}
|
||||
free(splash_screen);
|
||||
|
||||
editorSetStatusMessage("HELP: Ctrl-S = save | Ctrl-Q = quit");
|
||||
|
||||
|
||||
+36
-3
@@ -3,6 +3,7 @@
|
||||
#include "../include/input.h"
|
||||
#include "../include/file_io.h"
|
||||
#include "../include/editor_op.h"
|
||||
#include "../include/row_op.h"
|
||||
#include "../include/data.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -27,7 +28,6 @@ Lisp mapKey(Lisp args, LispError *e, LispContext ctx) {
|
||||
}
|
||||
|
||||
Lisp moveCursor(Lisp args, LispError *e, LispContext ctx) {
|
||||
fprintf(stderr, "Cursor is moving\n");
|
||||
const char *direction = lisp_string(lisp_car(args));
|
||||
switch (direction[0]) {
|
||||
case 'u':
|
||||
@@ -125,7 +125,7 @@ Lisp editorMoveCursorPageDown(Lisp args, LispError* e, LispContext ctx) {
|
||||
}
|
||||
|
||||
Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
|
||||
char *filename = editorPrompt("Path : %s");
|
||||
char *filename = editorPrompt("Open : %s", getenv("PWD"), 1);
|
||||
if (filename)
|
||||
editorOpen(filename);
|
||||
|
||||
@@ -134,8 +134,41 @@ Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
|
||||
|
||||
|
||||
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx) {
|
||||
char c = lisp_char(lisp_car(args));
|
||||
char c = lisp_string(lisp_car(args))[0];
|
||||
editorInsertChar(c);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp addPackage(Lisp args, LispError *e, LispContext ctx) {
|
||||
const char *package_name = lisp_string(lisp_car(args));
|
||||
char *package_dir = (char *) calloc(256, sizeof(char));
|
||||
FILE *fd_package = NULL;
|
||||
strcat(package_dir, getenv("HOME"));
|
||||
strcat(package_dir, "/.beluga/packages/");
|
||||
strcat(package_dir, package_name);
|
||||
strcat(package_dir, "/init.lisp");
|
||||
fd_package = fopen(package_dir, "r");
|
||||
lisp_eval(lisp_read_file(fd_package, &E.ctx_error, E.ctx), &E.ctx_error,
|
||||
E.ctx);
|
||||
fclose(fd_package);
|
||||
free(package_dir);
|
||||
|
||||
return lisp_null();
|
||||
|
||||
}
|
||||
|
||||
Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
editorDelRow(E.cursor_y);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
editorFind();
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp editorReadChar_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
fprintf(stderr, "char read : %c\n", E.row[E.cursor_y].render[E.cursor_x]);
|
||||
return lisp_make_char(E.row[E.cursor_y].render[E.cursor_x]);
|
||||
}
|
||||
|
||||
|
||||
+19
-1
@@ -87,7 +87,7 @@ void editorSave() {
|
||||
char *buf;
|
||||
int fd;
|
||||
if (E.filename == NULL) {
|
||||
E.filename = editorPrompt("Save as: %s (ESC to cancel)");
|
||||
E.filename = editorPrompt("Save as: %s (ESC to cancel)", "", 1);
|
||||
if (E.filename == NULL) {
|
||||
editorSetStatusMessage("Save aborted");
|
||||
return;
|
||||
@@ -110,3 +110,21 @@ void editorSave() {
|
||||
free(buf);
|
||||
editorSetStatusMessage("Can't save! I/O error: %s", strerror(errno));
|
||||
}
|
||||
|
||||
void editorFind() {
|
||||
char *query = editorPrompt("Search: %s (ESC to cancel)", "", 0);
|
||||
if (query == NULL) return;
|
||||
int i;
|
||||
for (i = E.cursor_y + 1; i < E.numrows; i++) {
|
||||
erow *row = &E.row[i];
|
||||
char *match = strstr(row->render, query);
|
||||
if (match) {
|
||||
E.cursor_y = i;
|
||||
E.cursor_x = editorRowRxToCx(row, match - row->render);
|
||||
E.row_offset = E.numrows;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(query);
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -31,9 +31,14 @@ void initBuiltins() {
|
||||
registerBuiltin("MOVE-CURSOR-PAGE-DOWN", editorMoveCursorPageDown);
|
||||
registerBuiltin("EDITOR-OPEN-FILE", editorOpenFile);
|
||||
registerBuiltin("EDITOR-INSERT-CHAR", editorPrintC);
|
||||
registerBuiltin("ADD-PACKAGE", addPackage);
|
||||
registerBuiltin("EDITOR-DEL-ROW", editorDelRow_L);
|
||||
registerBuiltin("EDITOR-FIND", editorFind_L);
|
||||
registerBuiltin("EDITOR-READ-CHAR", editorReadChar_L);
|
||||
}
|
||||
|
||||
void initEditor() {
|
||||
char * init_file_path = (char *) calloc(256, sizeof(char));
|
||||
E.cursor_x = 0;
|
||||
E.cursor_y = 0;
|
||||
E.rx = 0;
|
||||
@@ -53,8 +58,10 @@ void initEditor() {
|
||||
|
||||
E.number_of_keybinds = 0;
|
||||
|
||||
|
||||
E.fd_init_file = fopen("config/init.lisp", "r");
|
||||
strcat(init_file_path, getenv("HOME"));
|
||||
strcat(init_file_path, "/.beluga/config/init.lisp");
|
||||
printf("%s\n", init_file_path);
|
||||
E.fd_init_file = fopen(init_file_path, "r");
|
||||
E.ctx = lisp_init();
|
||||
E.env = lisp_env(E.ctx);
|
||||
lisp_lib_load(E.ctx);
|
||||
@@ -63,6 +70,7 @@ void initEditor() {
|
||||
|
||||
// Read config file
|
||||
E.ctx_data = lisp_read_file(E.fd_init_file, &E.ctx_error, E.ctx);
|
||||
free(init_file_path);
|
||||
if (E.ctx_error != LISP_ERROR_NONE) {
|
||||
die("init failed");
|
||||
}
|
||||
|
||||
+76
-3
@@ -3,6 +3,8 @@
|
||||
#include "../include/output.h"
|
||||
#include "../include/define.h"
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -11,19 +13,72 @@
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
char * file_completion(const char *path) {
|
||||
DIR * dir;
|
||||
struct dirent *entry;
|
||||
char directory[128];
|
||||
char predict[128];
|
||||
int predict_len = 0;
|
||||
|
||||
if (path[strlen(path) - 1] == '/') {
|
||||
return path;
|
||||
}
|
||||
|
||||
// Find dir name
|
||||
char * last_slash = strrchr(path, '/');
|
||||
if (last_slash) {
|
||||
size_t dir_len = last_slash - path + 1; // length of dir_path
|
||||
strncpy(directory, path, dir_len);
|
||||
predict_len = strlen(path) - dir_len - 1;
|
||||
strncpy(predict, last_slash + 1, predict_len);
|
||||
directory[dir_len] = '\0';
|
||||
predict[predict_len] = '\0';
|
||||
fprintf(stderr, "%s %s\n", directory, predict);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
dir = opendir(directory);
|
||||
if (!dir)
|
||||
return NULL;
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strncmp(entry->d_name, predict, predict_len) == 0) {
|
||||
static char full_path[128];
|
||||
snprintf(full_path, sizeof(full_path), "%s%s", directory, entry->d_name);
|
||||
|
||||
struct stat st;
|
||||
if (stat(full_path, &st) == 0 && S_ISDIR(st.st_mode)) {
|
||||
strcat(full_path, "/"); // add slash for directories
|
||||
}
|
||||
|
||||
return strdup(full_path);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup when no more entries
|
||||
closedir(dir);
|
||||
dir = NULL;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn char * editorPrompt(struct editorConfig *E, char *prompt)
|
||||
* \fn char * editorPrompt(struct editorConfig *E, char *prompt, char bPathMode)
|
||||
* \brief Return user input in a prompt when enter is hit. */
|
||||
|
||||
char *editorPrompt(char *prompt) {
|
||||
char *editorPrompt(char *prompt, char * placeHolder, char bPathMode) {
|
||||
size_t buf_size = 128;
|
||||
char *buf = malloc(buf_size);
|
||||
size_t buf_len = 0;
|
||||
int c = 0;
|
||||
buf[0] = '\0';
|
||||
strcpy(buf, placeHolder);
|
||||
buf_len = strlen(placeHolder);
|
||||
|
||||
while (1) {
|
||||
editorSetStatusMessage(prompt, buf);
|
||||
editorSetStatusMessage(prompt, buf);
|
||||
editorRefreshScreen();
|
||||
c = editorReadKey();
|
||||
if (c == DEL_KEY || c == CTRL_KEY('h') || c == BACKSPACE) {
|
||||
@@ -39,6 +94,24 @@ char *editorPrompt(char *prompt) {
|
||||
editorSetStatusMessage("");
|
||||
return buf;
|
||||
}
|
||||
} else if (bPathMode && c == '\t') {
|
||||
char path[128];
|
||||
char * pwd;
|
||||
if (buf[0] != '/') {
|
||||
pwd = getenv("PWD");
|
||||
fprintf(stderr, "%s\n", pwd);
|
||||
memcpy(path, pwd, strlen(pwd));
|
||||
path[strlen(pwd)] = '/';
|
||||
strncat(path, buf, buf_len);
|
||||
} else {
|
||||
strcpy(path, buf);
|
||||
}
|
||||
memset(buf, 0, 128);
|
||||
buf_len = 0;
|
||||
strcpy(buf, file_completion(path));
|
||||
buf_len = strlen(buf);
|
||||
buf[buf_len] = '\0';
|
||||
|
||||
} else if (!iscntrl(c) && c < 128) {
|
||||
if (buf_len == buf_size - 1) {
|
||||
buf_size *= 2;
|
||||
|
||||
@@ -18,6 +18,18 @@ int editorRowCxToRx(erow *row, int cursor_x) {
|
||||
return render_x;
|
||||
}
|
||||
|
||||
int editorRowRxToCx(erow *row, int rx) {
|
||||
int cur_rx = 0;
|
||||
int cx;
|
||||
for (cx = 0; cx < row->size; cx++) {
|
||||
if (row->chars[cx] == '\t')
|
||||
cur_rx += (E.constantes.TAB_LENGTH - 1) - (cur_rx % E.constantes.TAB_LENGTH);
|
||||
cur_rx++;
|
||||
if (cur_rx > rx) return cx;
|
||||
}
|
||||
return cx;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn editorUpdateRow(erow *row)
|
||||
* \brief Copy content of \p row in \p row->render.
|
||||
|
||||
Reference in New Issue
Block a user