CE edit Introduce viewer mode
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 1m54s
Build documentation / build-and-deploy (push) Successful in 47s

This commit is contained in:
2026-04-29 02:13:49 +02:00
parent 1ea7b4171e
commit da621c7ec6
3 changed files with 60 additions and 9 deletions

View File

@@ -130,7 +130,8 @@ static size_t count_digits(size_t n) {
return count;
}
void edit_start(const char* volume, const char* file_path, const char* text, size_t text_len) {
void edit_start(const char* volume, const char* file_path, const char* text, size_t text_len,
bool readonly) {
editor.volume = volume;
editor.path = file_path;
@@ -244,7 +245,7 @@ void edit_start(const char* volume, const char* file_path, const char* text, siz
switch (ch) {
case '\b':
if (editor.mode == EDIT_MODE_NORMAL) {
if (editor.mode == EDIT_MODE_NORMAL && !readonly) {
if (editor.cursor.col > 0) {
in_gb_move(&editor.current_line->gb, editor.cursor.col);
editor.cursor.col--;
@@ -271,7 +272,7 @@ void edit_start(const char* volume, const char* file_path, const char* text, siz
}
break;
case '\t':
if (editor.mode == EDIT_MODE_NORMAL) {
if (editor.mode == EDIT_MODE_NORMAL && !readonly) {
in_gb_move(&editor.current_line->gb, editor.cursor.col);
for (size_t i = 0; i < sizeof(TAB_INSERT) - 1; i++)
in_gb_insert(&wrealloc, NULL, &editor.current_line->gb, TAB_INSERT[i]);
@@ -280,7 +281,7 @@ void edit_start(const char* volume, const char* file_path, const char* text, siz
}
break;
case '\n': {
if (editor.mode == EDIT_MODE_NORMAL) {
if (editor.mode == EDIT_MODE_NORMAL && !readonly) {
in_gb_move(&editor.current_line->gb, editor.cursor.col);
struct edit_line* new_line = malloc(sizeof(*new_line));
@@ -311,7 +312,7 @@ void edit_start(const char* volume, const char* file_path, const char* text, siz
if (strcmp(editor.cmdbuf.buffer, "q") == 0) {
edit_run = false;
editor.mode = EDIT_MODE_NORMAL;
} else if (strcmp(editor.cmdbuf.buffer, "w") == 0) {
} else if (strcmp(editor.cmdbuf.buffer, "w") == 0 && !readonly) {
struct filewriter fw;
if (!(filewriter_init(&fw, editor.volume, editor.path, FW_CREATE_FILE) < 0)) {
struct list_node_link *line_link, *tmp_line_link;
@@ -335,7 +336,7 @@ void edit_start(const char* volume, const char* file_path, const char* text, siz
}
} break;
case KB_DELETE:
if (editor.mode == EDIT_MODE_NORMAL) {
if (editor.mode == EDIT_MODE_NORMAL && !readonly) {
size_t len = in_gb_length(&editor.current_line->gb);
if (editor.cursor.col < len) {
@@ -409,7 +410,7 @@ void edit_start(const char* volume, const char* file_path, const char* text, siz
editor.cmdbuf.buffer[editor.cmdbuf.len++] = ch;
editor.cmdbuf.buffer[editor.cmdbuf.len] = '\0';
}
} else if (editor.mode == EDIT_MODE_NORMAL) {
} else if (editor.mode == EDIT_MODE_NORMAL && !readonly) {
in_gb_move(&editor.current_line->gb, editor.cursor.col);
in_gb_insert(&wrealloc, NULL, &editor.current_line->gb, ch);
editor.cursor.col++;