Added samrc support for colors and fonts. - sam - An updated version of the sam… | |
git clone git://vernunftzentrum.de/sam.git | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 8ad914d3131fe32f0ed3a400a638f764fb75210f | |
parent 071c95698bc28739fb0289c84ff46a2278d1270c | |
Author: Rob King <[email protected]> | |
Date: Fri, 9 Sep 2016 14:35:42 -0500 | |
Added samrc support for colors and fonts. | |
Diffstat: | |
Makefile | 10 ++-------- | |
README.rst | 20 +++++++++++--------- | |
chords.h.def | 37 ------------------------------- | |
commands.h.def | 109 ------------------------------- | |
doc/samrc | 42 +++++++++++++++++++++++++++++++ | |
include/libg.h | 5 +++++ | |
libXg/xtbinit.c | 15 ++++++++++----- | |
samterm/samrc.c | 16 +++++++++++----- | |
8 files changed, 81 insertions(+), 173 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
@@ -6,13 +6,7 @@ | |
MODE?=user | |
-all: chords.h config.h config.mk commands.h lXg lframe rsamdir samdir s… | |
- | |
-chords.h: | |
- cp chords.h.def chords.h | |
- | |
-commands.h: | |
- cp commands.h.def commands.h | |
+all: config.h config.mk lXg lframe rsamdir samdir samtermdir docdir | |
config.h: | |
cp config.h.def config.h | |
@@ -55,4 +49,4 @@ clean: | |
cd rsam; $(MAKE) clean | |
nuke: clean | |
- rm -f chords.h config.h commands.h config.mk | |
+ rm -f config.h config.mk | |
diff --git a/README.rst b/README.rst | |
@@ -41,10 +41,10 @@ Basic Installation | |
------------------- | |
Installation and configuration is fairly simple: | |
-- Copy `config.mk.def` to `config.mk` and modify as needed. | |
-- Copy `config.h.def` to `config.h` and modify as needed. | |
-- Copy `commands.h.def` to `commands.h` and modify as needed. | |
-- Copy `chords.h.def` to `chords.h` and modify as needed. | |
+- Copy `config.mk.def` to `config.mk` and modify as needed | |
+ (a default version will be used if you don't do this that will probably be f… | |
+- Copy `config.h.def` to `config.h` and modify as needed | |
+ (a default version will be used if you don't do this that will probably be f… | |
- Run `make clean all` | |
- Run `make install` or, if needed, `sudo make install` | |
@@ -109,17 +109,19 @@ Multicolor Support | |
This version of sam supports colors, including different background colors… | |
This allows different files to be easily distinguished. | |
The default is still the classic two-color appearance, of course. | |
+ These colors can be configured at runtime. | |
Simplified and Dynamic Configuration | |
The graphical elements (colors and fonts) of this version of sam are contr… | |
The table of composable characters is now dynamically configurable (via th… | |
where it was once hard-coded. | |
+ Keybindings and mouse chords are configurable at runtime via a configurati… | |
Far Better Keyboard Support | |
The selection ("cursor") can be moved using keyboard commands. | |
Additional keyboard-accessible commands allow jumping between file windows… | |
scrolling the display, snarfing, pasting, etc. | |
- The binding of these commands to keyboard sequences is configurable at com… | |
+ The binding of these commands to keyboard sequences is configurable at run… | |
Support for Two-Button Mice and Wheel Mice | |
The original sam required a three-button mouse. | |
@@ -129,7 +131,7 @@ Support for Two-Button Mice and Wheel Mice | |
Support for Mouse Chords | |
The commands available for keyboard binding are also accessible via mouse-… | |
By default, the snarf, cut, and paste commands are mapped to chords. | |
- The binding of these chords is configurable at compile-time. | |
+ The binding of these chords is configurable at run-time. | |
Better Remote Editing Support | |
This version of sam can use `ssh(1)` as its remote shell. | |
@@ -190,15 +192,15 @@ Primary Goals | |
- send (TODO) | |
- eol / bol (DONE) | |
- Support a configurable scroll factor; | |
- scrolling is a bit drastic now (TODO) | |
+ scrolling is a bit drastic now (DONE) | |
- Support Unicode beyond the Basic Multilingual Plane | |
(note that this will break the sam binary protocol, | |
so this version of samterm won't work with other sams! | |
Email me if you think this is a bad idea; I'm willing to reconsider) (TODO) | |
- Support font fallback (TODO) | |
-- Allow runtime configuration of key bindings (TODO) | |
+- Allow runtime configuration of key bindings (DONE) | |
- Support a configurable set of mouse chords (DONE) | |
-- Support runtime configuration of mouse chords (TODO) | |
+- Support runtime configuration of mouse chords (DONE) | |
- Support mouse button reassignment (TODO) | |
- Support runtime mouse button reassignment (TODO) | |
- Remove non-*nix OS support (Plan 9 has their own sam) (TODO) | |
diff --git a/chords.h.def b/chords.h.def | |
@@ -1,37 +0,0 @@ | |
-/* This file defines mappings of mouse chords to commands. | |
- * The lines are of the form: | |
- * | |
- * {start, end, kind, action} | |
- * | |
- * start - the start state (i.e. what mouse buttons were pressed) | |
- * end - the end state (i.e. what mouse buttons are now pressed) | |
- * action - one of the commands listed in commands.h (or commands.h.def) | |
- * target - Tcurrent for the current (typing) layer | |
- * - Tmouse for the layer containing the mouse | |
- * | |
- * The following values are available for state definitions: | |
- * Bnone - No buttons are pressed | |
- * B[1-5] - Button n is pressed | |
- * | |
- * The Bn masks can be combined using the "|" operator, so | |
- * "B1|B2" means "both buttons 1 and 2 pressed". | |
- * | |
- * The default configuration shipped with sam has the mouse chords of the | |
- * "classic" Unix sam of the 1980s. | |
- */ | |
- | |
-{B1, B1|B2, Kcommand, Ccut, Tcurrent}, | |
-{B1, B1|B3, Kcommand, Cpaste, Tcurrent}, | |
- | |
-{B4, Bnone, Kcommand, Cscrollupline, Tmouse}, | |
-{B5, Bnone, Kcommand, Cscrolldownline, Tmouse}, | |
- | |
-/* The lines below "cancel" the mouse movement that is implicit above | |
- * in the Ccut and Cpaste chords. If these lines are not present, dot | |
- * will move to where the mouse is after the chords above are used. | |
- * | |
- * Some people might like that kind of behavior: if so, just remove | |
- * these lines. | |
- */ | |
-{B1|B3, B1, Kcommand, Cnone, Tcurrent}, | |
-{B1|B2, B1, Kcommand, Cnone, Tcurrent}, | |
diff --git a/commands.h.def b/commands.h.def | |
@@ -1,109 +0,0 @@ | |
-/* This file defines the keyboard mappings for keyboard commands. | |
- * The lines are of the form: | |
- * | |
- * {mask, keysym, kind, action} | |
- * | |
- * mask - one of the X modifier masks | |
- * or the user-defined COMMANDMASK (see config.h) | |
- * or 0, for no modifier | |
- * keysym - one of the X symbolic keysym names | |
- * kind - Kcommand for commands | |
- * Kraw for literal characters | |
- * Kcomposed for composed characters | |
- * action - for Kraw and Kcomposed, a single character | |
- * for Kcommand, one of the commands below | |
- * | |
- * Available commands are: | |
- * | |
- * Cnone - ignore the key | |
- * Cscrollup - scroll up by screen | |
- * Cscrolldown - scroll down by screen | |
- * Cscrollupline - scroll up by line | |
- * Cscrolldownline - scroll down by line | |
- * Clineup - move up by line | |
- * Clinedown - move down by line | |
- * Ccharright - move right by character | |
- * Ccharleft - move left by character | |
- * Cdelbol - delete to beginning of line | |
- * Cdelword - delete previous word | |
- * Cdel - delete previous character | |
- * Cjump - jump to and from the command window | |
- * Cescape - highlight recently typed text | |
- * Csnarf - copy text to the snarf buffer | |
- * Cpaste - paste text from the snarf buffer | |
- * Ccut - cut text to the snarf buffer | |
- * Cexchange - exchange operating system and sam snarf buffers | |
- * Cwrite - write the current file to disk | |
- * Cbol - move to beginning of line | |
- * Ceol - move to end of line | |
- * | |
- * The default configuration shipped with sam has the keyboard commands mapped | |
- * to the "classic" Unix sam of the 1980s, plus the WordStar Diamond for cursor | |
- * movement. | |
- * | |
- * Another popular choice is to map to vi-like bindings, see below. | |
- */ | |
- | |
-/* Commonly changed commands. */ | |
-{COMMANDMASK, XK_e, Kcommand, Clineup}, | |
-{COMMANDMASK, XK_x, Kcommand, Clinedown}, | |
-{COMMANDMASK, XK_d, Kcommand, Ccharright}, | |
-{COMMANDMASK, XK_s, Kcommand, Ccharleft}, | |
-{COMMANDMASK, XK_u, Kcommand, Cdelbol}, | |
-{COMMANDMASK, XK_w, Kcommand, Cdelword}, | |
-{COMMANDMASK, XK_k, Kcommand, Cjump}, | |
-{COMMANDMASK, XK_BackSpace, Kcommand, Cdelword}, | |
-{COMMANDMASK, XK_y, Kcommand, Ccut}, | |
-{COMMANDMASK, XK_c, Kcommand, Csnarf}, | |
-{COMMANDMASK, XK_v, Kcommand, Cpaste}, | |
-{COMMANDMASK, XK_q, Kcommand, Cexchange}, | |
- | |
-/* Use COMMAND-Tab to insert a literal tab when tab expansion is enabled. */ | |
-{COMMANDMASK, XK_Tab, Kcomposed, '\t'}, | |
- | |
-/* Some users might like these vi-like bindings. | |
-{COMMANDMASK, XK_h, Kcommand, Ccharleft}, | |
-{COMMANDMASK, XK_l, Kcommand, Ccharright}, | |
-{COMMANDMASK, XK_j, Kcommand, Clinedown}, | |
-{COMMANDMASK, XK_k, Kcommand, Clineup}, | |
-{COMMANDMASK, XK_space, Kcommand, Cescape}, | |
-{0, XK_Escape, Kcommand, Cjump}, */ | |
- | |
-/* Some users might like to make the arrow keys move the selection more logica… | |
-{0, XK_Up, Kcommand, Clineup}, | |
-{0, XK_Down, Kcommand, Clinedown}, | |
-{0, XK_Left, Kcommand, Ccharleft}, | |
-{0, XK_Right, Kcommand, Ccharright}, */ | |
- | |
-/* Less commonly changed commands (though see above about the arrow keys). */ | |
-{0, XK_Up, Kcommand, Cscrollup}, | |
-{0, XK_Prior, Kcommand, Cscrollup}, | |
-{0, XK_Left, Kcommand, Cscrollup}, | |
-{0, XK_Down, Kcommand, Cscrolldown}, | |
-{0, XK_Next, Kcommand, Cscrolldown}, | |
-{0, XK_Right, Kcommand, Cscrolldown}, | |
-{0, XK_Escape, Kcommand, Cescape}, | |
- | |
-/* You probably shouldn't change these. */ | |
-{0, XK_BackSpace, Kcommand, Cdel}, | |
-{0, XK_Delete, Kcommand, Cdel}, | |
-{0, XK_Return, Kraw, '\n'}, | |
-{0, XK_KP_Enter, Kraw, '\n'}, | |
-{0, XK_Linefeed, Kraw, '\r'}, | |
-{0, XK_Tab, Kraw, '\t'}, | |
-{0, XK_KP_0, Kraw, '0'}, | |
-{0, XK_KP_1, Kraw, '1'}, | |
-{0, XK_KP_2, Kraw, '2'}, | |
-{0, XK_KP_3, Kraw, '3'}, | |
-{0, XK_KP_4, Kraw, '4'}, | |
-{0, XK_KP_5, Kraw, '5'}, | |
-{0, XK_KP_6, Kraw, '6'}, | |
-{0, XK_KP_7, Kraw, '7'}, | |
-{0, XK_KP_8, Kraw, '8'}, | |
-{0, XK_KP_9, Kraw, '9'}, | |
-{0, XK_KP_Divide, Kraw, '/'}, | |
-{0, XK_KP_Multiply, Kraw, '*'}, | |
-{0, XK_KP_Subtract, Kraw, '-'}, | |
-{0, XK_KP_Add, Kraw, '+'}, | |
-{0, XK_KP_Decimal, Kraw, '.'}, | |
-{0, XK_hyphen, Kraw, '-'}, | |
diff --git a/doc/samrc b/doc/samrc | |
@@ -0,0 +1,42 @@ | |
+# This is a sample samrc file that sets up samterm the | |
+# way I like it. This offers a good starting point for | |
+# your own customized version. | |
+ | |
+# Control-A and Control-E jump to beginning/end of line | |
+bind C a command bol | |
+bind C e command eol | |
+ | |
+# Control-H/L/J/K move left/right/down/up | |
+bind C h command charleft | |
+bind C l command charright | |
+bind C j command linedown | |
+bind C k command lineup | |
+ | |
+# Control-Space highlights recently-typed text | |
+bind C space command escape | |
+ | |
+# Escape jumps between command file and working file | |
+bind n Escape command jump | |
+ | |
+# Control-U deletes to beginning of line | |
+bind C u command delbol | |
+ | |
+# Control-W/BackSpace deletes previous word | |
+bind C w command delword | |
+bind C BackSpace command delword | |
+ | |
+# Control-X/C/V does cut/snarf/paste | |
+bind C x command cut | |
+bind C c command snarf | |
+bind C v command paste | |
+ | |
+# Control-Q exchanges snarf buffers with windowing system | |
+bind C q command exchange | |
+ | |
+# Up/Down/Left/Right/PageUp/PageDown work as expected | |
+bind n Up command lineup | |
+bind n Down command linedown | |
+bind n Left command charleft | |
+bind n Right command charright | |
+bind n Prior command scrollup | |
+bind n Next command scrolldown | |
diff --git a/include/libg.h b/include/libg.h | |
@@ -232,4 +232,9 @@ extern XftColor bgcolor; | |
extern int installbinding(int, KeySym, int, int); | |
extern int installchord(int, int, int, int); | |
+ | |
+extern char foregroundspec[1024]; | |
+extern char backgroundspec[1024]; | |
+extern char borderspec[1024]; | |
+extern char fontspec[1024]; | |
#endif | |
diff --git a/libXg/xtbinit.c b/libXg/xtbinit.c | |
@@ -52,6 +52,10 @@ | |
Bitmap screen; | |
XftFont *font; | |
XftColor fontcolor; | |
+char fontspec[1024] = {0}; | |
+char foregroundspec[1024] = {0}; | |
+char backgroundspec[1024] = {0}; | |
+char borderspec[1024] = {0}; | |
/* implementation globals */ | |
extern char *machine; | |
@@ -179,11 +183,12 @@ xtbinit(Errfunc f, char *class, int *pargc, char **argv, … | |
widg = XtCreateManagedWidget("gwin", gwinWidgetClass, _toplevel, args, n); | |
_dpy = XtDisplay(widg); | |
- XAllocNamedColor(_dpy, DefaultColormap(_dpy, DefaultScreen(_dpy)), getenv(… | |
- XAllocNamedColor(_dpy, DefaultColormap(_dpy, DefaultScreen(_dpy)), getenv(… | |
- | |
+ XAllocNamedColor(_dpy, DefaultColormap(_dpy, DefaultScreen(_dpy)), | |
+ foregroundspec[0] ? foregroundspec : getenv("FOREGROUND")… | |
+ XAllocNamedColor(_dpy, DefaultColormap(_dpy, DefaultScreen(_dpy)), | |
+ borderspec[0] ? borderspec : getenv("BORDER") ? getenv("B… | |
char bgspec[1024] = {0}; | |
- strncpy(bgspec, getenv("BACKGROUND") ? getenv("BACKGROUND") : DEFAULT_BACK… | |
+ strncpy(bgspec, backgroundspec[0] ? backgroundspec : getenv("BACKGROUND") … | |
char *bgc = NULL; | |
for (bgc = strtok(bgspec, ":"); bgc != NULL && _nbgs < MAX_BACKGROUNDS; bg… | |
@@ -212,7 +217,7 @@ xtbinit(Errfunc f, char *class, int *pargc, char **argv, ch… | |
atexit(freebindings); | |
atexit(freechords); | |
- font = XftFontOpenName(_dpy, DefaultScreen(_dpy), getenv("FONT") ? getenv(… | |
+ font = XftFontOpenName(_dpy, DefaultScreen(_dpy), fontspec[0] ? fontspec :… | |
screen.id = 0; | |
XtRealizeWidget(_toplevel); | |
_topwindow = XtWindow(_toplevel); | |
diff --git a/samterm/samrc.c b/samterm/samrc.c | |
@@ -220,14 +220,14 @@ loadrcfile(FILE *f) | |
while ((r = getline(&l, &n, f)) >= 0){ | |
char s1[6] = {0}; | |
char s2[6] = {0}; | |
- char cname[100] = {0}; | |
- char tname[100] = {0}; | |
+ char cname[1024] = {0}; | |
+ char tname[1024] = {0}; | |
char c = 0; | |
unsigned short i = 0; | |
int rc = 0; | |
ln++; | |
- if (r == 0 || l[0] == '\n' || l[0] == 0) | |
+ if (r == 0 || l[0] == '\n' || l[0] == 0 || sscanf(l, " %[#]", &c) == 1) | |
continue; | |
if (sscanf(l, " chord %5[Nn12345] %5[Nn12345] %99s %99s", s1, s2, cnam… | |
@@ -242,8 +242,14 @@ loadrcfile(FILE *f) | |
rc = installbinding(statetomask(s1, modmapping), XStringToKeysym(s… | |
else if (sscanf(l, " bind %5[ncamshNCAMSH12345] %99s command %99s", s1… | |
rc = installbinding(statetomask(s1, modmapping), XStringToKeysym(s… | |
- else if (sscanf(l, " %[#]", &c) == 1) | |
- continue; | |
+ else if (sscanf(l, " foreground %1023s", cname) == 1) | |
+ strncpy(foregroundspec, cname, sizeof(foregroundspec) - 1); | |
+ else if (sscanf(l, " background %1023s", cname) == 1) | |
+ strncpy(backgroundspec, cname, sizeof(backgroundspec) - 1); | |
+ else if (sscanf(l, " border %1023s", cname) == 1) | |
+ strncpy(borderspec, cname, sizeof(borderspec) - 1); | |
+ else if (sscanf(l, " font %1023s", cname) == 1) | |
+ strncpy(fontspec, cname, sizeof(fontspec) - 1); | |
else | |
fprintf(stderr, "invalid rc line %zd\n", ln); | |