aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-04-22 11:47:38 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-04-22 12:35:15 +0200
commit7318931acca4e6928a8014dd00dc66f6f061b6c4 (patch)
treeea8bc1b754f7cd2b609fc71ee69ff66a8e6a0eab
parent4d7c630ff37fd0609aa58f60d6bd08fe53e57533 (diff)
downloadvis-7318931acca4e6928a8014dd00dc66f6f061b6c4.tar.gz
vis-7318931acca4e6928a8014dd00dc66f6f061b6c4.tar.xz
More renames, no functional changes
Win -> View, window_* -> view_*
-rw-r--r--config.def.h24
-rw-r--r--editor.c48
-rw-r--r--editor.h6
-rw-r--r--ui-curses.c24
-rw-r--r--ui.h4
-rw-r--r--vis.c164
-rw-r--r--window.c706
-rw-r--r--window.h84
8 files changed, 530 insertions, 530 deletions
diff --git a/config.def.h b/config.def.h
index 28f1ae5..88c032c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -410,9 +410,9 @@ static KeyBinding vis_mode_normal[] = {
{ { NONE(':') }, prompt_cmd, { .s = "" } },
{ { NONE('Z'), NONE('Z') }, cmd, { .s = "wq" } },
{ { NONE('Z'), NONE('Q') }, cmd, { .s = "q!" } },
- { { NONE('z'), NONE('t') }, window, { .w = window_redraw_top } },
- { { NONE('z'), NONE('z') }, window, { .w = window_redraw_center } },
- { { NONE('z'), NONE('b') }, window, { .w = window_redraw_bottom } },
+ { { NONE('z'), NONE('t') }, window, { .w = view_redraw_top } },
+ { { NONE('z'), NONE('z') }, window, { .w = view_redraw_center } },
+ { { NONE('z'), NONE('b') }, window, { .w = view_redraw_bottom } },
{ { NONE('q') }, macro_record, { NULL } },
{ { NONE('@') }, macro_replay, { NULL } },
{ /* empty last element, array terminator */ },
@@ -440,14 +440,14 @@ static KeyBinding vis_mode_visual[] = {
static void vis_mode_visual_enter(Mode *old) {
if (!old->visual) {
- window_selection_start(vis->win->view);
+ view_selection_start(vis->win->view);
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_TEXTOBJ];
}
}
static void vis_mode_visual_leave(Mode *new) {
if (!new->visual) {
- window_selection_clear(vis->win->view);
+ view_selection_clear(vis->win->view);
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_MOVE];
}
}
@@ -459,10 +459,10 @@ static KeyBinding vis_mode_visual_line[] = {
};
static void vis_mode_visual_line_enter(Mode *old) {
- Win *win = vis->win->view;
- window_cursor_to(win, text_line_begin(vis->win->file->text, window_cursor_get(win)));
+ View *view = vis->win->view;
+ view_cursor_to(view, text_line_begin(vis->win->file->text, view_cursor_get(view)));
if (!old->visual) {
- window_selection_start(vis->win->view);
+ view_selection_start(view);
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_TEXTOBJ];
}
movement(&(const Arg){ .i = MOVE_LINE_END });
@@ -470,10 +470,10 @@ static void vis_mode_visual_line_enter(Mode *old) {
static void vis_mode_visual_line_leave(Mode *new) {
if (!new->visual) {
- window_selection_clear(vis->win->view);
+ view_selection_clear(vis->win->view);
vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_MOVE];
} else {
- window_cursor_to(vis->win->view, window_cursor_get(vis->win->view));
+ view_cursor_to(vis->win->view, view_cursor_get(vis->win->view));
}
}
@@ -573,7 +573,7 @@ static void vis_mode_insert_idle(void) {
static void vis_mode_insert_input(const char *str, size_t len) {
static size_t oldpos = EPOS;
- size_t pos = window_cursor_get(vis->win->view);
+ size_t pos = view_cursor_get(vis->win->view);
if (pos != oldpos)
buffer_truncate(&vis->buffer_repeat);
buffer_append(&vis->buffer_repeat, str, len);
@@ -595,7 +595,7 @@ static void vis_mode_replace_leave(Mode *old) {
static void vis_mode_replace_input(const char *str, size_t len) {
static size_t oldpos = EPOS;
- size_t pos = window_cursor_get(vis->win->view);
+ size_t pos = view_cursor_get(vis->win->view);
if (pos != oldpos)
buffer_truncate(&vis->buffer_repeat);
buffer_append(&vis->buffer_repeat, str, len);
diff --git a/editor.c b/editor.c
index dcc0863..955894d 100644
--- a/editor.c
+++ b/editor.c
@@ -34,7 +34,7 @@ bool editor_window_reload(EditorWin *win) {
return false;
file_free(win->editor, win->file);
win->file = file;
- window_reload(win->view, file->text);
+ view_reload(win->view, file->text);
return true;
}
@@ -44,8 +44,8 @@ bool editor_window_split(EditorWin *original) {
return false;
win->file = original->file;
win->file->refcount++;
- window_syntax_set(win->view, window_syntax_get(original->view));
- window_cursor_to(win->view, window_cursor_get(original->view));
+ view_syntax_set(win->view, view_syntax_get(original->view));
+ view_cursor_to(win->view, view_cursor_get(original->view));
editor_draw(win->editor);
return true;
}
@@ -57,7 +57,7 @@ void editor_window_jumplist_add(EditorWin *win, size_t pos) {
}
size_t editor_window_jumplist_prev(EditorWin *win) {
- size_t cur = window_cursor_get(win->view);
+ size_t cur = view_cursor_get(win->view);
while (win->jumplist) {
Mark mark = ringbuf_prev(win->jumplist);
if (!mark)
@@ -70,7 +70,7 @@ size_t editor_window_jumplist_prev(EditorWin *win) {
}
size_t editor_window_jumplist_next(EditorWin *win) {
- size_t cur = window_cursor_get(win->view);
+ size_t cur = view_cursor_get(win->view);
while (win->jumplist) {
Mark mark = ringbuf_next(win->jumplist);
if (!mark)
@@ -88,7 +88,7 @@ void editor_window_jumplist_invalidate(EditorWin *win) {
}
size_t editor_window_changelist_prev(EditorWin *win) {
- size_t pos = window_cursor_get(win->view);
+ size_t pos = view_cursor_get(win->view);
if (pos != win->changelist.pos)
win->changelist.index = 0;
else
@@ -102,7 +102,7 @@ size_t editor_window_changelist_prev(EditorWin *win) {
}
size_t editor_window_changelist_next(EditorWin *win) {
- size_t pos = window_cursor_get(win->view);
+ size_t pos = view_cursor_get(win->view);
if (pos != win->changelist.pos)
win->changelist.index = 0;
else if (win->changelist.index > 0)
@@ -142,7 +142,7 @@ void editor_window_prev(Editor *ed) {
static void editor_windows_invalidate(Editor *ed, size_t start, size_t end) {
for (EditorWin *win = ed->windows; win; win = win->next) {
if (ed->win != win && ed->win->file == win->file) {
- Filerange view = window_viewport_get(win->view);
+ Filerange view = view_viewport_get(win->view);
if ((view.start <= start && start <= view.end) ||
(view.start <= end && end <= view.end))
win->ui->draw(win->ui);
@@ -159,7 +159,7 @@ void editor_tabwidth_set(Editor *ed, int tabwidth) {
if (tabwidth < 1 || tabwidth > 8)
return;
for (EditorWin *win = ed->windows; win; win = win->next)
- window_tabwidth_set(win->view, tabwidth);
+ view_tabwidth_set(win->view, tabwidth);
ed->tabwidth = tabwidth;
}
@@ -223,7 +223,7 @@ static void editor_window_free(EditorWin *win) {
Editor *ed = win->editor;
if (ed && ed->ui)
ed->ui->window_free(win->ui);
- window_free(win->view);
+ view_free(win->view);
ringbuf_free(win->jumplist);
free(win);
}
@@ -239,13 +239,13 @@ static EditorWin *editor_window_new_file(Editor *ed, File *file) {
.selection = editor_window_selection_changed,
};
win->jumplist = ringbuf_alloc(31);
- win->view = window_new(file->text, &win->events);
+ win->view = view_new(file->text, &win->events);
win->ui = ed->ui->window_new(ed->ui, win->view, file->text);
if (!win->jumplist || !win->view || !win->ui) {
editor_window_free(win);
return NULL;
}
- window_tabwidth_set(win->view, ed->tabwidth);
+ view_tabwidth_set(win->view, ed->tabwidth);
if (ed->windows)
ed->windows->prev = win;
win->next = ed->windows;
@@ -328,7 +328,7 @@ bool editor_window_new(Editor *ed, const char *filename) {
if (filename) {
for (Syntax *syn = ed->syntaxes; syn && syn->name; syn++) {
if (!regexec(&syn->file_regex, filename, 0, NULL, 0)) {
- window_syntax_set(win->view, syn);
+ view_syntax_set(win->view, syn);
break;
}
}
@@ -389,7 +389,7 @@ Editor *editor_new(Ui *ui) {
goto err;
if (!(ed->prompt->file->text = text_load(NULL)))
goto err;
- if (!(ed->prompt->view = window_new(ed->prompt->file->text, NULL)))
+ if (!(ed->prompt->view = view_new(ed->prompt->file->text, NULL)))
goto err;
if (!(ed->prompt->ui = ed->ui->prompt_new(ed->ui, ed->prompt->view, ed->prompt->file->text)))
goto err;
@@ -420,28 +420,28 @@ void editor_free(Editor *ed) {
}
void editor_insert_key(Editor *ed, const char *c, size_t len) {
- Win *win = ed->win->view;
- size_t start = window_cursor_get(win);
- window_insert_key(win, c, len);
+ View *view = ed->win->view;
+ size_t start = view_cursor_get(view);
+ view_insert_key(view, c, len);
editor_windows_invalidate(ed, start, start + len);
}
void editor_replace_key(Editor *ed, const char *c, size_t len) {
- Win *win = ed->win->view;
- size_t start = window_cursor_get(win);
- window_replace_key(win, c, len);
+ View *view = ed->win->view;
+ size_t start = view_cursor_get(view);
+ view_replace_key(view, c, len);
editor_windows_invalidate(ed, start, start + 6);
}
void editor_backspace_key(Editor *ed) {
- Win *win = ed->win->view;
- size_t end = window_cursor_get(win);
- size_t start = window_backspace_key(win);
+ View *view = ed->win->view;
+ size_t end = view_cursor_get(view);
+ size_t start = view_backspace_key(view);
editor_windows_invalidate(ed, start, end);
}
void editor_delete_key(Editor *ed) {
- size_t start = window_delete_key(ed->win->view);
+ size_t start = view_delete_key(ed->win->view);
editor_windows_invalidate(ed, start, start + 6);
}
diff --git a/editor.h b/editor.h
index 5d038c1..a3e220b 100644
--- a/editor.h
+++ b/editor.h
@@ -22,7 +22,7 @@ typedef union {
bool b;
int i;
const char *s;
- void (*w)(Win*); /* generic window commands */
+ void (*w)(View*); /* generic window commands */
void (*f)(Editor*); /* generic editor commands */
} Arg;
@@ -79,7 +79,7 @@ typedef struct {
typedef struct {
size_t (*cmd)(const Arg*); /* a custom movement based on user input from vis.c */
- size_t (*win)(Win*); /* a movement based on current window content from window.h */
+ size_t (*view)(View*); /* a movement based on current window content from window.h */
size_t (*txt)(Text*, size_t pos); /* a movement form text-motions.h */
size_t (*file)(File*, size_t pos);
enum {
@@ -207,7 +207,7 @@ struct EditorWin {
Editor *editor; /* editor instance to which this window belongs */
UiWin *ui;
File *file; /* file being displayed in this window */
- Win *view; /* currently displayed part of underlying text */
+ View *view; /* currently displayed part of underlying text */
ViewEvent events;
RingBuffer *jumplist; /* LRU jump management */
ChangeList changelist; /* state for iterating through least recently changes */
diff --git a/ui-curses.c b/ui-curses.c
index 6217da5..a999aef 100644
--- a/ui-curses.c
+++ b/ui-curses.c
@@ -66,7 +66,7 @@ struct UiCursesWin {
UiWin uiwin; /* generic interface, has to be the first struct member */
UiCurses *ui; /* ui which manages this window */
Text *text; /* underlying text management */
- Win *view; /* current viewport */
+ View *view; /* current viewport */
WINDOW *win; /* curses window for the text area */
WINDOW *winstatus; /* curses window for the status bar */
WINDOW *winside; /* curses window for the side bar (line numbers) */
@@ -147,7 +147,7 @@ static void ui_window_resize(UiCursesWin *win, int width, int height) {
wresize(win->win, win->winstatus ? height - 1 : height, width - win->sidebar_width);
if (win->winside)
wresize(win->winside, height-1, win->sidebar_width);
- window_resize(win->view, width - win->sidebar_width, win->winstatus ? height - 1 : height);
+ view_resize(win->view, width - win->sidebar_width, win->winstatus ? height - 1 : height);
}
static void ui_window_move(UiCursesWin *win, int x, int y) {
@@ -168,7 +168,7 @@ static void ui_window_draw_status(UiWin *w) {
Editor *vis = uic->ed;
bool focused = uic->selwin == win;
const char *filename = text_filename_get(win->text);
- CursorPos pos = window_cursor_getpos(win->view);
+ CursorPos pos = view_cursor_getpos(win->view);
wattrset(win->winstatus, focused ? A_REVERSE|A_BOLD : A_REVERSE);
mvwhline(win->winstatus, 0, 0, ' ', win->width);
mvwprintw(win->winstatus, 0, 0, "%s %s %s %s",
@@ -188,8 +188,8 @@ static void ui_window_draw(UiWin *w) {
UiCursesWin *win = (UiCursesWin*)w;
if (win->winstatus)
ui_window_draw_status((UiWin*)win);
- window_draw(win->view);
- window_cursor_to(win->view, window_cursor_get(win->view));
+ view_draw(win->view);
+ view_cursor_to(win->view, view_cursor_get(win->view));
}
static void ui_window_reload(UiWin *w, Text *text) {
@@ -210,7 +210,7 @@ static void ui_window_draw_sidebar(UiCursesWin *win, const Line *line) {
} else {
int i = 0;
size_t prev_lineno = 0;
- size_t cursor_lineno = window_cursor_getpos(win->view).line;
+ size_t cursor_lineno = view_cursor_getpos(win->view).line;
werase(win->winside);
for (const Line *l = line; l; l = l->next, i++) {
if (l->lineno != prev_lineno) {
@@ -359,7 +359,7 @@ static void ui_window_cursor_to(UiWin *w, int x, int y) {
wmove(win->win, y, x);
ui_window_draw_status(w);
if (win->options & UI_OPTION_LINE_NUMBERS_RELATIVE)
- ui_window_draw_sidebar(win, window_lines_get(win->view));
+ ui_window_draw_sidebar(win, view_lines_get(win->view));
}
static void ui_window_draw_text(UiWin *w, const Line *line) {
@@ -413,7 +413,7 @@ static void ui_window_options(UiWin *w, enum UiOption options) {
ui_window_draw(w);
}
-static UiWin *ui_window_new(Ui *ui, Win *view, Text *text) {
+static UiWin *ui_window_new(Ui *ui, View *view, Text *text) {
UiCurses *uic = (UiCurses*)ui;
UiCursesWin *win = calloc(1, sizeof(UiCursesWin));
if (!win)
@@ -436,7 +436,7 @@ static UiWin *ui_window_new(Ui *ui, Win *view, Text *text) {
win->ui = uic;
win->view = view;
win->text = text;
- window_ui(view, &win->uiwin);
+ view_ui(view, &win->uiwin);
if (uic->windows)
uic->windows->prev = win;
@@ -460,7 +460,7 @@ static void info_hide(Ui *ui) {
}
}
-static UiWin *prompt_new(Ui *ui, Win *view, Text *text) {
+static UiWin *prompt_new(Ui *ui, View *view, Text *text) {
UiCurses *uic = (UiCurses*)ui;
if (uic->prompt_win)
return (UiWin*)uic->prompt_win;
@@ -489,9 +489,9 @@ static void prompt(Ui *ui, const char *title, const char *text) {
strncpy(uic->prompt_title, title, sizeof(uic->prompt_title)-1);
while (text_undo(uic->prompt_win->text) != EPOS);
text_insert(uic->prompt_win->text, 0, text, text_len);
- window_cursor_to(uic->prompt_win->view, 0);
+ view_cursor_to(uic->prompt_win->view, 0);
ui_resize_to(ui, uic->width, uic->height);
- window_cursor_to(uic->prompt_win->view, text_len);
+ view_cursor_to(uic->prompt_win->view, text_len);
}
static char *prompt_input(Ui *ui) {
diff --git a/ui.h b/ui.h
index 073bd09..1d3df4b 100644
--- a/ui.h
+++ b/ui.h
@@ -26,10 +26,10 @@ struct Ui {
void (*free)(Ui*);
short (*color_get)(short fg, short bg);
void (*resize)(Ui*);
- UiWin* (*window_new)(Ui*, Win*, Text*);
+ UiWin* (*window_new)(Ui*, View*, Text*);
void (*window_free)(UiWin*);
void (*window_focus)(UiWin*);
- UiWin* (*prompt_new)(Ui*, Win*, Text*);
+ UiWin* (*prompt_new)(Ui*, View*, Text*);
void (*prompt)(Ui*, const char *title, const char *value);
char* (*prompt_input)(Ui*);
void (*prompt_hide)(Ui*);
diff --git a/vis.c b/vis.c
index feedfc0..0fdd11d 100644
--- a/vis.c
+++ b/vis.c
@@ -159,20 +159,20 @@ static size_t line(Text *txt, size_t pos);
/* goto to byte action.count on current line */
static size_t column(Text *txt, size_t pos);
/* goto the action.count-th line from top of the focused window */
-static size_t window_lines_top(const Arg *arg);
+static size_t view_lines_top(const Arg *arg);
/* goto the start of middle line of the focused window */
-static size_t window_lines_middle(const Arg *arg);
+static size_t view_lines_middle(const Arg *arg);
/* goto the action.count-th line from bottom of the focused window */
-static size_t window_lines_bottom(const Arg *arg);
+static size_t view_lines_bottom(const Arg *arg);
static Movement moves[] = {
- [MOVE_LINE_UP] = { .win = window_line_up },
- [MOVE_LINE_DOWN] = { .win = window_line_down },
- [MOVE_SCREEN_LINE_UP] = { .win = window_screenline_up },
- [MOVE_SCREEN_LINE_DOWN] = { .win = window_screenline_down },
- [MOVE_SCREEN_LINE_BEGIN] = { .win = window_screenline_begin, .type = CHARWISE },
- [MOVE_SCREEN_LINE_MIDDLE] = { .win = window_screenline_middle, .type = CHARWISE },
- [MOVE_SCREEN_LINE_END] = { .win = window_screenline_end, .type = CHARWISE|INCLUSIVE },
+ [MOVE_LINE_UP] = { .view = view_line_up },
+ [MOVE_LINE_DOWN] = { .view = view_line_down },
+ [MOVE_SCREEN_LINE_UP] = { .view = view_screenline_up },
+ [MOVE_SCREEN_LINE_DOWN] = { .view = view_screenline_down },
+ [MOVE_SCREEN_LINE_BEGIN] = { .view = view_screenline_begin, .type = CHARWISE },
+ [MOVE_SCREEN_LINE_MIDDLE] = { .view = view_screenline_middle, .type = CHARWISE },
+ [MOVE_SCREEN_LINE_END] = { .view = view_screenline_end, .type = CHARWISE|INCLUSIVE },
[MOVE_LINE_PREV] = { .txt = text_line_prev, .type = LINEWISE },
[MOVE_LINE_BEGIN] = { .txt = text_line_begin, .type = LINEWISE },
[MOVE_LINE_START] = { .txt = text_line_start, .type = LINEWISE },
@@ -182,8 +182,8 @@ static Movement moves[] = {
[MOVE_LINE_NEXT] = { .txt = text_line_next, .type = LINEWISE },
[MOVE_LINE] = { .txt = line, .type = LINEWISE|IDEMPOTENT|JUMP},
[MOVE_COLUMN] = { .txt = column, .type = CHARWISE|IDEMPOTENT},
- [MOVE_CHAR_PREV] = { .win = window_char_prev },
- [MOVE_CHAR_NEXT] = { .win = window_char_next },
+ [MOVE_CHAR_PREV] = { .view = view_char_prev },
+ [MOVE_CHAR_NEXT] = { .view = view_char_next },
[MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE },
[MOVE_WORD_START_NEXT] = { .txt = text_word_start_next, .type = CHARWISE },
[MOVE_WORD_END_PREV] = { .txt = text_word_end_prev, .type = CHARWISE|INCLUSIVE },
@@ -209,9 +209,9 @@ static Movement moves[] = {
[MOVE_SEARCH_WORD_BACKWARD]= { .txt = search_word_backward, .type = LINEWISE|JUMP },
[MOVE_SEARCH_FORWARD] = { .txt = search_forward, .type = LINEWISE|JUMP },
[MOVE_SEARCH_BACKWARD] = { .txt = search_backward, .type = LINEWISE|JUMP },
- [MOVE_WINDOW_LINE_TOP] = { .cmd = window_lines_top, .type = LINEWISE|JUMP|IDEMPOTENT },
- [MOVE_WINDOW_LINE_MIDDLE] = { .cmd = window_lines_middle, .type = LINEWISE|JUMP|IDEMPOTENT },
- [MOVE_WINDOW_LINE_BOTTOM] = { .cmd = window_lines_bottom, .type = LINEWISE|JUMP|IDEMPOTENT },
+ [MOVE_WINDOW_LINE_TOP] = { .cmd = view_lines_top, .type = LINEWISE|JUMP|IDEMPOTENT },
+ [MOVE_WINDOW_LINE_MIDDLE] = { .cmd = view_lines_middle, .type = LINEWISE|JUMP|IDEMPOTENT },
+ [MOVE_WINDOW_LINE_BOTTOM] = { .cmd = view_lines_bottom, .type = LINEWISE|JUMP|IDEMPOTENT },
};
/* these can be passed as int argument to textobj(&(const Arg){ .i = TEXT_OBJ_* }) */
@@ -433,7 +433,7 @@ static void op_delete(OperatorContext *c) {
c->reg->linewise = c->linewise;
register_put(c->reg, vis->win->file->text, &c->range);
editor_delete(vis, c->range.start, len);
- window_cursor_to(vis->win->view, c->range.start);
+ view_cursor_to(vis->win->view, c->range.start);
}
static void op_change(OperatorContext *c) {
@@ -448,7 +448,7 @@ static void op_yank(OperatorContext *c) {
static void op_put(OperatorContext *c) {
Text *txt = vis->win->file->text;
- size_t pos = window_cursor_get(vis->win->view);
+ size_t pos = view_cursor_get(vis->win->view);
if (c->arg->i > 0) {
if (c->reg->linewise)
pos = text_line_next(txt, pos);
@@ -460,9 +460,9 @@ static void op_put(OperatorContext *c) {
}
editor_insert(vis, pos, c->reg->data, c->reg->len);
if (c->reg->linewise)
- window_cursor_to(vis->win->view, text_line_start(txt, pos));
+ view_cursor_to(vis->win->view, text_line_start(txt, pos));
else
- window_cursor_to(vis->win->view, pos + c->reg->len);
+ view_cursor_to(vis->win->view, pos + c->reg->len);
}
static const char *expand_tab(void) {
@@ -490,7 +490,7 @@ static void op_shift_right(OperatorContext *c) {
text_insert(txt, pos, tab, tablen);
pos = text_line_prev(txt, pos);
} while (pos >= c->range.start && pos != prev_pos);
- window_cursor_to(vis->win->view, c->pos + tablen);
+ view_cursor_to(vis->win->view, c->pos + tablen);
editor_draw(vis);
}
@@ -518,7 +518,7 @@ static void op_shift_left(OperatorContext *c) {
text_delete(txt, pos, tablen);
pos = text_line_prev(txt, pos);
} while (pos >= c->range.start && pos != prev_pos);
- window_cursor_to(vis->win->view, c->pos - tablen);
+ view_cursor_to(vis->win->view, c->pos - tablen);
editor_draw(vis);
}
@@ -550,7 +550,7 @@ static void op_case_change(OperatorContext *c) {
static void op_join(OperatorContext *c) {
Text *txt = vis->win->file->text;
size_t pos = text_line_begin(txt, c->range.end), prev_pos;
- Filerange sel = window_selection_get(vis->win->view);
+ Filerange sel = view_selection_get(vis->win->view);
/* if a selection ends at the begin of a line, skip line break */
if (pos == c->range.end && text_range_valid(&sel))
pos = text_line_prev(txt, pos);
@@ -567,7 +567,7 @@ static void op_join(OperatorContext *c) {
}
} while (pos != prev_pos);
- window_cursor_to(vis->win->view, c->range.start);
+ view_cursor_to(vis->win->view, c->range.start);
editor_draw(vis);
}
@@ -576,7 +576,7 @@ static void op_repeat_insert(OperatorContext *c) {
if (!len)
return;
editor_insert(vis, c->pos, vis->buffer_repeat.data, len);
- window_cursor_to(vis->win->view, c->pos + len);
+ view_cursor_to(vis->win->view, c->pos + len);
}
static void op_repeat_replace(OperatorContext *c) {
@@ -636,7 +636,7 @@ static size_t search_backward(Text *txt, size_t pos) {
}
static void mark_set(const Arg *arg) {
- size_t pos = window_cursor_get(vis->win->view);
+ size_t pos = view_cursor_get(vis->win->view);
vis->win->file->marks[arg->i] = text_mark_set(vis->win->file->text, pos);
}
@@ -688,18 +688,18 @@ static size_t column(Text *txt, size_t pos) {
return text_line_offset(txt, pos, vis->action.count);
}
-static size_t window_lines_top(const Arg *arg) {
- return window_screenline_goto(vis->win->view, vis->action.count);
+static size_t view_lines_top(const Arg *arg) {
+ return view_screenline_goto(vis->win->view, vis->action.count);
}
-static size_t window_lines_middle(const Arg *arg) {
- int h = window_height_get(vis->win->view);
- return window_screenline_goto(vis->win->view, h/2);
+static size_t view_lines_middle(const Arg *arg) {
+ int h = view_height_get(vis->win->view);
+ return view_screenline_goto(vis->win->view, h/2);
}
-static size_t window_lines_bottom(const Arg *arg) {
- int h = window_height_get(vis->win->view);
- return window_screenline_goto(vis->win->view, h - vis->action.count);
+static size_t view_lines_bottom(const Arg *arg) {
+ int h = view_height_get(vis->win->view);
+ return view_screenline_goto(vis->win->view, h - vis->action.count);
}
/** key bindings functions of type: void (*func)(const Arg*) */
@@ -711,7 +711,7 @@ static void jumplist(const Arg *arg) {
else
pos = editor_window_jumplist_prev(vis->win);
if (pos != EPOS)
- window_cursor_to(vis->win->view, pos);
+ view_cursor_to(vis->win->view, pos);
}
static void changelist(const Arg *arg) {
@@ -721,7 +721,7 @@ static void changelist(const Arg *arg) {
else
pos = editor_window_changelist_prev(vis->win);
if (pos != EPOS)
- window_cursor_to(vis->win->view, pos);
+ view_cursor_to(vis->win->view, pos);
}
static Macro *key2macro(const Arg *arg) {
@@ -801,14 +801,14 @@ static void replace(const Arg *arg) {
Key k = getkey();
if (!k.str[0])
return;
- size_t pos = window_cursor_get(vis->win->view);
+ size_t pos = view_cursor_get(vis->win->view);
action_reset(&vis->action_prev);
vis->action_prev.op = &ops[OP_REPEAT_REPLACE];
buffer_put(&vis->buffer_repeat, k.str, strlen(k.str));
editor_delete_key(vis);
editor_insert_key(vis, k.str, strlen(k.str));
text_snapshot(vis->win->file->text);
- window_cursor_to(vis->win->view, pos);
+ view_cursor_to(vis->win->view, pos);
}
static void count(const Arg *arg) {
@@ -893,8 +893,8 @@ static void textobj(const Arg *arg) {
}
static void selection_end(const Arg *arg) {
- size_t pos = window_cursor_get(vis->win->view);
- Filerange sel = window_selection_get(vis->win->view);
+ size_t pos = view_cursor_get(vis->win->view);
+ Filerange sel = view_selection_get(vis->win->view);
if (pos == sel.start) {
pos = text_char_prev(vis->win->file->text, sel.end);
} else {
@@ -902,8 +902,8 @@ static void selection_end(const Arg *arg) {
sel.start = text_char_prev(vis->win->file->text, sel.end);
sel.end = pos;
}
- window_selection_set(vis->win->view, &sel);
- window_cursor_to(vis->win->view, pos);
+ view_selection_set(vis->win->view, &sel);
+ view_cursor_to(vis->win->view, pos);
}
static void reg(const Arg *arg) {
@@ -925,7 +925,7 @@ static void mark_line(const Arg *arg) {
static void undo(const Arg *arg) {
size_t pos = text_undo(vis->win->file->text);
if (pos != EPOS) {
- window_cursor_to(vis->win->view, pos);
+ view_cursor_to(vis->win->view, pos);
/* redraw all windows in case some display the same file */
editor_draw(vis);
}
@@ -934,7 +934,7 @@ static void undo(const Arg *arg) {
static void redo(const Arg *arg) {
size_t pos = text_redo(vis->win->file->text);
if (pos != EPOS) {
- window_cursor_to(vis->win->view, pos);
+ view_cursor_to(vis->win->view, pos);
/* redraw all windows in case some display the same file */
editor_draw(vis);
}
@@ -964,9 +964,9 @@ static void delete(const Arg *arg) {
static void insert_register(const Arg *arg) {
Register *reg = &vis->registers[arg->i];
- int pos = window_cursor_get(vis->win->view);
+ int pos = view_cursor_get(vis->win->view);
editor_insert(vis, pos, reg->data, reg->len);
- window_cursor_to(vis->win->view, pos + reg->len);
+ view_cursor_to(vis->win->view, pos + reg->len);
}
static void prompt_search(const Arg *arg) {
@@ -1006,7 +1006,7 @@ static void prompt_backspace(const Arg *arg) {
if (!cmd || !*cmd)
prompt_enter(NULL);
else
- window_backspace_key(vis->win->view);
+ view_backspace_key(vis->win->view);
free(cmd);
}
@@ -1019,7 +1019,7 @@ static void insert_verbatim(const Arg *arg) {
value = value * 10 + k.str[0] - '0';
}
char v = value;
- editor_insert(vis, window_cursor_get(vis->win->view), &v, 1);
+ editor_insert(vis, view_cursor_get(vis->win->view), &v, 1);
}
static void quit(const Arg *arg) {
@@ -1034,10 +1034,10 @@ static int argi2lines(const Arg *arg) {
switch (arg->i) {
case -PAGE:
case +PAGE:
- return window_height_get(vis->win->view);
+ return view_height_get(vis->win->view);
case -PAGE_HALF:
case +PAGE_HALF:
- return window_height_get(vis->win->view)/2;
+ return view_height_get(vis->win->view)/2;
default:
if (vis->action.count > 0)
return vis->action.count;
@@ -1047,16 +1047,16 @@ static int argi2lines(const Arg *arg) {
static void wscroll(const Arg *arg) {
if (arg->i >= 0)
- window_scroll_down(vis->win->view, argi2lines(arg));
+ view_scroll_down(vis->win->view, argi2lines(arg));
else
- window_scroll_up(vis->win->view, argi2lines(arg));
+ view_scroll_up(vis->win->view, argi2lines(arg));
}
static void wslide(const Arg *arg) {
if (arg->i >= 0)
- window_slide_down(vis->win->view, argi2lines(arg));
+ view_slide_down(vis->win->view, argi2lines(arg));
else
- window_slide_up(vis->win->view, argi2lines(arg));
+ view_slide_up(vis->win->view, argi2lines(arg));
}
static void call(const Arg *arg) {
@@ -1075,8 +1075,8 @@ static void insert_tab(const Arg *arg) {
insert(&(const Arg){ .s = expand_tab() });
}
-static void copy_indent_from_previous_line(Win *win, Text *text) {
- size_t pos = window_cursor_get(win);
+static void copy_indent_from_previous_line(View *view, Text *text) {
+ size_t pos = view_cursor_get(view);
size_t prev_line = text_line_prev(text, pos);
if (pos == prev_line)
return;
@@ -1130,8 +1130,8 @@ static void switchmode(const Arg *arg) {
static void action_do(Action *a) {
Text *txt = vis->win->file->text;
- Win *win = vis->win->view;
- size_t pos = window_cursor_get(win);
+ View *view = vis->win->view;
+ size_t pos = view_cursor_get(view);
int count = MAX(1, a->count);
OperatorContext c = {
.count = a->count,
@@ -1146,8 +1146,8 @@ static void action_do(Action *a) {
for (int i = 0; i < count; i++) {
if (a->movement->txt)
pos = a->movement->txt(txt, pos);
- else if (a->movement->win)
- pos = a->movement->win(win);
+ else if (a->movement->view)
+ pos = a->movement->view(view);
else if (a->movement->file)
pos = a->movement->file(vis->win->file, pos);
else
@@ -1167,9 +1167,9 @@ static void action_do(Action *a) {
if (!a->op) {
if (a->movement->type & CHARWISE)
- window_scroll_to(win, pos);
+ view_scroll_to(view, pos);
else
- window_cursor_to(win, pos);
+ view_cursor_to(view, pos);
if (a->movement->type & JUMP)
editor_window_jumplist_add(vis->win, pos);
else
@@ -1181,7 +1181,7 @@ static void action_do(Action *a) {
}
} else if (a->textobj) {
if (vis->mode->visual)
- c.range = window_selection_get(win);
+ c.range = view_selection_get(view);
else
c.range.start = c.range.end = pos;
for (int i = 0; i < count; i++) {
@@ -1205,18 +1205,18 @@ static void action_do(Action *a) {
}
if (vis->mode->visual) {
- window_selection_set(win, &c.range);
+ view_selection_set(view, &c.range);
pos = c.range.end;
- window_cursor_to(win, pos);
+ view_cursor_to(view, pos);
}
} else if (vis->mode->visual) {
- c.range = window_selection_get(win);
+ c.range = view_selection_get(view);
if (!text_range_valid(&c.range))
c.range.start = c.range.end = pos;
}
if (vis->mode == &vis_modes[VIS_MODE_VISUAL_LINE] && (a->movement || a->textobj)) {
- Filerange sel = window_selection_get(win);
+ Filerange sel = view_selection_get(view);
sel.end = text_char_prev(txt, sel.end);
size_t start = text_line_begin(txt, sel.start);
size_t end = text_line_end(txt, sel.end);
@@ -1227,7 +1227,7 @@ static void action_do(Action *a) {
sel.start = start;
sel.end = end;
}
- window_selection_set(win, &sel);
+ view_selection_set(view, &sel);
c.range = sel;
}
@@ -1397,7 +1397,7 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) {
break;
case OPTION_SYNTAX:
if (!argv[2]) {
- Syntax *syntax = window_syntax_get(vis->win->view);
+ Syntax *syntax = view_syntax_get(vis->win->view);
if (syntax)
editor_info_show(vis, "Syntax definition in use: `%s'", syntax->name);
else
@@ -1407,13 +1407,13 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) {
for (Syntax *syntax = syntaxes; syntax && syntax->name; syntax++) {
if (!strcasecmp(syntax->name, argv[2])) {
- window_syntax_set(vis->win->view, syntax);
+ view_syntax_set(vis->win->view, syntax);
return true;
}
}
if (parse_bool(argv[2], &arg.b) && !arg.b)
- window_syntax_set(vis->win->view, NULL);
+ view_syntax_set(vis->win->view, NULL);
else
editor_info_show(vis, "Unknown syntax definition: `%s'", argv[2]);
break;
@@ -1444,7 +1444,7 @@ static bool cmd_open(Filerange *range, enum CmdOpt opt, const char *argv[]) {
return true;
}
-static bool is_window_closeable(EditorWin *win) {
+static bool is_view_closeable(EditorWin *win) {
if (!text_modified(win->file->text))
return true;
return win->file->refcount > 1;
@@ -1456,7 +1456,7 @@ static void info_unsaved_changes(void) {
static bool cmd_edit(Filerange *range, enum CmdOpt opt, const char *argv[]) {
EditorWin *oldwin = vis->win;
- if (!(opt & CMD_OPT_FORCE) && !is_window_closeable(oldwin)) {
+ if (!(opt & CMD_OPT_FORCE) && !is_view_closeable(oldwin)) {
info_unsaved_changes();
return false;
}
@@ -1469,7 +1469,7 @@ static bool cmd_edit(Filerange *range, enum CmdOpt opt, const char *argv[]) {
}
static bool cmd_quit(Filerange *range, enum CmdOpt opt, const char *argv[]) {
- if (!(opt & CMD_OPT_FORCE) && !is_window_closeable(vis->win)) {
+ if (!(opt & CMD_OPT_FORCE) && !is_view_closeable(vis->win)) {
info_unsaved_changes();
return false;
}
@@ -1517,7 +1517,7 @@ static bool cmd_qall(Filerange *range, enum CmdOpt opt, const char *argv[]) {
}
static bool cmd_read(Filerange *range, enum CmdOpt opt, const char *argv[]) {
- size_t pos = window_cursor_get(vis->win->view);
+ size_t pos = view_cursor_get(vis->win->view);
for (const char **file = &argv[1]; *file; file++) {
int fd = open(*file, O_RDONLY);
char *text = NULL;
@@ -1625,12 +1625,12 @@ static bool cmd_saveas(Filerange *range, enum CmdOpt opt, const char *argv[]) {
static Filepos parse_pos(char **cmd) {
size_t pos = EPOS;
- Win *win = vis->win->view;
+ View *view = vis->win->view;
Text *txt = vis->win->file->text;
Mark *marks = vis->win->file->marks;
switch (**cmd) {
case '.':
- pos = text_line_begin(txt, window_cursor_get(win));
+ pos = text_line_begin(txt, view_cursor_get(view));
(*cmd)++;
break;
case '$':
@@ -1658,14 +1658,14 @@ static Filepos parse_pos(char **cmd) {
return EPOS;
if (!text_regex_compile(regex, *cmd, 0)) {
*cmd = pattern_end;
- pos = text_search_forward(txt, window_cursor_get(win), regex);
+ pos = text_search_forward(txt, view_cursor_get(view), regex);
}
text_regex_free(regex);
break;
case '+':
case '-':
{
- CursorPos curspos = window_cursor_getpos(win);
+ CursorPos curspos = view_cursor_getpos(view);
long long line = curspos.line + strtoll(*cmd, cmd, 10);
if (line < 0)
line = 0;
@@ -1730,7 +1730,7 @@ static bool exec_cmdline_command(const char *cmdline) {
if (!text_range_valid(&range)) {
/* if only one position was given, jump to it */
if (range.start != EPOS && !*name) {
- window_cursor_to(vis->win->view, range.start);
+ view_cursor_to(vis->win->view, range.start);
free(line);
return true;
}
@@ -1822,7 +1822,7 @@ static void settings_apply(const char **settings) {
static bool vis_window_new(const char *file) {
if (!editor_window_new(vis, file))
return false;
- Syntax *s = window_syntax_get(vis->win->view);
+ Syntax *s = view_syntax_get(vis->win->view);
if (s)
settings_apply(s->settings);
return true;
@@ -1831,7 +1831,7 @@ static bool vis_window_new(const char *file) {
static bool vis_window_new_fd(int fd) {
if (!editor_window_new_fd(vis, fd))
return false;
- Syntax *s = window_syntax_get(vis->win->view);
+ Syntax *s = view_syntax_get(vis->win->view);
if (s)
settings_apply(s->settings);
return true;
@@ -1840,7 +1840,7 @@ static bool vis_window_new_fd(int fd) {
static bool vis_window_split(EditorWin *win) {
if (!editor_window_split(win))
return false;
- Syntax *s = window_syntax_get(vis->win->view);
+ Syntax *s = view_syntax_get(vis->win->view);
if (s)
settings_apply(s->settings);
return true;
diff --git a/window.c b/window.c
index df2b069..000e42d 100644
--- a/window.c
+++ b/window.c
@@ -35,66 +35,66 @@ typedef struct { /* cursor position */
bool highlighted; /* true e.g. when cursor is on a bracket */
} Cursor;
-struct Win { /* window showing part of a file */
+struct View { /* viewable area, showing part of a file */
Text *text; /* underlying text management */
UiWin *ui;
ViewEvent *events;
- int width, height; /* window text area size */
+ int width, height; /* size of display area */
Filepos start, end; /* currently displayed area [start, end] in bytes from the start of the file */
size_t lines_size; /* number of allocated bytes for lines (grows only) */
- Line *lines; /* win->height number of lines representing window content */
- Line *topline; /* top of the window, first line currently shown */
+ Line *lines; /* view->height number of lines representing view content */
+ Line *topline; /* top of the view, first line currently shown */
Line *lastline; /* last currently used line, always <= bottomline */
- Line *bottomline; /* bottom of screen, might be unused if lastline < bottomline */
+ Line *bottomline; /* bottom of view, might be unused if lastline < bottomline */
Filerange sel; /* selected text range in bytes from start of file */
- Cursor cursor; /* current window cursor position */
- Line *line; /* used while drawing window content, line where next char will be drawn */
- int col; /* used while drawing window content, column where next char will be drawn */
- Syntax *syntax; /* syntax highlighting definitions for this window or NULL */
+ Cursor cursor; /* current cursor position within view */
+ Line *line; /* used while drawing view content, line where next char will be drawn */
+ int col; /* used while drawing view content, column where next char will be drawn */
+ Syntax *syntax; /* syntax highlighting definitions for this view or NULL */
int tabwidth; /* how many spaces should be used to display a tab character */
};
-static void window_clear(Win *win);
-static bool window_addch(Win *win, Cell *cell);
-static size_t window_cursor_update(Win *win);
+static void view_clear(View *view);
+static bool view_addch(View *view, Cell *cell);
+static size_t view_cursor_update(View *view);
/* set/move current cursor position to a given (line, column) pair */
-static size_t window_cursor_set(Win *win, Line *line, int col);
-/* move visible viewport n-lines up/down, redraws the window but does not change
+static size_t view_cursor_set(View *view, Line *line, int col);
+/* move visible viewport n-lines up/down, redraws the view but does not change
* cursor position which becomes invalid and should be corrected by either:
*
- * - window_cursor_to
- * - window_cursor_set
+ * - view_cursor_to
+ * - view_cursor_set
*
* the return value indicates wether the visible area changed.
*/
-static bool window_viewport_up(Win *win, int n);
-static bool window_viewport_down(Win *win, int n);
+static bool view_viewport_up(View *view, int n);
+static bool view_viewport_down(View *view, int n);
-void window_tabwidth_set(Win *win, int tabwidth) {
- win->tabwidth = tabwidth;
- window_draw(win);
+void view_tabwidth_set(View *view, int tabwidth) {
+ view->tabwidth = tabwidth;
+ view_draw(view);
}
-void window_selection_clear(Win *win) {
- win->sel = text_range_empty();
- window_draw(win);
- window_cursor_update(win);
+void view_selection_clear(View *view) {
+ view->sel = text_range_empty();
+ view_draw(view);
+ view_cursor_update(view);
}
-/* reset internal window data structures (cell matrix, line offsets etc.) */
-static void window_clear(Win *win) {
+/* reset internal view data structures (cell matrix, line offsets etc.) */
+static void view_clear(View *view) {
/* calculate line number of first line */
// TODO move elsewhere
- win->topline = win->lines;
- win->topline->lineno = text_lineno_by_pos(win->text, win->start);
- win->lastline = win->topline;
+ view->topline = view->lines;
+ view->topline->lineno = text_lineno_by_pos(view->text, view->start);
+ view->lastline = view->topline;
/* reset all other lines */
- size_t line_size = sizeof(Line) + win->width*sizeof(Cell);
- size_t end = win->height * line_size;
+ size_t line_size = sizeof(Line) + view->width*sizeof(Cell);
+ size_t end = view->height * line_size;
Line *prev = NULL;
for (size_t i = 0; i < end; i += line_size) {
- Line *line = (Line*)(((char*)win->lines) + i);
+ Line *line = (Line*)(((char*)view->lines) + i);
line->width = 0;
line->len = 0;
line->prev = prev;
@@ -102,14 +102,14 @@ static void window_clear(Win *win) {
prev->next = line;
prev = line;
}
- win->bottomline = prev ? prev : win->topline;
- win->bottomline->next = NULL;
- win->line = win->topline;
- win->col = 0;
+ view->bottomline = prev ? prev : view->topline;
+ view->bottomline->next = NULL;
+ view->line = view->topline;
+ view->col = 0;
}
-Filerange window_selection_get(Win *win) {
- Filerange sel = win->sel;
+Filerange view_selection_get(View *view) {
+ Filerange sel = view->sel;
if (sel.start > sel.end) {
size_t tmp = sel.start;
sel.start = sel.end;
@@ -117,79 +117,79 @@ Filerange window_selection_get(Win *win) {
}
if (!text_range_valid(&sel))
return text_range_empty();
- sel.end = text_char_next(win->text, sel.end);
+ sel.end = text_char_next(view->text, sel.end);
return sel;
}
-void window_selection_set(Win *win, Filerange *sel) {
- Cursor *cursor = &win->cursor;
- win->sel = *sel;
- window_draw(win);
- if (win->ui)
- win->ui->cursor_to(win->ui, cursor->col, cursor->row);
+void view_selection_set(View *view, Filerange *sel) {
+ Cursor *cursor = &view->cursor;
+ view->sel = *sel;
+ view_draw(view);
+ if (view->ui)
+ view->ui->cursor_to(view->ui, cursor->col, cursor->row);
}
-Filerange window_viewport_get(Win *win) {
- return (Filerange){ .start = win->start, .end = win->end };
+Filerange view_viewport_get(View *view) {
+ return (Filerange){ .start = view->start, .end = view->end };
}
-/* try to add another character to the window, return whether there was space left */
-static bool window_addch(Win *win, Cell *cell) {
- if (!win->line)
+/* try to add another character to the view, return whether there was space left */
+static bool view_addch(View *view, Cell *cell) {
+ if (!view->line)
return false;
int width;
static Cell empty;
- size_t lineno = win->line->lineno;
+ size_t lineno = view->line->lineno;
switch (cell->data[0]) {
case '\t':
- width = win->tabwidth - (win->col % win->tabwidth);
+ width = view->tabwidth - (view->col % view->tabwidth);
for (int w = 0; w < width; w++) {
- if (win->col + 1 > win->width) {
- win->line = win->line->next;
- win->col = 0;
- if (!win->line)
+ if (view->col + 1 > view->width) {
+ view->line = view->line->next;
+ view->col = 0;
+ if (!view->line)
return false;
- win->line->lineno = lineno;
+ view->line->lineno = lineno;
}
if (w == 0) {
/* first cell of a tab has a length of 1 */
- win->line->cells[win->col].len = cell->len;
- win->line->len += cell->len;
+ view->line->cells[view->col].len = cell->len;
+ view->line->len += cell->len;
} else {
/* all remaining ones have a lenght of zero */
- win->line->cells[win->col].len = 0;
+ view->line->cells[view->col].len = 0;
}
/* but all are marked as part of a tabstop */
- win->line->cells[win->col].width = 1;
- win->line->cells[win->col].data[0] = ' ';
- win->line->cells[win->col].data[1] = '\0';
- win->line->cells[win->col].istab = true;
- win->line->cells[win->col].attr = cell->attr;
- win->line->width++;
- win->col++;
+ view->line->cells[view->col].width = 1;
+ view->line->cells[view->col].data[0] = ' ';
+ view->line->cells[view->col].data[1] = '\0';
+ view->line->cells[view->col].istab = true;
+ view->line->cells[view->col].attr = cell->attr;
+ view->line->width++;
+ view->col++;
}
return true;
case '\n':
cell->width = 1;
- if (win->col + cell->width > win->width) {
- win->line = win->line->next;
- win->col = 0;
- if (!win->line)
+ if (view->col + cell->width > view->width) {
+ view->line = view->line->next;
+ view->col = 0;
+ if (!view->line)
return false;
- win->line->lineno = lineno;
+ view->line->lineno = lineno;
}
- win->line->cells[win->col] = *cell;
- win->line->len += cell->len;
- win->line->width += cell->width;
- for (int i = win->col + 1; i < win->width; i++)
- win->line->cells[i] = empty;
-
- win->line = win->line->next;
- if (win->line)
- win->line->lineno = lineno + 1;
- win->col = 0;
+ view->line->cells[view->col] = *cell;
+ view->line->len += cell->len;
+ view->line->width += cell->width;
+ for (int i = view->col + 1; i < view->width; i++)
+ view->line->cells[i] = empty;
+
+ view->line = view->line->next;
+ if (view->line)
+ view->line->lineno = lineno + 1;
+ view->col = 0;
return true;
default:
if ((unsigned char)cell->data[0] < 128 && !isprint((unsigned char)cell->data[0])) {
@@ -203,30 +203,30 @@ static bool window_addch(Win *win, Cell *cell) {
};
}
- if (win->col + cell->width > win->width) {
- for (int i = win->col; i < win->width; i++)
- win->line->cells[i] = empty;
- win->line = win->line->next;
- win->col = 0;
+ if (view->col + cell->width > view->width) {
+ for (int i = view->col; i < view->width; i++)
+ view->line->cells[i] = empty;
+ view->line = view->line->next;
+ view->col = 0;
}
- if (win->line) {
- win->line->width += cell->width;
- win->line->len += cell->len;
- win->line->lineno = lineno;
- win->line->cells[win->col] = *cell;
- win->col++;
+ if (view->line) {
+ view->line->width += cell->width;
+ view->line->len += cell->len;
+ view->line->lineno = lineno;
+ view->line->cells[view->col] = *cell;
+ view->col++;
/* set cells of a character which uses multiple columns */
for (int i = 1; i < cell->width; i++)
- win->line->cells[win->col++] = empty;
+ view->line->cells[view->col++] = empty;
return true;
}
return false;
}
}
-CursorPos window_cursor_getpos(Win *win) {
- Cursor *cursor = &win->cursor;
+CursorPos view_cursor_getpos(View *view) {
+ Cursor *cursor = &view->cursor;
Line *line = cursor->line;
CursorPos pos = { .line = line->lineno, .col = cursor->col };
while (line->prev && line->prev->lineno == pos.line) {
@@ -238,12 +238,12 @@ CursorPos window_cursor_getpos(Win *win) {
}
/* snyc current cursor position with internal Line/Cell structures */
-static void window_cursor_sync(Win *win) {
+static void view_cursor_sync(View *view) {
int row = 0, col = 0;
- size_t cur = win->start, pos = win->cursor.pos;
- Line *line = win->topline;
+ size_t cur = view->start, pos = view->cursor.pos;
+ Line *line = view->topline;
- while (line && line != win->lastline && cur < pos) {
+ while (line && line != view->lastline && cur < pos) {
if (cur + line->len > pos)
break;
cur += line->len;
@@ -252,104 +252,104 @@ static void window_cursor_sync(Win *win) {
}
if (line) {
- int max_col = MIN(win->width, line->width);
+ int max_col = MIN(view->width, line->width);
while (cur < pos && col < max_col) {
cur += line->cells[col].len;
/* skip over columns occupied by the same character */
while (++col < max_col && line->cells[col].len == 0);
}
} else {
- line = win->bottomline;
- row = win->height - 1;
+ line = view->bottomline;
+ row = view->height - 1;
}
- win->cursor.line = line;
- win->cursor.row = row;
- win->cursor.col = col;
+ view->cursor.line = line;
+ view->cursor.row = row;
+ view->cursor.col = col;
}
-/* place the cursor according to the screen coordinates in win->{row,col} and
- * fire user callback. if a selection is active, redraw the window to reflect
+/* place the cursor according to the screen coordinates in view->{row,col} and
+ * fire user callback. if a selection is active, redraw the view to reflect
* its changes. */
-static size_t window_cursor_update(Win *win) {
- Cursor *cursor = &win->cursor;
- if (win->sel.start != EPOS) {
- win->sel.end = cursor->pos;
- window_draw(win);
- } else if (win->ui && win->syntax) {
+static size_t view_cursor_update(View *view) {
+ Cursor *cursor = &view->cursor;
+ if (view->sel.start != EPOS) {
+ view->sel.end = cursor->pos;
+ view_draw(view);
+ } else if (view->ui && view->syntax) {
size_t pos = cursor->pos;
- size_t pos_match = text_bracket_match_except(win->text, pos, "<>");
- if (pos != pos_match && win->start <= pos_match && pos_match < win->end) {
+ size_t pos_match = text_bracket_match_except(view->text, pos, "<>");
+ if (pos != pos_match && view->start <= pos_match && pos_match < view->end) {
if (cursor->highlighted)
- window_draw(win); /* clear active highlighting */
+ view_draw(view); /* clear active highlighting */
cursor->pos = pos_match;
- window_cursor_sync(win);
+ view_cursor_sync(view);
cursor->line->cells[cursor->col].attr |= A_REVERSE;
cursor->pos = pos;
- window_cursor_sync(win);
- win->ui->draw_text(win->ui, win->topline);
+ view_cursor_sync(view);
+ view->ui->draw_text(view->ui, view->topline);
cursor->highlighted = true;
} else if (cursor->highlighted) {
cursor->highlighted = false;
- window_draw(win);
+ view_draw(view);
}
}
if (cursor->pos != cursor->lastpos)
cursor->lastcol = 0;
cursor->lastpos = cursor->pos;
- if (win->ui)
- win->ui->cursor_to(win->ui, cursor->col, cursor->row);
+ if (view->ui)
+ view->ui->cursor_to(view->ui, cursor->col, cursor->row);
return cursor->pos;
}
/* move the cursor to the character at pos bytes from the begining of the file.
- * if pos is not in the current viewport, redraw the window to make it visible */
-void window_cursor_to(Win *win, size_t pos) {
- size_t max = text_size(win->text);
+ * if pos is not in the current viewport, redraw the view to make it visible */
+void view_cursor_to(View *view, size_t pos) {
+ size_t max = text_size(view->text);
if (pos > max)
pos = max > 0 ? max - 1 : 0;
- if (pos == max && win->end != max) {
- /* do not display an empty screen when showing the end of the file */
- win->start = max - 1;
- window_viewport_up(win, win->height / 2);
+ if (pos == max && view->end != max) {
+ /* do not display an empty screen when shoviewg the end of the file */
+ view->start = max - 1;
+ view_viewport_up(view, view->height / 2);
} else {
/* set the start of the viewable region to the start of the line on which
* the cursor should be placed. if this line requires more space than
- * available in the window then simply start displaying text at the new
+ * available in the view then simply start displaying text at the new
* cursor position */
- for (int i = 0; i < 2 && (pos < win->start || pos > win->end); i++) {
- win->start = i == 0 ? text_line_begin(win->text, pos) : pos;
- window_draw(win);
+ for (int i = 0; i < 2 && (pos < view->start || pos > view->end); i++) {
+ view->start = i == 0 ? text_line_begin(view->text, pos) : pos;
+ view_draw(view);
}
}
- win->cursor.pos = pos;
- window_cursor_sync(win);
- window_cursor_update(win);
+ view->cursor.pos = pos;
+ view_cursor_sync(view);
+ view_cursor_update(view);
}
-/* redraw the complete with data starting from win->start bytes into the file.
- * stop once the screen is full, update win->end, win->lastline */
-void window_draw(Win *win) {
- window_clear(win);
+/* redraw the complete with data starting from view->start bytes into the file.
+ * stop once the screen is full, update view->end, view->lastline */
+void view_draw(View *view) {
+ view_clear(view);
/* current absolute file position */
- size_t pos = win->start;
+ size_t pos = view->start;
/* number of bytes to read in one go */
- size_t text_len = win->width * win->height;
+ size_t text_len = view->width * view->height;
/* current buffer to work with */
char text[text_len+1];
/* remaining bytes to process in buffer*/
- size_t rem = text_bytes_get(win->text, pos, text_len, text);
+ size_t rem = text_bytes_get(view->text, pos, text_len, text);
/* NUL terminate because regex(3) function expect it */
text[rem] = '\0';
/* current position into buffer from which to interpret a character */
char *cur = text;
/* current selection */
- Filerange sel = window_selection_get(win);
+ Filerange sel = view_selection_get(view);
/* syntax definition to use */
- Syntax *syntax = win->syntax;
+ Syntax *syntax = view->syntax;
/* matched tokens for each syntax rule */
regmatch_t match[syntax ? LENGTH(syntax->rules) : 1][1], *matched = NULL;
memset(match, 0, sizeof match);
@@ -403,7 +403,7 @@ void window_draw(Win *win) {
/* within matched expression */
matched = &match[i][0];
attrs = rule->color->attr;
- break; /* first match wins */
+ break; /* first match views */
}
}
}
@@ -421,7 +421,7 @@ void window_draw(Win *win) {
* wide character. advance file position and read
* another junk into buffer.
*/
- rem = text_bytes_get(win->text, pos, text_len, text);
+ rem = text_bytes_get(view->text, pos, text_len, text);
text[rem] = '\0';
cur = text;
continue;
@@ -440,14 +440,14 @@ void window_draw(Win *win) {
}
if (cur[0] == '\r' && rem > 1 && cur[1] == '\n') {
- /* convert windows style newline \r\n into a single char with len = 2 */
+ /* convert views style newline \r\n into a single char with len = 2 */
cell = (Cell){ .data = "\n", .len = 2, .width = 1, .istab = false };
}
cell.attr = attrs;
if (sel.start <= pos && pos < sel.end)
cell.attr |= A_REVERSE;
- if (!window_addch(win, &cell))
+ if (!view_addch(view, &cell))
break;
rem -= cell.len;
@@ -455,78 +455,78 @@ void window_draw(Win *win) {
pos += cell.len;
}
- /* set end of viewing region */
- win->end = pos;
- win->lastline = win->line ? win->line : win->bottomline;
- win->lastline->next = NULL;
- window_cursor_sync(win);
- if (win->ui)
- win->ui->draw_text(win->ui, win->topline);
- if (sel.start != EPOS && win->events && win->events->selection)
- win->events->selection(win->events->data, &sel);
+ /* set end of vieviewg region */
+ view->end = pos;
+ view->lastline = view->line ? view->line : view->bottomline;
+ view->lastline->next = NULL;
+ view_cursor_sync(view);
+ if (view->ui)
+ view->ui->draw_text(view->ui, view->topline);
+ if (sel.start != EPOS && view->events && view->events->selection)
+ view->events->selection(view->events->data, &sel);
}
-bool window_resize(Win *win, int width, int height) {
+bool view_resize(View *view, int width, int height) {
size_t lines_size = height*(sizeof(Line) + width*sizeof(Cell));
- if (lines_size > win->lines_size) {
- Line *lines = realloc(win->lines, lines_size);
+ if (lines_size > view->lines_size) {
+ Line *lines = realloc(view->lines, lines_size);
if (!lines)
return false;
- win->lines = lines;
- win->lines_size = lines_size;
+ view->lines = lines;
+ view->lines_size = lines_size;
}
- win->width = width;
- win->height = height;
- if (win->lines)
- memset(win->lines, 0, win->lines_size);
- window_draw(win);
+ view->width = width;
+ view->height = height;
+ if (view->lines)
+ memset(view->lines, 0, view->lines_size);
+ view_draw(view);
return true;
}
-int window_height_get(Win *win) {
- return win->height;
+int view_height_get(View *view) {
+ return view->height;
}
-void window_free(Win *win) {
- if (!win)
+void view_free(View *view) {
+ if (!view)
return;
- free(win->lines);
- free(win);
+ free(view->lines);
+ free(view);
}
-void window_reload(Win *win, Text *text) {
- win->text = text;
- window_selection_clear(win);
- window_cursor_to(win, 0);
- if (win->ui)
- win->ui->reload(win->ui, text);
+void view_reload(View *view, Text *text) {
+ view->text = text;
+ view_selection_clear(view);
+ view_cursor_to(view, 0);
+ if (view->ui)
+ view->ui->reload(view->ui, text);
}
-Win *window_new(Text *text, ViewEvent *events) {
+View *view_new(Text *text, ViewEvent *events) {
if (!text)
return NULL;
- Win *win = calloc(1, sizeof(Win));
- if (!win)
+ View *view = calloc(1, sizeof(View));
+ if (!view)
return NULL;
- win->text = text;
- win->events = events;
- win->tabwidth = 8;
+ view->text = text;
+ view->events = events;
+ view->tabwidth = 8;
- if (!window_resize(win, 1, 1)) {
- window_free(win);
+ if (!view_resize(view, 1, 1)) {
+ view_free(view);
return NULL;
}
- window_selection_clear(win);
- window_cursor_to(win, 0);
+ view_selection_clear(view);
+ view_cursor_to(view, 0);
- return win;
+ return view;
}
-void window_ui(Win *win, UiWin* ui) {
- win->ui = ui;
+void view_ui(View *view, UiWin* ui) {
+ view->ui = ui;
}
-size_t window_char_prev(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_char_prev(View *view) {
+ Cursor *cursor = &view->cursor;
Line *line = cursor->line;
do {
@@ -534,7 +534,7 @@ size_t window_char_prev(Win *win) {
if (!line->prev)
return cursor->pos;
cursor->line = line = line->prev;
- cursor->col = MIN(line->width, win->width - 1);
+ cursor->col = MIN(line->width, view->width - 1);
cursor->row--;
} else {
cursor->col--;
@@ -542,16 +542,16 @@ size_t window_char_prev(Win *win) {
} while (line->cells[cursor->col].len == 0);
cursor->pos -= line->cells[cursor->col].len;
- return window_cursor_update(win);
+ return view_cursor_update(view);
}
-size_t window_char_next(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_char_next(View *view) {
+ Cursor *cursor = &view->cursor;
Line *line = cursor->line;
do {
cursor->pos += line->cells[cursor->col].len;
- if ((line->width == win->width && cursor->col == win->width - 1) ||
+ if ((line->width == view->width && cursor->col == view->width - 1) ||
cursor->col == line->width) {
if (!line->next)
return cursor->pos;
@@ -563,15 +563,15 @@ size_t window_char_next(Win *win) {
}
} while (line->cells[cursor->col].len == 0);
- return window_cursor_update(win);
+ return view_cursor_update(view);
}
-static size_t window_cursor_set(Win *win, Line *line, int col) {
+static size_t view_cursor_set(View *view, Line *line, int col) {
int row = 0;
- size_t pos = win->start;
- Cursor *cursor = &win->cursor;
+ size_t pos = view->start;
+ Cursor *cursor = &view->cursor;
/* get row number and file offset at start of the given line */
- for (Line *cur = win->topline; cur && cur != line; cur = cur->next) {
+ for (Line *cur = view->topline; cur && cur != line; cur = cur->next) {
pos += cur->len;
row++;
}
@@ -591,35 +591,35 @@ static size_t window_cursor_set(Win *win, Line *line, int col) {
cursor->pos = pos;
cursor->line = line;
- window_cursor_update(win);
+ view_cursor_update(view);
return pos;
}
-static bool window_viewport_down(Win *win, int n) {
+static bool view_viewport_down(View *view, int n) {
Line *line;
- if (win->end == text_size(win->text))
+ if (view->end == text_size(view->text))
return false;
- if (n >= win->height) {
- win->start = win->end;
+ if (n >= view->height) {
+ view->start = view->end;
} else {
- for (line = win->topline; line && n > 0; line = line->next, n--)
- win->start += line->len;
+ for (line = view->topline; line && n > 0; line = line->next, n--)
+ view->start += line->len;
}
- window_draw(win);
+ view_draw(view);
return true;
}
-static bool window_viewport_up(Win *win, int n) {
+static bool view_viewport_up(View *view, int n) {
/* scrolling up is somewhat tricky because we do not yet know where
* the lines start, therefore scan backwards but stop at a reasonable
* maximum in case we are dealing with a file without any newlines
*/
- if (win->start == 0)
+ if (view->start == 0)
return false;
- size_t max = win->width * win->height;
+ size_t max = view->width * view->height;
char c;
- Iterator it = text_iterator_get(win->text, win->start - 1);
+ Iterator it = text_iterator_get(view->text, view->start - 1);
if (!text_iterator_byte_get(&it, &c))
return false;
@@ -637,262 +637,262 @@ static bool window_viewport_up(Win *win, int n) {
} while (text_iterator_byte_prev(&it, &c));
if (c == '\r')
off++;
- win->start -= off;
- window_draw(win);
+ view->start -= off;
+ view_draw(view);
return true;
}
-void window_redraw_top(Win *win) {
- Line *line = win->cursor.line;
- for (Line *cur = win->topline; cur && cur != line; cur = cur->next)
- win->start += cur->len;
- window_draw(win);
- window_cursor_to(win, win->cursor.pos);
+void view_redraw_top(View *view) {
+ Line *line = view->cursor.line;
+ for (Line *cur = view->topline; cur && cur != line; cur = cur->next)
+ view->start += cur->len;
+ view_draw(view);
+ view_cursor_to(view, view->cursor.pos);
}
-void window_redraw_center(Win *win) {
- int center = win->height / 2;
- size_t pos = win->cursor.pos;
+void view_redraw_center(View *view) {
+ int center = view->height / 2;
+ size_t pos = view->cursor.pos;
for (int i = 0; i < 2; i++) {
int linenr = 0;
- Line *line = win->cursor.line;
- for (Line *cur = win->topline; cur && cur != line; cur = cur->next)
+ Line *line = view->cursor.line;
+ for (Line *cur = view->topline; cur && cur != line; cur = cur->next)
linenr++;
if (linenr < center) {
- window_slide_down(win, center - linenr);
+ view_slide_down(view, center - linenr);
continue;
}
- for (Line *cur = win->topline; cur && cur != line && linenr > center; cur = cur->next) {
- win->start += cur->len;
+ for (Line *cur = view->topline; cur && cur != line && linenr > center; cur = cur->next) {
+ view->start += cur->len;
linenr--;
}
break;
}
- window_draw(win);
- window_cursor_to(win, pos);
+ view_draw(view);
+ view_cursor_to(view, pos);
}
-void window_redraw_bottom(Win *win) {
- Line *line = win->cursor.line;
- if (line == win->lastline)
+void view_redraw_bottom(View *view) {
+ Line *line = view->cursor.line;
+ if (line == view->lastline)
return;
int linenr = 0;
- size_t pos = win->cursor.pos;
- for (Line *cur = win->topline; cur && cur != line; cur = cur->next)
+ size_t pos = view->cursor.pos;
+ for (Line *cur = view->topline; cur && cur != line; cur = cur->next)
linenr++;
- window_slide_down(win, win->height - linenr - 1);
- window_cursor_to(win, pos);
+ view_slide_down(view, view->height - linenr - 1);
+ view_cursor_to(view, pos);
}
-size_t window_slide_up(Win *win, int lines) {
- Cursor *cursor = &win->cursor;
- if (window_viewport_down(win, lines)) {
- if (cursor->line == win->topline)
- window_cursor_set(win, win->topline, cursor->col);
+size_t view_slide_up(View *view, int lines) {
+ Cursor *cursor = &view->cursor;
+ if (view_viewport_down(view, lines)) {
+ if (cursor->line == view->topline)
+ view_cursor_set(view, view->topline, cursor->col);
else
- window_cursor_to(win, cursor->pos);
+ view_cursor_to(view, cursor->pos);
} else {
- window_screenline_down(win);
+ view_screenline_down(view);
}
return cursor->pos;
}
-size_t window_slide_down(Win *win, int lines) {
- Cursor *cursor = &win->cursor;
- if (window_viewport_up(win, lines)) {
- if (cursor->line == win->lastline)
- window_cursor_set(win, win->lastline, cursor->col);
+size_t view_slide_down(View *view, int lines) {
+ Cursor *cursor = &view->cursor;
+ if (view_viewport_up(view, lines)) {
+ if (cursor->line == view->lastline)
+ view_cursor_set(view, view->lastline, cursor->col);
else
- window_cursor_to(win, cursor->pos);
+ view_cursor_to(view, cursor->pos);
} else {
- window_screenline_up(win);
+ view_screenline_up(view);
}
return cursor->pos;
}
-size_t window_scroll_up(Win *win, int lines) {
- Cursor *cursor = &win->cursor;
- if (window_viewport_up(win, lines)) {
- Line *line = cursor->line < win->lastline ? cursor->line : win->lastline;
- window_cursor_set(win, line, win->cursor.col);
+size_t view_scroll_up(View *view, int lines) {
+ Cursor *cursor = &view->cursor;
+ if (view_viewport_up(view, lines)) {
+ Line *line = cursor->line < view->lastline ? cursor->line : view->lastline;
+ view_cursor_set(view, line, view->cursor.col);
} else {
- window_cursor_to(win, 0);
+ view_cursor_to(view, 0);
}
return cursor->pos;
}
-size_t window_scroll_down(Win *win, int lines) {
- Cursor *cursor = &win->cursor;
- if (window_viewport_down(win, lines)) {
- Line *line = cursor->line > win->topline ? cursor->line : win->topline;
- window_cursor_set(win, line, cursor->col);
+size_t view_scroll_down(View *view, int lines) {
+ Cursor *cursor = &view->cursor;
+ if (view_viewport_down(view, lines)) {
+ Line *line = cursor->line > view->topline ? cursor->line : view->topline;
+ view_cursor_set(view, line, cursor->col);
} else {
- window_cursor_to(win, text_size(win->text));
+ view_cursor_to(view, text_size(view->text));
}
return cursor->pos;
}
-size_t window_line_up(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_line_up(View *view) {
+ Cursor *cursor = &view->cursor;
if (cursor->line->prev && cursor->line->prev->prev &&
cursor->line->lineno != cursor->line->prev->lineno &&
cursor->line->prev->lineno != cursor->line->prev->prev->lineno)
- return window_screenline_up(win);
- size_t bol = text_line_begin(win->text, cursor->pos);
- size_t prev = text_line_prev(win->text, bol);
- size_t pos = text_line_offset(win->text, prev, cursor->pos - bol);
- window_cursor_to(win, pos);
+ return view_screenline_up(view);
+ size_t bol = text_line_begin(view->text, cursor->pos);
+ size_t prev = text_line_prev(view->text, bol);
+ size_t pos = text_line_offset(view->text, prev, cursor->pos - bol);
+ view_cursor_to(view, pos);
return cursor->pos;
}
-size_t window_line_down(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_line_down(View *view) {
+ Cursor *cursor = &view->cursor;
if (!cursor->line->next || cursor->line->next->lineno != cursor->line->lineno)
- return window_screenline_down(win);
- size_t bol = text_line_begin(win->text, cursor->pos);
- size_t next = text_line_next(win->text, bol);
- size_t pos = text_line_offset(win->text, next, cursor->pos - bol);
- window_cursor_to(win, pos);
+ return view_screenline_down(view);
+ size_t bol = text_line_begin(view->text, cursor->pos);
+ size_t next = text_line_next(view->text, bol);
+ size_t pos = text_line_offset(view->text, next, cursor->pos - bol);
+ view_cursor_to(view, pos);
return cursor->pos;
}
-size_t window_screenline_up(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_screenline_up(View *view) {
+ Cursor *cursor = &view->cursor;
int lastcol = cursor->lastcol;
if (!lastcol)
lastcol = cursor->col;
if (!cursor->line->prev)
- window_scroll_up(win, 1);
+ view_scroll_up(view, 1);
if (cursor->line->prev)
- window_cursor_set(win, cursor->line->prev, lastcol);
+ view_cursor_set(view, cursor->line->prev, lastcol);
cursor->lastcol = lastcol;
return cursor->pos;
}
-size_t window_screenline_down(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_screenline_down(View *view) {
+ Cursor *cursor = &view->cursor;
int lastcol = cursor->lastcol;
if (!lastcol)
lastcol = cursor->col;
- if (!cursor->line->next && cursor->line == win->bottomline)
- window_scroll_down(win, 1);
+ if (!cursor->line->next && cursor->line == view->bottomline)
+ view_scroll_down(view, 1);
if (cursor->line->next)
- window_cursor_set(win, cursor->line->next, lastcol);
+ view_cursor_set(view, cursor->line->next, lastcol);
cursor->lastcol = lastcol;
return cursor->pos;
}
-size_t window_screenline_begin(Win *win) {
- return window_cursor_set(win, win->cursor.line, 0);
+size_t view_screenline_begin(View *view) {
+ return view_cursor_set(view, view->cursor.line, 0);
}
-size_t window_screenline_middle(Win *win) {
- Cursor *cursor = &win->cursor;
- return window_cursor_set(win, cursor->line, cursor->line->width / 2);
+size_t view_screenline_middle(View *view) {
+ Cursor *cursor = &view->cursor;
+ return view_cursor_set(view, cursor->line, cursor->line->width / 2);
}
-size_t window_screenline_end(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_screenline_end(View *view) {
+ Cursor *cursor = &view->cursor;
int col = cursor->line->width - 1;
- return window_cursor_set(win, cursor->line, col >= 0 ? col : 0);
+ return view_cursor_set(view, cursor->line, col >= 0 ? col : 0);
}
-size_t window_delete_key(Win *win) {
- Cursor *cursor = &win->cursor;
+size_t view_delete_key(View *view) {
+ Cursor *cursor = &view->cursor;
Line *line = cursor->line;
size_t len = line->cells[cursor->col].len;
- text_delete(win->text, cursor->pos, len);
- window_draw(win);
- window_cursor_to(win, cursor->pos);
+ text_delete(view->text, cursor->pos, len);
+ view_draw(view);
+ view_cursor_to(view, cursor->pos);
return cursor->pos;
}
-size_t window_backspace_key(Win *win) {
- Cursor *cursor = &win->cursor;
- if (win->start == cursor->pos) {
- if (win->start == 0)
+size_t view_backspace_key(View *view) {
+ Cursor *cursor = &view->cursor;
+ if (view->start == cursor->pos) {
+ if (view->start == 0)
return cursor->pos;
- /* if we are on the top left most position in the window
+ /* if we are on the top left most position in the view
* first scroll up so that the to be deleted character is
* visible then proceed as normal */
size_t pos = cursor->pos;
- window_viewport_up(win, 1);
- window_cursor_to(win, pos);
+ view_viewport_up(view, 1);
+ view_cursor_to(view, pos);
}
- window_char_prev(win);
+ view_char_prev(view);
size_t pos = cursor->pos;
size_t len = cursor->line->cells[cursor->col].len;
- text_delete(win->text, pos, len);
- window_draw(win);
- window_cursor_to(win, pos);
+ text_delete(view->text, pos, len);
+ view_draw(view);
+ view_cursor_to(view, pos);
return pos;
}
-size_t window_insert_key(Win *win, const char *c, size_t len) {
- size_t pos = win->cursor.pos;
- text_insert(win->text, pos, c, len);
- if (win->cursor.line == win->bottomline && memchr(c, '\n', len))
- window_viewport_down(win, 1);
+size_t view_insert_key(View *view, const char *c, size_t len) {
+ size_t pos = view->cursor.pos;
+ text_insert(view->text, pos, c, len);
+ if (view->cursor.line == view->bottomline && memchr(c, '\n', len))
+ view_viewport_down(view, 1);
else
- window_draw(win);
+ view_draw(view);
pos += len;
- window_cursor_to(win, pos);
+ view_cursor_to(view, pos);
return pos;
}
-size_t window_replace_key(Win *win, const char *c, size_t len) {
- Cursor *cursor = &win->cursor;
+size_t view_replace_key(View *view, const char *c, size_t len) {
+ Cursor *cursor = &view->cursor;
Line *line = cursor->line;
size_t pos = cursor->pos;
/* do not overwrite new line which would merge the two lines */
if (line->cells[cursor->col].data[0] != '\n') {
size_t oldlen = line->cells[cursor->col].len;
- text_delete(win->text, pos, oldlen);
+ text_delete(view->text, pos, oldlen);
}
- text_insert(win->text, pos, c, len);
- if (cursor->line == win->bottomline && memchr(c, '\n', len))
- window_viewport_down(win, 1);
+ text_insert(view->text, pos, c, len);
+ if (cursor->line == view->bottomline && memchr(c, '\n', len))
+ view_viewport_down(view, 1);
else
- window_draw(win);
+ view_draw(view);
pos += len;
- window_cursor_to(win, pos);
+ view_cursor_to(view, pos);
return pos;
}
-size_t window_cursor_get(Win *win) {
- return win->cursor.pos;
+size_t view_cursor_get(View *view) {
+ return view->cursor.pos;
}
-const Line *window_lines_get(Win *win) {
- return win->topline;
+const Line *view_lines_get(View *view) {
+ return view->topline;
}
-void window_scroll_to(Win *win, size_t pos) {
- while (pos < win->start && window_viewport_up(win, 1));
- while (pos > win->end && window_viewport_down(win, 1));
- window_cursor_to(win, pos);
+void view_scroll_to(View *view, size_t pos) {
+ while (pos < view->start && view_viewport_up(view, 1));
+ while (pos > view->end && view_viewport_down(view, 1));
+ view_cursor_to(view, pos);
}
-void window_selection_start(Win *win) {
- if (win->sel.start != EPOS && win->sel.end != EPOS)
+void view_selection_start(View *view) {
+ if (view->sel.start != EPOS && view->sel.end != EPOS)
return;
- size_t pos = window_cursor_get(win);
- win->sel.start = win->sel.end = pos;
- window_draw(win);
- window_cursor_to(win, pos);
+ size_t pos = view_cursor_get(view);
+ view->sel.start = view->sel.end = pos;
+ view_draw(view);
+ view_cursor_to(view, pos);
}
-void window_syntax_set(Win *win, Syntax *syntax) {
- win->syntax = syntax;
+void view_syntax_set(View *view, Syntax *syntax) {
+ view->syntax = syntax;
}
-Syntax *window_syntax_get(Win *win) {
- return win->syntax;
+Syntax *view_syntax_get(View *view) {
+ return view->syntax;
}
-size_t window_screenline_goto(Win *win, int n) {
- size_t pos = win->start;
- for (Line *line = win->topline; --n > 0 && line != win->lastline; line = line->next)
+size_t view_screenline_goto(View *view, int n) {
+ size_t pos = view->start;
+ for (Line *line = view->topline; --n > 0 && line != view->lastline; line = line->next)
pos += line->len;
return pos;
}
diff --git a/window.h b/window.h
index e1e2080..6b0d330 100644
--- a/window.h
+++ b/window.h
@@ -7,7 +7,7 @@
#include "ui.h"
#include "syntax.h"
-typedef struct Win Win;
+typedef struct View View;
typedef struct {
void *data;
@@ -40,76 +40,76 @@ typedef struct {
size_t col;
} CursorPos;
-Win *window_new(Text*, ViewEvent*);
-void window_ui(Win*, UiWin*);
+View *view_new(Text*, ViewEvent*);
+void view_ui(View*, UiWin*);
/* change associated text displayed in this window */
-void window_reload(Win*, Text*);
-void window_free(Win*);
+void view_reload(View*, Text*);
+void view_free(View*);
/* keyboard input at cursor position */
-size_t window_insert_key(Win*, const char *c, size_t len);
-size_t window_replace_key(Win*, const char *c, size_t len);
-size_t window_backspace_key(Win*);
-size_t window_delete_key(Win*);
+size_t view_insert_key(View*, const char *c, size_t len);
+size_t view_replace_key(View*, const char *c, size_t len);
+size_t view_backspace_key(View*);
+size_t view_delete_key(View*);
-bool window_resize(Win*, int width, int height);
-int window_height_get(Win*);
-void window_draw(Win*);
+bool view_resize(View*, int width, int height);
+int view_height_get(View*);
+void view_draw(View*);
/* changes how many spaces are used for one tab (must be >0), redraws the window */
-void window_tabwidth_set(Win*, int tabwidth);
+void view_tabwidth_set(View*, int tabwidth);
/* cursor movements which also update selection if one is active.
* they return new cursor postion */
-size_t window_char_next(Win*);
-size_t window_char_prev(Win*);
-size_t window_line_down(Win*);
-size_t window_line_up(Win*);
-size_t window_screenline_down(Win*);
-size_t window_screenline_up(Win*);
-size_t window_screenline_begin(Win*);
-size_t window_screenline_middle(Win*);
-size_t window_screenline_end(Win*);
+size_t view_char_next(View*);
+size_t view_char_prev(View*);
+size_t view_line_down(View*);
+size_t view_line_up(View*);
+size_t view_screenline_down(View*);
+size_t view_screenline_up(View*);
+size_t view_screenline_begin(View*);
+size_t view_screenline_middle(View*);
+size_t view_screenline_end(View*);
/* move window content up/down, but keep cursor position unchanged unless it is
* on a now invisible line in which case we try to preserve the column position */
-size_t window_slide_up(Win*, int lines);
-size_t window_slide_down(Win*, int lines);
+size_t view_slide_up(View*, int lines);
+size_t view_slide_down(View*, int lines);
/* scroll window contents up/down by lines, place the cursor on the newly
* visible line, try to preserve the column position */
-size_t window_scroll_up(Win*, int lines);
-size_t window_scroll_down(Win*, int lines);
+size_t view_scroll_up(View*, int lines);
+size_t view_scroll_down(View*, int lines);
/* place the cursor at the start ot the n-th window line, counting from 1 */
-size_t window_screenline_goto(Win*, int n);
+size_t view_screenline_goto(View*, int n);
/* get cursor position in bytes from start of the file */
-size_t window_cursor_get(Win*);
+size_t view_cursor_get(View*);
-const Line *window_lines_get(Win*);
+const Line *view_lines_get(View*);
/* get cursor position in terms of screen coordinates */
-CursorPos window_cursor_getpos(Win*);
+CursorPos view_cursor_getpos(View*);
/* moves window viewport in direction until pos is visible. should only be
* used for short distances between current cursor position and destination */
-void window_scroll_to(Win*, size_t pos);
+void view_scroll_to(View*, size_t pos);
/* move cursor to a given position. changes the viewport to make sure that
* position is visible. if the position is in the middle of a line, try to
* adjust the viewport in such a way that the whole line is displayed */
-void window_cursor_to(Win*, size_t pos);
+void view_cursor_to(View*, size_t pos);
/* redraw current cursor line at top/center/bottom of window */
-void window_redraw_top(Win*);
-void window_redraw_center(Win*);
-void window_redraw_bottom(Win*);
+void view_redraw_top(View*);
+void view_redraw_center(View*);
+void view_redraw_bottom(View*);
/* start selected area at current cursor position. further cursor movements will
* affect the selected region. */
-void window_selection_start(Win*);
+void view_selection_start(View*);
/* returns the currently selected text region, is either empty or well defined,
* i.e. sel.start <= sel.end */
-Filerange window_selection_get(Win*);
-void window_selection_set(Win*, Filerange *sel);
+Filerange view_selection_get(View*);
+void view_selection_set(View*, Filerange *sel);
/* clear selection and redraw window */
-void window_selection_clear(Win*);
+void view_selection_clear(View*);
/* get the currently displayed area in bytes from the start of the file */
-Filerange window_viewport_get(Win*);
+Filerange view_viewport_get(View*);
/* associate a set of syntax highlighting rules to this window. */
-void window_syntax_set(Win*, Syntax*);
-Syntax *window_syntax_get(Win*);
+void view_syntax_set(View*, Syntax*);
+Syntax *view_syntax_get(View*);
#endif