This commit is contained in:
+2
-2
@@ -1,3 +1,3 @@
|
||||
tmp/*
|
||||
bin/*
|
||||
build/*
|
||||
doc/*
|
||||
beluga.wiki/*
|
||||
|
||||
+6
-7
@@ -7,15 +7,14 @@
|
||||
*#-------------------------------------------------=##
|
||||
*#----------------------------------------------------:-##
|
||||
#----------------------------------------------------------##
|
||||
#=-------------------------------------------------------------##
|
||||
#----------------------------==----------------------------------=#*
|
||||
#=--------------------------------------------------------------##
|
||||
+--------------------------+@#-%*-----------------------------------#*
|
||||
+--------------------------%@@@@#-------------------------------------**
|
||||
+--------------------------%@@@@#-------------------------------------** BELUGA - VERSION 1.1
|
||||
*-=-------------------------#@@*---------------------------------------=%
|
||||
%*#==--------------------------------------------------------------------+#
|
||||
*%%=-=--------------------------------------------------------------------=#
|
||||
%=--------------------------------------------------------------------------#*
|
||||
%-----------------------------------------------------------------------------**
|
||||
%*#==--------------------------------------------------------------------+# ----- KEY-BINDS -----
|
||||
*%%=-=--------------------------------------------------------------------=# CTRL-q leave
|
||||
%=--------------------------------------------------------------------------#* CTRL-s save
|
||||
%-----------------------------------------------------------------------------** CTRL-o open-file
|
||||
*+--=---===----=---------------=*-----------------------------------------------**
|
||||
#--=## *#%#*+==----==+**+----------------------= ***=---------------------%
|
||||
*%**=-----------==== ==---------------------------------=+#+-----------------=#
|
||||
|
||||
+10
-5
@@ -1,8 +1,9 @@
|
||||
(define TAB-LENGTH 2)
|
||||
;; MACROS
|
||||
|
||||
(define TAB-LENGTH 4)
|
||||
(define QUIT-TIMES 1)
|
||||
|
||||
(map-key "CTRL-q" editor-quit)
|
||||
(map-key "CTRL-s" editor-save)
|
||||
;; FUNCTIONS
|
||||
|
||||
(define editor-delete-next-char (lambda () (
|
||||
(move-cursor "right")
|
||||
@@ -12,6 +13,10 @@
|
||||
)
|
||||
|
||||
|
||||
;; KEY MAPPING
|
||||
|
||||
(map-key "CTRL-q" editor-quit)
|
||||
(map-key "CTRL-s" editor-save)
|
||||
(map-key "ARROW-UP" '(move-cursor "up"))
|
||||
(map-key "ARROW-DOWN" '(move-cursor "down"))
|
||||
(map-key "ARROW-RIGHT" '(move-cursor "right"))
|
||||
@@ -23,7 +28,7 @@
|
||||
(map-key "DEL" editor-delete-next-char)
|
||||
(map-key "PAGE-UP" move-cursor-page-up)
|
||||
(map-key "PAGE-DOWN" move-cursor-page-down)
|
||||
|
||||
; Key binds
|
||||
(map-key "CTRL-o" editor-open-file)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,4 +25,8 @@ Lisp editorMoveCursorPageUp(Lisp args, LispError* e, LispContext ctx);
|
||||
|
||||
Lisp editorMoveCursorPageDown(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,6 +20,11 @@ typedef struct erow {
|
||||
char *render; /**< The actual line we will print */
|
||||
} erow;
|
||||
|
||||
enum editorStatus_e {
|
||||
IDLE,
|
||||
READ_ONLY,
|
||||
READ_AND_WRITE,
|
||||
};
|
||||
|
||||
struct const_t {
|
||||
int TAB_LENGTH;
|
||||
@@ -47,6 +52,7 @@ struct editorConfig {
|
||||
erow *row; /**< Store all the rows printed */
|
||||
int dirty;
|
||||
char *filename;
|
||||
enum editorStatus_e state;
|
||||
char status_msg[80];
|
||||
time_t status_msg_time;
|
||||
struct termios orig_termios; /**< Terminal communication interface */
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
|
||||
char *editorRowsToString(int *buffer_len);
|
||||
|
||||
|
||||
void editorCloseFile(void);
|
||||
|
||||
void editorOpen(char *filename);
|
||||
|
||||
void editorSave();
|
||||
|
||||
@@ -24,7 +24,10 @@ int main(int argc, char *argv[]) {
|
||||
enableRawMode();
|
||||
initEditor();
|
||||
if (argc >= 2) {
|
||||
E.state = READ_AND_WRITE;
|
||||
editorOpen(argv[1]);
|
||||
} else {
|
||||
editorOpen("assets/beluga.txt");
|
||||
}
|
||||
|
||||
editorSetStatusMessage("HELP: Ctrl-S = save | Ctrl-Q = quit");
|
||||
|
||||
@@ -124,5 +124,18 @@ Lisp editorMoveCursorPageDown(Lisp args, LispError* e, LispContext ctx) {
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
|
||||
char *filename = editorPrompt("Path : %s");
|
||||
if (filename)
|
||||
editorOpen(filename);
|
||||
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
|
||||
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx) {
|
||||
char c = lisp_char(lisp_car(args));
|
||||
editorInsertChar(c);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
#include "../include/editor_op.h"
|
||||
#include "../include/row_op.h"
|
||||
#include <stdio.h>
|
||||
#include "data.h"
|
||||
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../include/file_io.h"
|
||||
#include "../include/input.h"
|
||||
#include "../include/output.h"
|
||||
#include "data.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -36,9 +37,29 @@ char *editorRowsToString(int *buffer_len) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
void editorCloseFile(void) {
|
||||
E.cursor_x = 0;
|
||||
E.cursor_y = 0;
|
||||
E.rx = 0;
|
||||
E.row_offset = 0;
|
||||
E.col_offset = 0;
|
||||
E.numrows = 0;
|
||||
E.row = NULL;
|
||||
E.dirty = 0;
|
||||
E.filename = NULL;
|
||||
E.status_msg[0] = '\0';
|
||||
E.status_msg_time = 0;
|
||||
|
||||
}
|
||||
|
||||
void editorOpen(char *filename) {
|
||||
FILE *fp;
|
||||
|
||||
// Test if a file is already open
|
||||
if (E.filename != NULL) {
|
||||
editorCloseFile();
|
||||
}
|
||||
|
||||
free(E.filename);
|
||||
E.filename = strdup(filename);
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ void initBuiltins() {
|
||||
registerBuiltin("EDITOR-DELETE-PREVIOUS-CHAR", deletePreviousChar);
|
||||
registerBuiltin("MOVE-CURSOR-PAGE-UP", editorMoveCursorPageUp);
|
||||
registerBuiltin("MOVE-CURSOR-PAGE-DOWN", editorMoveCursorPageDown);
|
||||
registerBuiltin("EDITOR-OPEN-FILE", editorOpenFile);
|
||||
registerBuiltin("EDITOR-INSERT-CHAR", editorPrintC);
|
||||
}
|
||||
|
||||
void initEditor() {
|
||||
@@ -41,6 +43,7 @@ void initEditor() {
|
||||
E.row = NULL;
|
||||
E.dirty = 0;
|
||||
E.filename = NULL;
|
||||
E.state = READ_ONLY;
|
||||
E.status_msg[0] = '\0';
|
||||
E.status_msg_time = 0;
|
||||
if (getWindowSize(&E.screenrows, &E.screencols) == -1) {
|
||||
|
||||
@@ -102,6 +102,8 @@ void editorDelRow(int at) {
|
||||
* \param at Index of where we want to insert the char */
|
||||
|
||||
void editorRowInsertChar(erow *row, int at, int c) {
|
||||
if (E.state == READ_ONLY)
|
||||
return;
|
||||
if (at < 0 || at > row->size) {
|
||||
at = row->size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user