pre-scrolling
This commit is contained in:
parent
7271dc323d
commit
1713acd5e8
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,4 @@
|
|||||||
cmake-*
|
cmake-*
|
||||||
|
CMakeC*
|
||||||
|
CMakeF*
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
project(editor)
|
project(tted)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
add_executable(editor tte.c)
|
add_executable(tted tted.c)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
/** defines */
|
/** defines */
|
||||||
#define TYREL_VERSION "0.0.1"
|
#define TTED_VERSION "0.0.1"
|
||||||
#define CTRL_KEY(k) ((k) & 0x1f)
|
#define CTRL_KEY(k) ((k) & 0x1f)
|
||||||
|
|
||||||
enum editorKey {
|
enum editorKey {
|
||||||
@ -38,6 +38,7 @@ typedef struct erow {
|
|||||||
|
|
||||||
struct editorConfig {
|
struct editorConfig {
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
|
int rowoff;
|
||||||
int screenrows;
|
int screenrows;
|
||||||
int screencols;
|
int screencols;
|
||||||
int numrows;
|
int numrows;
|
||||||
@ -165,19 +166,20 @@ int getWindowSize(int *rows, int *cols) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Row operations */
|
/** Row operations */
|
||||||
void editorAppendRow(char *s, size_t len) {
|
void editorAppendRow(char *s, size_t len) {
|
||||||
E.row = realloc(E.row, sizeof(erow) * (E.numrows+1));
|
E.row = realloc(E.row, sizeof(erow) * (E.numrows + 1));
|
||||||
|
|
||||||
int at = E.numrows;
|
int at = E.numrows;
|
||||||
E.row[at].size = len;
|
E.row[at].size = len;
|
||||||
E.row[at].chars = malloc(len+1);
|
E.row[at].chars = malloc(len + 1);
|
||||||
memcpy(E.row[at].chars, s, len);
|
memcpy(E.row[at].chars, s, len);
|
||||||
E.row[at].chars[len] = '\0';
|
E.row[at].chars[len] = '\0';
|
||||||
E.numrows++;
|
E.numrows++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** file i/o */
|
/** file i/o */
|
||||||
|
|
||||||
void editorOpen(char *filename) {
|
void editorOpen(char *filename) {
|
||||||
FILE *fp = fopen(filename, "r");
|
FILE *fp = fopen(filename, "r");
|
||||||
if (!fp) die("fopen");
|
if (!fp) die("fopen");
|
||||||
@ -185,8 +187,7 @@ void editorOpen(char *filename) {
|
|||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t linecap = 0;
|
size_t linecap = 0;
|
||||||
ssize_t linelen;
|
ssize_t linelen;
|
||||||
linelen = getline(&line, &linecap, fp);
|
while ((linelen = getline(&line, &linecap, fp)) != -1) {
|
||||||
while((linelen = getline(&line, &linecap, fp)) != -1) {
|
|
||||||
while (linelen > 0 && (line[linelen - 1] == '\n' ||
|
while (linelen > 0 && (line[linelen - 1] == '\n' ||
|
||||||
line[linelen - 1] == '\r'))
|
line[linelen - 1] == '\r'))
|
||||||
linelen--;
|
linelen--;
|
||||||
@ -197,7 +198,6 @@ void editorOpen(char *filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** append buffer */
|
/** append buffer */
|
||||||
struct abuf {
|
struct abuf {
|
||||||
char *b;
|
char *b;
|
||||||
@ -226,7 +226,8 @@ void editorDrawRows(struct abuf *ab) {
|
|||||||
if (y >= E.numrows) { // Draw rows after buffer
|
if (y >= E.numrows) { // Draw rows after buffer
|
||||||
if (E.numrows == 0 && y == E.screenrows / 3) {
|
if (E.numrows == 0 && y == E.screenrows / 3) {
|
||||||
char welcome[80];
|
char welcome[80];
|
||||||
int welcomelen = snprintf(welcome, sizeof welcome, "Tyrel Editor -- version %s", TYREL_VERSION);
|
int welcomelen = snprintf(welcome, sizeof welcome, "Tyrel Text Editor Deluxe -- version %s",
|
||||||
|
TTED_VERSION);
|
||||||
int padding = (E.screencols - welcomelen) / 2;
|
int padding = (E.screencols - welcomelen) / 2;
|
||||||
if (padding) {
|
if (padding) {
|
||||||
abAppend(ab, "~", 1);
|
abAppend(ab, "~", 1);
|
||||||
@ -330,6 +331,7 @@ void editorProcessKeypress() {
|
|||||||
void initEditor() {
|
void initEditor() {
|
||||||
E.cx = 0;
|
E.cx = 0;
|
||||||
E.cy = 0;
|
E.cy = 0;
|
||||||
|
E.rowoff = 0;
|
||||||
E.numrows = 0;
|
E.numrows = 0;
|
||||||
E.row = NULL;
|
E.row = NULL;
|
||||||
if (getWindowSize(&E.screenrows, &E.screencols) == -1) die("getWindowSize");
|
if (getWindowSize(&E.screenrows, &E.screencols) == -1) die("getWindowSize");
|
||||||
@ -347,4 +349,4 @@ int main(int argc, char *argv[]) {
|
|||||||
editorProcessKeypress();
|
editorProcessKeypress();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user