Skip to content

Commit

Permalink
remove SyntaxSymbol redirection type
Browse files Browse the repository at this point in the history
There is no reason why this isn't just a char *.
  • Loading branch information
rnpnr committed May 24, 2024
1 parent 4d38c3a commit 66c7dfe
Showing 3 changed files with 19 additions and 29 deletions.
38 changes: 17 additions & 21 deletions view.c
Original file line number Diff line number Diff line change
@@ -29,20 +29,20 @@
* the necessary offset for the last character.
*/

static const SyntaxSymbol symbols_none[] = {
[SYNTAX_SYMBOL_SPACE] = { " " },
[SYNTAX_SYMBOL_TAB] = { " " },
[SYNTAX_SYMBOL_TAB_FILL] = { " " },
[SYNTAX_SYMBOL_EOL] = { " " },
[SYNTAX_SYMBOL_EOF] = { " " },
static const char *symbols_none[] = {
[SYNTAX_SYMBOL_SPACE] = " ",
[SYNTAX_SYMBOL_TAB] = " ",
[SYNTAX_SYMBOL_TAB_FILL] = " ",
[SYNTAX_SYMBOL_EOL] = " ",
[SYNTAX_SYMBOL_EOF] = " ",
};

static const SyntaxSymbol symbols_default[] = {
[SYNTAX_SYMBOL_SPACE] = { "·" /* Middle Dot U+00B7 */ },
[SYNTAX_SYMBOL_TAB] = { "›" /* Single Right-Pointing Angle Quotation Mark U+203A */ },
[SYNTAX_SYMBOL_TAB_FILL] = { " " },
[SYNTAX_SYMBOL_EOL] = { "↵" /* Downwards Arrow with Corner Leftwards U+21B5 */ },
[SYNTAX_SYMBOL_EOF] = { "~" },
static const char *symbols_default[] = {
[SYNTAX_SYMBOL_SPACE] = "·", /* Middle Dot U+00B7 */
[SYNTAX_SYMBOL_TAB] = "›", /* Single Right-Pointing Angle Quotation Mark U+203A */
[SYNTAX_SYMBOL_TAB_FILL] = " ",
[SYNTAX_SYMBOL_EOL] = "↵", /* Downwards Arrow with Corner Leftwards U+21B5 */
[SYNTAX_SYMBOL_EOF] = "~",
};

static Cell cell_blank = { .width = 0, .len = 0, .data = " ", };
@@ -268,7 +268,7 @@ static bool view_expand_tab(View *view, Cell *cell) {
int displayed_width = view->tabwidth - (view->col % view->tabwidth);
for (int w = 0; w < displayed_width; ++w) {
int t = (w == 0) ? SYNTAX_SYMBOL_TAB : SYNTAX_SYMBOL_TAB_FILL;
const char *symbol = view->symbols[t]->symbol;
const char *symbol = view->symbols[t];
strncpy(cell->data, symbol, sizeof(cell->data) - 1);
cell->len = (w == 0) ? 1 : 0;

@@ -282,7 +282,7 @@ static bool view_expand_tab(View *view, Cell *cell) {

static bool view_expand_newline(View *view, Cell *cell) {
size_t lineno = view->line->lineno;
const char *symbol = view->symbols[SYNTAX_SYMBOL_EOL]->symbol;
const char *symbol = view->symbols[SYNTAX_SYMBOL_EOL];

strncpy(cell->data, symbol, sizeof(cell->data) - 1);
cell->width = 1;
@@ -316,7 +316,7 @@ static bool view_addch(View *view, Cell *cell) {
case '\n':
return view_expand_newline(view, cell);
case ' ': {
const char *symbol = view->symbols[SYNTAX_SYMBOL_SPACE]->symbol;
const char *symbol = view->symbols[SYNTAX_SYMBOL_SPACE];
strncpy(cell->data, symbol, sizeof(cell->data) - 1);
return view_add_cell(view, cell);
}}
@@ -869,8 +869,8 @@ void view_options_set(View *view, enum UiOption options) {
};

for (int i = 0; i < LENGTH(mapping); i++) {
view->symbols[i] = (options & mapping[i]) ? &symbols_default[i] :
&symbols_none[i];
view->symbols[i] = (options & mapping[i]) ? symbols_default[i] :
symbols_none[i];
}

if (options & UI_OPTION_LINE_NUMBERS_ABSOLUTE)
@@ -1332,10 +1332,6 @@ void view_selections_normalize(View *view) {
view_selections_set(prev, &range_prev);
}

char *view_symbol_eof_get(View *view) {
return view->symbols[SYNTAX_SYMBOL_EOF]->symbol;
}

void view_style(View *view, enum UiStyle style, size_t start, size_t end) {
if (end < view->start || start > view->end)
return;
8 changes: 1 addition & 7 deletions view.h
Original file line number Diff line number Diff line change
@@ -8,10 +8,6 @@
#include "text.h"
#include "array.h"

typedef struct {
char *symbol;
} SyntaxSymbol;

enum {
SYNTAX_SYMBOL_SPACE,
SYNTAX_SYMBOL_TAB,
@@ -69,7 +65,7 @@ typedef struct View {
int selection_count; /* how many cursors do currently exist */
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 */
const SyntaxSymbol *symbols[SYNTAX_SYMBOL_LAST]; /* symbols to use for white spaces etc */
const char *symbols[SYNTAX_SYMBOL_LAST]; /* symbols to use for white spaces etc */
int tabwidth; /* how many spaces should be used to display a tab character */
Selection *selections; /* all cursors currently active */
int selection_generation; /* used to filter out newly created cursors during iteration */
@@ -351,8 +347,6 @@ void view_tabwidth_set(View*, int tabwidth);
/** Apply a style to a text range. */
void view_style(View*, enum UiStyle, size_t start, size_t end);

char *view_symbol_eof_get(View*);

/** @} */

#endif
2 changes: 1 addition & 1 deletion vis.c
Original file line number Diff line number Diff line change
@@ -341,7 +341,7 @@ static void window_draw_eof(Win *win) {
if (view->width == 0)
return;
for (Line *l = view->lastline->next; l; l = l->next) {
strncpy(l->cells[0].data, view_symbol_eof_get(view), sizeof(l->cells[0].data)-1);
strncpy(l->cells[0].data, view->symbols[SYNTAX_SYMBOL_EOF], sizeof(l->cells[0].data)-1);
ui_window_style_set(win->ui, &l->cells[0], UI_STYLE_EOF);
}
}

0 comments on commit 66c7dfe

Please sign in to comment.