ledit

Text editor (WIP)
git clone git://lumidify.org/ledit.git (fast, but not encrypted)
git clone https://lumidify.org/git/ledit.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

commit 673c0ad7488286a17873fa81826e5212ac520642
parent 5f298263efe3a7df06b1275446967e56ca99e62d
Author: lumidify <nobody@lumidify.org>
Date:   Wed, 12 Jan 2022 19:33:03 +0100

Add more options to theme

Diffstat:
MMakefile | 2+-
Mbuffer.c | 1+
Mbuffer.h | 2++
Mkeys_basic_config.h | 4++--
Mtheme.c | 10++++++++++
Mtheme.h | 10++++++++++
Mtheme_config.h | 15+++++++++++++--
Mview.c | 29+++++++++++++++++------------
Mwindow.c | 2+-
9 files changed, 57 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile @@ -59,7 +59,7 @@ CONFIGHDR = \ keys_command_config.h \ keys_config.h -CFLAGS_LEDIT = ${CFLAGS} -g -Wall -Wextra -D_POSIX_C_SOURCE=200809L `pkg-config --cflags x11 xkbfile pangoxft xext` +CFLAGS_LEDIT = ${CFLAGS} -g -Wall -Wextra -pedantic -D_POSIX_C_SOURCE=200809L `pkg-config --cflags x11 xkbfile pangoxft xext` LDFLAGS_LEDIT = ${LDFLAGS} `pkg-config --libs x11 xkbfile pangoxft xext` -lm all: ${BIN} diff --git a/buffer.c b/buffer.c @@ -331,6 +331,7 @@ buffer_load_file(ledit_buffer *buffer, char *filename, size_t line, char **errst char *file_contents; FILE *file; + /* FIXME: https://wiki.sei.cmu.edu/confluence/display/c/FIO19-C.+Do+not+use+fseek()+and+ftell()+to+compute+the+size+of+a+regular+file */ file = fopen(filename, "r"); if (!file) goto error; if (fseek(file, 0, SEEK_END)) goto errorclose; diff --git a/buffer.h b/buffer.h @@ -264,6 +264,8 @@ void buffer_delete_with_undo( * adding the operation to the undo stack. * If 'line_ret' and 'byte_ret' are not NULL, they are filled with * the end position of the insertion. + * This function does not tell the views to update their line heights + * and offsets. */ void buffer_insert_with_undo_base( ledit_buffer *buffer, diff --git a/keys_basic_config.h b/keys_basic_config.h @@ -416,9 +416,9 @@ static struct key keys_hi[] = { {"ण", 0, 0, NORMAL, KEY_NONE, KEY_ENSURE_CURSOR_SHOWN, &key_search_prev}, {"ु", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &undo}, {"ू", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &redo}, - {".", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &repeat_command}, /* FIXME: only allow after finished key sequence */ + {".", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &repeat_command}, {"श", ControlMask, 0, INSERT, KEY_ANY, KEY_ENSURE_CURSOR_SHOWN, &undo}, - {"य", ControlMask, 0, INSERT, KEY_ANY, KEY_ENSURE_CURSOR_SHOWN, &redo}, /* FIXME: this is confusing with ctrl+y in normal mode */ + {"य", ControlMask, 0, INSERT, KEY_ANY, KEY_ENSURE_CURSOR_SHOWN, &redo}, {"ब", ControlMask, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &screen_up}, {"ट", ControlMask, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &screen_down}, {"े", ControlMask, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &scroll_with_cursor_down}, diff --git a/theme.c b/theme.c @@ -17,14 +17,24 @@ theme_create(ledit_common *common) { theme->text_size = TEXT_SIZE; theme->text_fg_hex = TEXT_FG; theme->text_bg_hex = TEXT_BG; + theme->cursor_fg_hex = CURSOR_FG; + theme->cursor_bg_hex = CURSOR_BG; + theme->selection_fg_hex = SELECTION_FG; + theme->selection_bg_hex = SELECTION_BG; theme->bar_fg_hex = BAR_FG; theme->bar_bg_hex = BAR_BG; + theme->bar_cursor_hex = BAR_CURSOR; theme->scrollbar_fg_hex = SCROLLBAR_FG; theme->scrollbar_bg_hex = SCROLLBAR_BG; XftColorAllocName(common->dpy, common->vis, common->cm, TEXT_FG, &theme->text_fg); XftColorAllocName(common->dpy, common->vis, common->cm, TEXT_BG, &theme->text_bg); + XftColorAllocName(common->dpy, common->vis, common->cm, CURSOR_FG, &theme->cursor_fg); + XftColorAllocName(common->dpy, common->vis, common->cm, CURSOR_BG, &theme->cursor_bg); + XftColorAllocName(common->dpy, common->vis, common->cm, SELECTION_FG, &theme->selection_fg); + XftColorAllocName(common->dpy, common->vis, common->cm, SELECTION_BG, &theme->selection_bg); XftColorAllocName(common->dpy, common->vis, common->cm, BAR_FG, &theme->bar_fg); XftColorAllocName(common->dpy, common->vis, common->cm, BAR_BG, &theme->bar_bg); + XftColorAllocName(common->dpy, common->vis, common->cm, BAR_CURSOR, &theme->bar_cursor); XftColorAllocName(common->dpy, common->vis, common->cm, SCROLLBAR_FG, &theme->scrollbar_fg); XftColorAllocName(common->dpy, common->vis, common->cm, SCROLLBAR_BG, &theme->scrollbar_bg); return theme; diff --git a/theme.h b/theme.h @@ -10,15 +10,25 @@ typedef struct { int text_size; XftColor text_fg; XftColor text_bg; + XftColor cursor_fg; + XftColor cursor_bg; + XftColor selection_fg; + XftColor selection_bg; XftColor bar_fg; XftColor bar_bg; + XftColor bar_cursor; XftColor scrollbar_fg; XftColor scrollbar_bg; const char *text_font; const char *text_fg_hex; const char *text_bg_hex; + const char *cursor_fg_hex; + const char *cursor_bg_hex; + const char *selection_fg_hex; + const char *selection_bg_hex; const char *bar_fg_hex; const char *bar_bg_hex; + const char *bar_cursor_hex; const char *scrollbar_fg_hex; const char *scrollbar_bg_hex; } ledit_theme; diff --git a/theme_config.h b/theme_config.h @@ -2,14 +2,25 @@ static const char *TEXT_FONT = "Monospace"; /* size used for text in points or whatever pango uses */ static const int TEXT_SIZE = 12; -/* foreground color of main text area */ +/* text color of main text area */ static const char *TEXT_FG = "#000000"; /* background color of main text area */ static const char *TEXT_BG = "#FFFFFF"; -/* foreground color of status bar/line editor */ +/* color of text under cursor */ +static const char *CURSOR_FG = "#FFFFFF"; +/* color of text cursor */ +static const char *CURSOR_BG = "#000000"; +/* color of selected text */ +static const char *SELECTION_FG = "#FFFFFF"; +/* color of selection */ +static const char *SELECTION_BG = "#000000"; + +/* text color of status bar/line editor */ static const char *BAR_FG = "#000000"; /* background color of status bar/line editor */ static const char *BAR_BG = "#CCCCCC"; +/* color of text cursor in status bar/line editor */ +static const char *BAR_CURSOR = "#000000"; /* FIXME: give in units other than pixels */ /* scrollbar width in pixels */ diff --git a/view.c b/view.c @@ -62,7 +62,10 @@ static void set_pango_text_and_highlight(ledit_view *view, size_t line); static PangoLayout *get_pango_layout(ledit_view *view, size_t line); /* Get an attribute list for a text highlight between the given range. */ -static PangoAttrList *get_pango_attributes(ledit_view *view, size_t start_byte, size_t end_byte); +static PangoAttrList *get_pango_attributes( + size_t start_byte, size_t end_byte, + XRenderColor fg, XRenderColor bg +); /* * Set the attributes for a PangoLayout belonging to the given line index. @@ -304,11 +307,9 @@ view_cleanup(void) { } static PangoAttrList * -get_pango_attributes(ledit_view *view, size_t start_byte, size_t end_byte) { - XRenderColor fg = view->theme->text_fg.color; - XRenderColor bg = view->theme->text_bg.color; - PangoAttribute *attr0 = pango_attr_background_new(fg.red, fg.green, fg.blue); - PangoAttribute *attr1 = pango_attr_foreground_new(bg.red, bg.green, bg.blue); +get_pango_attributes(size_t start_byte, size_t end_byte, XRenderColor fg, XRenderColor bg) { + PangoAttribute *attr0 = pango_attr_foreground_new(fg.red, fg.green, fg.blue); + PangoAttribute *attr1 = pango_attr_background_new(bg.red, bg.green, bg.blue); attr0->start_index = start_byte; attr0->end_index = end_byte; attr1->start_index = start_byte; @@ -330,23 +331,27 @@ set_line_layout_attrs(ledit_view *view, size_t line, PangoLayout *layout) { ledit_view_line *vl = view_get_line(view, line); PangoAttrList *list = NULL; if (view->sel_valid) { + XRenderColor fg = view->theme->selection_fg.color; + XRenderColor bg = view->theme->selection_bg.color; ledit_range sel = view->sel; sort_range(&sel.line1, &sel.byte1, &sel.line2, &sel.byte2); if (sel.line1 < line && sel.line2 > line) { - list = get_pango_attributes(view, 0, ll->len); + list = get_pango_attributes(0, ll->len, fg, bg); } else if (sel.line1 == line && sel.line2 == line) { size_t start = sel.byte1, end = sel.byte2; if (start > end) swap_sz(&start, &end); - list = get_pango_attributes(view, start, end); + list = get_pango_attributes(start, end, fg, bg); } else if (sel.line1 == line && sel.line2 > line) { - list = get_pango_attributes(view, sel.byte1, ll->len); + list = get_pango_attributes(sel.byte1, ll->len, fg, bg); } else if (sel.line1 < line && sel.line2 == line) { - list = get_pango_attributes(view, 0, sel.byte2); + list = get_pango_attributes(0, sel.byte2, fg, bg); } } else if (vl->cursor_index_valid) { + XRenderColor fg = view->theme->cursor_fg.color; + XRenderColor bg = view->theme->cursor_bg.color; /* FIXME: does just adding one really do the right thing? */ - list = get_pango_attributes(view, vl->cursor_index, vl->cursor_index + 1); + list = get_pango_attributes(vl->cursor_index, vl->cursor_index + 1, fg, bg); } if (list != NULL) { pango_layout_set_attributes(layout, list); @@ -1879,7 +1884,7 @@ view_redraw_text(ledit_view *view) { h += vline->h; } - XSetForeground(view->buffer->common->dpy, view->window->gc, view->theme->text_fg.pixel); + XSetForeground(view->buffer->common->dpy, view->window->gc, view->theme->cursor_bg.pixel); PangoRectangle strong, weak; ledit_line *cur_line = buffer_get_line(view->buffer, view->cur_line); PangoLayout *layout = get_pango_layout(view, view->cur_line); diff --git a/window.c b/window.c @@ -708,7 +708,7 @@ window_redraw(ledit_window *window) { 0, window->text_h ); } else if (window->bottom_text_shown) { - XSetForeground(window->common->dpy, window->gc, t->bar_fg.pixel); + XSetForeground(window->common->dpy, window->gc, t->bar_cursor.pixel); /* move input method position to cursor and draw cursor */ PangoRectangle strong, weak; pango_layout_get_cursor_pos(