add utf8_char_t struct

This commit is contained in:
Arthur Barraux
2025-11-19 10:37:41 +01:00
parent c06c820dfb
commit eae85c32ca
18 changed files with 770 additions and 339 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
#include <stdlib.h>
#include <string.h>
void abAppend(struct abuf *ab, const char *s, int len);
void abAppend(struct abuf *ab, const unsigned char *s, int len);
void abFree(struct abuf *ab);
+46 -5
View File
@@ -7,6 +7,12 @@
#include "lisp.h"
typedef struct{
unsigned char c[4];
char len;
} utf_8_char_t;
/**
* \struct erow
* \brief Store one editor row
@@ -16,8 +22,8 @@
typedef struct erow {
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 */
utf_8_char_t *chars; /**< Characters of the line */
utf_8_char_t *render; /**< The actual line we will print */
} erow;
enum editorStatus_e {
@@ -31,10 +37,45 @@ struct const_t {
int QUIT_TIMES;
};
// Key types
typedef enum {
KEY_CHAR, // Regular character or UTF-8
KEY_CTRL, // Ctrl+letter
KEY_ALT, // Alt+letter
KEY_ARROW, // Arrow keys
KEY_FUNCTION, // Function keys
KEY_SPECIAL, // Tab, Enter, ESC, Backspace, etc.
KEY_NAVIGATION, // Home, End, PgUp, PgDn, Insert, Delete
KEY_UNKNOWN
} KeyType;
// Modifiers
typedef enum {
MOD_NONE = 0,
MOD_SHIFT = 1,
MOD_ALT = 2,
MOD_CTRL = 4
} KeyModifier;
// Key information structure
typedef struct {
KeyType type;
int modifiers; // Bitmask of KeyModifier
union {
unsigned int codepoint; // For KEY_CHAR
char ctrl_char; // For KEY_CTRL (A-Z)
char alt_char; // For KEY_ALT
char arrow; // For KEY_ARROW (U/D/L/R)
int function_num; // For KEY_FUNCTION (1-12)
char special; // For KEY_SPECIAL and KEY_NAVIGATION
} data;
utf_8_char_t c; // Raw bytes
} KeyInfo;
struct keyBind_t {
char *key_sequence;
KeyInfo *key_sequence;
Lisp command;
};
/**
@@ -77,7 +118,7 @@ struct editorConfig {
* */
struct abuf {
char *b; /**< Text that will be printed */
unsigned char *b; /**< Text that will be printed */
int len; /**< Length of the text */
};
+3 -12
View File
@@ -8,19 +8,10 @@
#define HIDE_CURSOR "\x1b[?25l"
#define SHOW_CURSOR "\x1b[?25h"
#define ERASE_END_LINE "\x1b[K"
#define TAB "\x09"
#define SPACE "\x20"
enum editorKey {
BACKSPACE = 127,
ARROW_LEFT = 1000,
ARROW_RIGHT,
ARROW_UP,
ARROW_DOWN,
DEL_KEY,
BEG_LINE,
END_LINE,
PAGE_UP,
PAGE_DOWN,
};
#define ABUF_INIT {NULL, 0}
+2 -2
View File
@@ -2,9 +2,9 @@
#define EDITOR_OP_H_
#include "data.h"
void editorInsertChar(int c);
void editorInsertChar(utf_8_char_t *c);
void editorInsertNewLine();
void editorInsertNewLine(void);
void editorDelChar();
+2 -2
View File
@@ -24,9 +24,9 @@ char *editorPrompt(char *prompt, char * PlaceHolder, char bPathMode);
char *key_to_string(int key);
void editorMoveCursor(int key);
void editorMoveCursor(KeyInfo * key);
int executeKeyBind(char *key_sequence);
int executeKeyBind(KeyInfo *key_sequence);
/**
* \fn void editorProcessKeypress()
+1 -1
View File
@@ -20,7 +20,7 @@ void editorFreeRow(erow *row);
void editorDelRow(int at);
void editorRowInsertChar(erow *row, int at, int c);
void editorRowInsertChar(erow *row, int at, utf_8_char_t c);
void editorRowAppendString(erow *row, char *s, size_t len);
+3 -1
View File
@@ -25,10 +25,12 @@ void disableRawMode();
void enableRawMode();
int editorReadKey();
KeyInfo * editorReadKey();
int getCursorPosition(int *rows, int *cols);
KeyInfo *stringToCodepoint(const char *string);
int getWindowSize(int *rows, int *cols);
#endif