libinput Generic way of gathering user commandline input
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m49s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m49s
This commit is contained in:
46
ce/edit.c
46
ce/edit.c
@@ -1,9 +1,9 @@
|
||||
#include "edit.h"
|
||||
#include "arena_alloc.h"
|
||||
#include "gapbuffer.h"
|
||||
#include "walloc.h"
|
||||
#include <arena.h>
|
||||
#include <filewriter.h>
|
||||
#include <in_gb.h>
|
||||
#include <kb.h>
|
||||
#include <list.h>
|
||||
#include <malloc.h>
|
||||
@@ -33,7 +33,7 @@ struct edit_line {
|
||||
struct list_node_link select_link;
|
||||
size_t select_start;
|
||||
size_t select_end;
|
||||
struct gapbuffer gb;
|
||||
struct in_gb gb;
|
||||
};
|
||||
|
||||
struct cursor {
|
||||
@@ -79,10 +79,10 @@ static bool prepare_lines_cb (void* ctx, const char* start, size_t len) {
|
||||
|
||||
memset (line, 0, sizeof (*line));
|
||||
size_t init_len = len > 0 ? len : 32;
|
||||
gapbuffer_init (&wmalloc, NULL, &line->gb, init_len);
|
||||
in_gb_init (&wmalloc, NULL, &line->gb, init_len);
|
||||
|
||||
for (size_t chr = 0; chr < len; chr++)
|
||||
gapbuffer_insert (&wrealloc, NULL, &line->gb, start[chr]);
|
||||
in_gb_insert (&wrealloc, NULL, &line->gb, start[chr]);
|
||||
|
||||
list_append (editor.lines, &line->lines_link);
|
||||
|
||||
@@ -246,17 +246,17 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
case '\b':
|
||||
if (editor.mode == EDIT_MODE_NORMAL) {
|
||||
if (editor.cursor.col > 0) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
in_gb_move (&editor.current_line->gb, editor.cursor.col);
|
||||
editor.cursor.col--;
|
||||
gapbuffer_backspace (&editor.current_line->gb);
|
||||
in_gb_backspace (&editor.current_line->gb);
|
||||
} else {
|
||||
if (editor.cursor.line > 0) {
|
||||
struct list_node_link* prev = editor.current_line->lines_link.prev;
|
||||
struct edit_line* prev_line = list_entry (prev, struct edit_line, lines_link);
|
||||
|
||||
size_t prev_len = gapbuffer_length (&prev_line->gb);
|
||||
size_t prev_len = in_gb_length (&prev_line->gb);
|
||||
|
||||
gapbuffer_concat (&wrealloc, NULL, &prev_line->gb, &editor.current_line->gb);
|
||||
in_gb_concat (&wrealloc, NULL, &prev_line->gb, &editor.current_line->gb);
|
||||
|
||||
list_remove (editor.lines, &editor.current_line->lines_link);
|
||||
free (editor.current_line->gb.buffer);
|
||||
@@ -272,26 +272,26 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
break;
|
||||
case '\t':
|
||||
if (editor.mode == EDIT_MODE_NORMAL) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
in_gb_move (&editor.current_line->gb, editor.cursor.col);
|
||||
for (size_t i = 0; i < sizeof (TAB_INSERT) - 1; i++)
|
||||
gapbuffer_insert (&wrealloc, NULL, &editor.current_line->gb, TAB_INSERT[i]);
|
||||
in_gb_insert (&wrealloc, NULL, &editor.current_line->gb, TAB_INSERT[i]);
|
||||
|
||||
editor.cursor.col += sizeof (TAB_INSERT) - 1;
|
||||
}
|
||||
break;
|
||||
case '\n': {
|
||||
if (editor.mode == EDIT_MODE_NORMAL) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
in_gb_move (&editor.current_line->gb, editor.cursor.col);
|
||||
|
||||
struct edit_line* new_line = malloc (sizeof (*new_line));
|
||||
memset (new_line, 0, sizeof (*new_line));
|
||||
|
||||
char* tail = gapbuffer_string_at (&warena_malloc, &temp_arena, &editor.current_line->gb,
|
||||
editor.cursor.col);
|
||||
char* tail = in_gb_string_at (&warena_malloc, &temp_arena, &editor.current_line->gb,
|
||||
editor.cursor.col);
|
||||
size_t tail_size = strlen (tail);
|
||||
size_t init_cap = tail_size > 0 ? tail_size : 32;
|
||||
|
||||
gapbuffer_init (&wmalloc, NULL, &new_line->gb, init_cap);
|
||||
in_gb_init (&wmalloc, NULL, &new_line->gb, init_cap);
|
||||
|
||||
if (tail_size > 0) {
|
||||
memcpy (new_line->gb.buffer,
|
||||
@@ -337,10 +337,10 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
} break;
|
||||
case KB_DELETE:
|
||||
if (editor.mode == EDIT_MODE_NORMAL) {
|
||||
size_t len = gapbuffer_length (&editor.current_line->gb);
|
||||
size_t len = in_gb_length (&editor.current_line->gb);
|
||||
|
||||
if (editor.cursor.col < len) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
in_gb_move (&editor.current_line->gb, editor.cursor.col);
|
||||
if (editor.current_line->gb.gap_end < editor.current_line->gb.size)
|
||||
editor.current_line->gb.gap_end++;
|
||||
} else {
|
||||
@@ -348,7 +348,7 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
struct list_node_link* next = editor.current_line->lines_link.next;
|
||||
struct edit_line* next_line = list_entry (next, struct edit_line, lines_link);
|
||||
|
||||
gapbuffer_concat (&wrealloc, NULL, &editor.current_line->gb, &next_line->gb);
|
||||
in_gb_concat (&wrealloc, NULL, &editor.current_line->gb, &next_line->gb);
|
||||
|
||||
list_remove (editor.lines, &next_line->lines_link);
|
||||
free (next_line->gb.buffer);
|
||||
@@ -362,7 +362,7 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
editor.cursor.col--;
|
||||
break;
|
||||
case KB_RIGHT:
|
||||
if (editor.cursor.col < gapbuffer_length (&editor.current_line->gb))
|
||||
if (editor.cursor.col < in_gb_length (&editor.current_line->gb))
|
||||
editor.cursor.col++;
|
||||
break;
|
||||
case KB_UP: {
|
||||
@@ -370,7 +370,7 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
editor.cursor.line--;
|
||||
editor.current_line =
|
||||
list_entry (editor.current_line->lines_link.prev, struct edit_line, lines_link);
|
||||
size_t len = gapbuffer_length (&editor.current_line->gb);
|
||||
size_t len = in_gb_length (&editor.current_line->gb);
|
||||
if (editor.cursor.col > len)
|
||||
editor.cursor.col = len;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
editor.cursor.line++;
|
||||
editor.current_line =
|
||||
list_entry (editor.current_line->lines_link.next, struct edit_line, lines_link);
|
||||
size_t len = gapbuffer_length (&editor.current_line->gb);
|
||||
size_t len = in_gb_length (&editor.current_line->gb);
|
||||
if (editor.cursor.col > len)
|
||||
editor.cursor.col = len;
|
||||
}
|
||||
@@ -389,7 +389,7 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
editor.cursor.col = 0;
|
||||
break;
|
||||
case KB_END:
|
||||
editor.cursor.col = gapbuffer_length (&editor.current_line->gb);
|
||||
editor.cursor.col = in_gb_length (&editor.current_line->gb);
|
||||
break;
|
||||
case KB_ESCAPE:
|
||||
if (editor.mode == EDIT_MODE_COMAMND) {
|
||||
@@ -411,8 +411,8 @@ void edit_start (const char* volume, const char* file_path, const char* text, si
|
||||
editor.cmdbuf.buffer[editor.cmdbuf.len] = '\0';
|
||||
}
|
||||
} else if (editor.mode == EDIT_MODE_NORMAL) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
gapbuffer_insert (&wrealloc, NULL, &editor.current_line->gb, ch);
|
||||
in_gb_move (&editor.current_line->gb, editor.cursor.col);
|
||||
in_gb_insert (&wrealloc, NULL, &editor.current_line->gb, ch);
|
||||
editor.cursor.col++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user