From: Michael D. Lowis Date: Mon, 17 Sep 2018 16:41:41 +0000 (-0400) Subject: Added Font tag for toggling between preset fonts or selecting a new font manually X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=34ae04c7e0fa8ea07213cf61670d19cfc7b49aa3;p=projs%2Ftide.git Added Font tag for toggling between preset fonts or selecting a new font manually --- diff --git a/TODO.md b/TODO.md index 498088a..2a2cc53 100644 --- a/TODO.md +++ b/TODO.md @@ -22,7 +22,6 @@ Tags: * Clear - Clear the current window's edit buffer * Line - Get the current line number(s) containing the selection * Kill - Kill a background command -* Font - Toggle font between monospace and proportional or set the font * ID - Get window id of the X window * Zerox - Create a copy of the window @@ -30,15 +29,16 @@ The Future: * Wily-like rc file for registering builtins * Case insensitive search -* use transaction ids to only mark buffer dirty when it really is * 100% coverage with unit and unit-integration tests -* tab inserts dont coalesce like one would expect * move by words is inconsistent. Example: var infoId = 'readerinfo'+reader.id; Maybe think about addressing these later: -* add current dir to path]'\\\''''''''''''''''''''''''''''' char is newline +* add current dir to path +* add support for guidefiles +* Shift+Insert should insert primary selection +* Find shortcut should select previous word if current char is newline # Auxillary Programs diff --git a/inc/edit.h b/inc/edit.h index 4a198bb..bffdbe0 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -186,7 +186,7 @@ enum { /* Color Names */ ClrCount }; -extern char *TagString, *FontString; +extern char *TagString, *Fonts[2]; extern int Palette[ClrCount]; extern int WinWidth, WinHeight, ScrollWidth, Timeout, TabWidth, ScrollBy, ClickTime, CopyIndent, TrimOnSave, ExpandTabs, DosLineFeed; diff --git a/inc/win.h b/inc/win.h index 5cbf2b6..9610219 100644 --- a/inc/win.h +++ b/inc/win.h @@ -133,6 +133,7 @@ typedef struct { void win_init(KeyBinding* bindings); void win_title(char* path); +void win_font(char* font); void win_prop_set(char* xname, char* ename, char* value); void win_update(int ms); void win_loop(void); diff --git a/lib/config.c b/lib/config.c index 4f712ed..1ce32cf 100644 --- a/lib/config.c +++ b/lib/config.c @@ -4,8 +4,11 @@ #include #include -char* TagString = "Del Put Undo Redo Find "; -char* FontString = "Verdana:size=11"; +char* TagString = "Del Put Undo Redo | Font Tabs | Find "; +char* Fonts[2] = { + "Verdana:size=11", + "Liberation Mono:size=11" +}; int /* Integer config options */ WinWidth = 640, diff --git a/lib/x11.c b/lib/x11.c index 09f5696..d0f0d37 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -49,6 +49,7 @@ static View Regions[NREGIONS]; static KeyBinding* Keys = NULL; static int Divider; static Atom SelTarget; +static int FontSel; static struct XSel Selections[] = { { .name = "PRIMARY" }, { .name = "CLIPBOARD" }, @@ -543,7 +544,7 @@ void win_init(KeyBinding* bindings) { X.colormap = wa.colormap; X.screen = DefaultScreen(X.display); X.depth = DefaultDepth(X.display, X.screen); - font_load(FontString); + font_load(Fonts[FontSel = 0]); x11_window("unnamed"); /* initialize selection atoms */ for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++) @@ -561,6 +562,14 @@ void win_title(char* path) { XStoreName(X.display, X.self, path); } +void win_font(char* font) { + if (font) { + font_load(font); + } else { + font_load(Fonts[++FontSel % nelem(Fonts)]); + } +} + void win_prop_set(char* xname, char* ename, char* value) { if (!value) return; Atom propname = XInternAtom(X.display, xname, 0); diff --git a/tide.c b/tide.c index 3762814..ecebb7f 100644 --- a/tide.c +++ b/tide.c @@ -46,10 +46,10 @@ static Tag* tag_lookup(char* cmd) { static void tag_exec(Tag* tag, char* arg) { /* if we didnt get an arg, find one in the selection */ - if (!arg) arg = view_getstr(win_view(TAGS)); - if (!arg) arg = view_getstr(win_view(EDIT)); + if (!arg || *arg) arg = view_getstr(win_view(TAGS)); + if (!arg || *arg) arg = view_getstr(win_view(EDIT)); /* execute the tag handler */ - tag->action(arg); + tag->action(arg || *arg ? NULL : arg); free(arg); } @@ -400,6 +400,7 @@ static Tag Builtins[] = { { .tag = "Redo", .action = tag_redo }, { .tag = "Tabs", .action = tabs }, { .tag = "Undo", .action = tag_undo }, + { .tag = "Font", .action = win_font }, { .tag = NULL, .action = NULL } }; @@ -459,12 +460,10 @@ static KeyBinding Bindings[] = { static void usage(void) { printf( "Usage: %s [FLAGS] [FILE]\n" - "\n -S 0,1 Enable/disable syntax highlighting" "\n -I 0,1 Enable/disable automatic indenting" "\n -W 0,1 Enable/disable trimming whitespace on save" "\n -E 0,1 Enable/disable expanding tabs to spaces" "\n -N 0,1 Enable/disable dos line ending style" - "\n -F str Set the font to use" "\n -T str String to use for the tags region" "\n -C str Set the shell to use for command execution\n", ARGV0); @@ -480,7 +479,6 @@ int main(int argc, char** argv) { case 'W': TrimOnSave = BOOLARG(); break; case 'E': ExpandTabs = BOOLARG(); break; case 'N': DosLineFeed = BOOLARG(); break; - case 'F': FontString = STRARG(); break; case 'T': TagString = STRARG(); break; case 'C': ShellCmd[0] = STRARG(); break; } OPTEND;