Status bar / editing / saving file

This commit is contained in:
Arthur Barraux
2024-10-08 14:57:59 +02:00
parent 297eef4ce2
commit 1c22c3beca
15 changed files with 334 additions and 27 deletions
+30 -11
View File
@@ -2,10 +2,19 @@
#define DATA_H_
#include <termios.h>
#include <time.h>
/**
* \struct erow
* \brief Store one editor row
* \param
* */
typedef struct erow {
int size;
char *chars;
int size; /**< Size of the line */
int rsize; /**< Size of the render line */
char *chars; /**< Characters of the line */
char *render; /**< The actual line we will print */
} erow;
/**
@@ -13,18 +22,28 @@ typedef struct erow {
* \brief Containing our editor state.
*/
struct editorConfig {
int cursor_x, cursor_y;
int row_offset;
int screenrows;
int screencols;
int numrows;
erow *row;
struct termios orig_termios;
int cursor_x, cursor_y; /**< Cursor position */
int rx; /**< Position in the render*/
int row_offset; /**< Position scroll of lines */
int col_offset; /**< Position scroll of colomns*/
int screenrows; /**< Terminal height*/
int screencols; /**< Terminal width*/
int numrows; /**< Number of rows contained */
erow *row; /**< Store all the rows printed */
char *filename;
char status_msg[80];
time_t status_msg_time;
struct termios orig_termios; /**< Terminal communication interface */
};
/**
* \struct abuf
* \brief Contains text to add before writing to screen.
* */
struct abuf {
char *b;
int len;
char *b; /**< Text that will be printed */
int len; /**< Length of the text */
};
#endif
+2
View File
@@ -9,6 +9,7 @@
#define ERASE_END_LINE "\x1b[K"
enum editorKey {
BACKSPACE = 127,
CURSOR_LEFT = 1000,
CURSOR_RIGHT,
CURSOR_UP,
@@ -23,5 +24,6 @@ enum editorKey {
#define ABUF_INIT {NULL, 0}
#define BELUGA_VERSION "0.1"
#define TAB_LENGTH 8
#endif // DEFINE_H_
+7
View File
@@ -0,0 +1,7 @@
#ifndef EDITOR_OP_H_
#define EDITOR_OP_H_
#include "data.h"
void editorInsertChar(struct editorConfig *E, int c);
#endif // EDITOR_OP_H_
+4
View File
@@ -8,6 +8,10 @@
#include <stdlib.h>
#include <sys/types.h>
char *editorRowsToString(struct editorConfig *E, int *buffer_len);
void editorOpen(struct editorConfig *E, char *filename);
void editorSave(struct editorConfig *E);
#endif // FILE_IO_H_
+9
View File
@@ -4,6 +4,7 @@
#include "append_buffer.h"
#include "data.h"
#include "define.h"
#include "row_op.h"
#include <stdio.h>
#include <unistd.h>
@@ -16,4 +17,12 @@ void editorDrawRows(struct editorConfig *E, struct abuf *ab);
void editorRefreshScreen(struct editorConfig *E);
void editorScroll(struct editorConfig *E);
void editorDrawStatusBar(struct editorConfig *E, struct abuf *ab);
void editorDrawMessageBar(struct editorConfig *E, struct abuf *ab);
void editorSetStatusMessage(struct editorConfig *E, const char *fmt, ...);
#endif // OUTPUT_H_
+7
View File
@@ -2,10 +2,17 @@
#define ROW_OP_H_
#include "data.h"
#include "define.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int editorRowCxToRx(erow *row, int cursor_x);
void editorUpdateRow(erow *row);
void editorAppendRow(struct editorConfig *E, char *s, size_t len);
void editorRowInsertChar(erow *row, int at, int c);
#endif // ROW_OP_H_