-
Notifications
You must be signed in to change notification settings - Fork 0
/
ronto.h
129 lines (110 loc) · 2.87 KB
/
ronto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
To use any function, anywhere without the compiler shouting
*/
#ifndef RONTO_H_
#define RONTO_H_
// We use the `vdprintf` function, which is a GNU Extension, and
// were described in POSIX.1-2008, so we define the POSIX C source
// to avoid `gcc` yelling about implicit functions
#define _POSIX_C_SOURCE 200809L
// Includes
#include <unistd.h>
#include <assert.h>
#include <ctype.h>
#include <getopt.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#include <stddef.h>
// struct defs
// Vim-like mode of the editor
typedef enum {
NORMAL,
INSERT
}Mode;
// Describes one row of the Editor
typedef struct row {
int idx; // Current index of the row
int size; // Number of chars, punctuations and tabs in this current row
int render_size; // size after adding all the tabs
char *content; // content of the row
char *render; // content ready for render - with tabs expanded
} row;
// Editor config & state
struct Editor {
int x;
int y;
row *r;
int numrow;
int coloff;
int rowoff;
int tabsize;
int screenrow;
int screencol;
bool save;
// File stream of the temporary file used for saving data
FILE *temp_file;
// File stream of the opened file
FILE *file;
char *file_name;
FILE *log;
Mode mode;
};
// a append buffer to flush everything at once
struct buf {
char *seq; int l;
};
// Basic Terminal Structure that holds some frequently used values - #GLOBAL
struct Terminal {
/*
The struct pointer definition is completely useless(especially because it's
global variable anyway).
One could easily use a non-pointer version. I just wanted to
see & learn, so used a pointer version.
Pitfalls here I come.
*/
struct termios *original_term;
bool is_raw;
int fd;
};
// Function defs:
void dbg(char *s, ...);
void editor_log(char *s, ...);
int isalnum_str(char *string);
int tabreplce(char* target, int pos);
int get_cursor_position(int *row, int *col);
bool init_editor(char *file);
void disable_raw_mode(void);
int enable_raw_mode(void);
void query_cursor_pos(int *x, int *y);
void get_window_size(int *row, int *col);
char *rowstostr(ssize_t *s);
void xclp_cpy(void);
void save_file_temp(ssize_t size, char *strings);
void save_file(void);
void bootstrap_file(char *file);
void bf_once(char *buf, ...);
void bf(char *buf, ...);
void bf_flush(void);
int add_row(int pos, char* buf, ssize_t len);
void remove_row(int row);
void add_char_at(char c, int at, int rowpos);
void insert_key(char c);
void insert_tab(void);
void delete_at(int rpos, int at);
void e_delete(void);
void enter_between(int row, int col);
void enter_key(void);
void shift_cursor(void);
void set_cursor(int row, int pos);
void arrow_key(int key);
int key_up(void);
int handle_key_press(void);
void expand_rows(void);
void refresh_screen(void);
#endif