Permalink
Browse files

Configurable keymapping

  • Loading branch information...
ec429
ec429 committed Jul 5, 2011
1 parent 8ee9802 commit 62617ffc09802a764bcf2f396aa55ab8832e98dd
Showing with 1,023 additions and 265 deletions.
  1. +1 −0 .gitignore
  2. +14 −3 Makefile
  3. +31 −6 README
  4. +94 −0 config.c
  5. +5 −0 config.h
  6. +15 −4 distMakefile
  7. +172 −0 genkeymap.c
  8. +265 −242 input.c
  9. +5 −3 input.h
  10. +302 −0 keymap.c
  11. +48 −0 keymod.h
  12. +38 −0 keys
  13. +13 −2 quirc.c
  14. +20 −5 readme.htm
View
@@ -5,5 +5,6 @@ quirc
*.tar.gz
*.tgz
genconfig
+genkeymap
version.h
View
@@ -60,18 +60,21 @@ buffer.h: config.h version.h
config.o: config.c config.h names.h bits.h colour.h text.h version.h
-config.c: config_check.c config_def.c config_need.c config_rcread.c config_pargs.c config_help.c
+config.c: config_check.c config_def.c config_need.c config_rcread.c config_pargs.c config_help.c keymap.c
touch config.c
-config.h: config_globals.h version.h
+config.h: config_globals.h version.h keymod.h
touch config.h
config_%: config.cdl genconfig
./genconfig $@ < config.cdl > $@ || (rm $@ && false)
genconfig: genconfig.c
-input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h
+input.h: keymod.h
+ touch input.h
+
+input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h config.h
input.c: config_set.c
touch input.c
@@ -83,6 +86,14 @@ script.o: script.c script.h bits.h buffer.h
c_init.c: colour.d c_init.awk
$(AWK) -f c_init.awk colour.d > c_init.c
+genkeymap: genkeymap.c
+
+keymod.h: keys genkeymap
+ ./genkeymap h < keys > $@ || (rm $@ && false)
+
+keymap.c: keys genkeymap
+ ./genkeymap c < keys > $@ || (rm $@ && false)
+
FORCE:
version.h: FORCE
./gitversion
View
37 README
@@ -1,13 +1,13 @@
****** quIRC: readme ******
-** quIRC is a simple terminal-based IRC (Internet Relay Chat) client. It is
-written in C. **
+** quIRC is a lightweight terminal-based IRC client. It is written in C. **
***** Contents *****
* Further_Help
* Commands
* Configuration
* Input_Controls
* Other_Controls
+ * Keymapping
* Tab_strip
* Troubleshooting
***** Further Help *****
@@ -116,11 +116,13 @@ the channel (or nick if current tab is a private messaging tab).
Sorts the tab list into an intuitive order (grouping channels after their
parent servers; maintaining the order of the servers and of each server's
channels).
+ //[msg]
+ Sends /msg to the channel.
***** Configuration *****
quIRC can be configured through an "rc file" as follows. (For a compact
reference table see config_ref.htm)
-In your home directory (/home/username), create a file called ".quirc", and
-open it in your editor.
+In your home directory (/home/username), create a folder called ".quirc", a
+file within that folder called "rc", and open it in your editor.
In this file you can set servers, nick and channels to automatically use:
nick global-nickname
ignore -options global-ignore
@@ -254,8 +256,27 @@ These are based, broadly, on bash's controls.
Ctrl-left
Ctrl-right
Change tab.
- Alt-[#], where [#] is a number key
- Equivalent to /tab [#]
+ F1 through F12
+ Equivalent to /tab #, except that F12 is /tab 0.
+***** Keymapping *****
+quIRC's mapping of function and other special keys defaults to a VT100 mapping,
+such as used by xterm and rxvt. However, this mapping can be changed with a
+file /home/username/.quirc/keys.
+To change key mappings, add lines of the form MODNAME hex. The MODNAMEs
+expected are those which appear in the "keys" file in the quIRC source
+directory; at present, these are:
+BS, UP, DOWN, LEFT, RIGHT, HOME, END, DELETE, PGUP, PGDN, CUP, AUP, CDOWN,
+ADOWN, CLEFT, ALEFT, CRIGHT, ARIGHT, CHOME, AHOME, CEND, AEND, CPGUP, APGUP,
+CPGDN, APGDN, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, and F12.
+The prefix 'C' refers to Ctrl, and 'A' to Alt.
+If, for instance, your terminal sends Ctrl-Left as ^[OD, you would add the
+following line:
+CLEFT 1b4f44
+Similarly, if your terminal sends backspace as ^H, you would add:
+BS 08
+You can find out what sequences your terminal sends for various keys by running
+a hex-dump program such as xxd or hd, pressing the key, and noting the output.
+(You will usually need to press first the key, then enter/return, then ^D)
***** Tab strip *****
The strip of tabs along the bottom of the screen has various indicators.
The parens bracketing the name tell you what kind of tab it is:
@@ -285,3 +306,7 @@ turns yellow.
positioning). For details see your terminal emulator's documentation; it
is known that xterm works out-of-the-box, and that PuTTY has an option to
enable VT100 support.
+ The control keys/cursor keys/function keys don't do anything!
+ This probably means your terminal isn't sending VT100 (ANSI) escape
+ sequences, but rather some other set of sequences. See the section
+ "Keymapping", above.
View
@@ -8,6 +8,100 @@
#include "config.h"
+#include "keymap.c"
+
+void loadkeys(FILE *fp)
+{
+ if(!fp) return;
+ while(!feof(fp))
+ {
+ char *line=fgetl(fp);
+ if(line)
+ {
+ if((*line)&&(*line!='#'))
+ {
+ keymod new;
+ new.name=strtok(line, " \t");
+ char *mod=strtok(NULL, " \t");
+ if(!mod)
+ {
+ char msg[32+strlen(new.name)];
+ sprintf(msg, "keys: missing mod in %s", new.name);
+ asb_failsafe(c_err, msg);
+ free(line);
+ continue;
+ }
+ off_t o=strlen(mod);
+ if(o&1)
+ {
+ char msg[32+strlen(new.name)];
+ sprintf(msg, "keys: odd mod length in %s", new.name);
+ asb_failsafe(c_err, msg);
+ free(line);
+ continue;
+ }
+ new.mod=malloc((o>>1)+1);
+ if(!new.mod)
+ {
+ char msg[32+strlen(new.name)];
+ sprintf(msg, "keys: malloc failure in %s", new.name);
+ asb_failsafe(c_err, msg);
+ free(line);
+ continue;
+ }
+ bool cont=false;
+ for(int i=0;i<o;i+=2)
+ {
+ if(!(isxdigit(mod[i])&&isxdigit(mod[i+1])))
+ {
+ char msg[32+strlen(new.name)];
+ sprintf(msg, "keys: bad mod (not hex) in %s", new.name);
+ asb_failsafe(c_err, msg);
+ free(line);
+ cont=true;
+ break;
+ }
+ char buf[3];buf[0]=mod[i];buf[1]=mod[i+1];buf[2]=0;
+ unsigned int c;
+ if(sscanf(buf, "%x", &c)!=1)
+ {
+ char msg[32+strlen(new.name)];
+ sprintf(msg, "keys: sscanf failed in %s", new.name);
+ asb_failsafe(c_err, msg);
+ free(line);
+ cont=true;
+ break;
+ }
+ new.mod[i>>1]=c;
+ }
+ if(cont) continue;
+ new.mod[o>>1]=0;
+ bool match=false;
+ for(int i=0;i<nkeys;i++)
+ {
+ if(strcmp(new.name, kmap[i].name)==0)
+ {
+ free(kmap[i].mod);
+ kmap[i].mod=strdup(new.mod);
+ match=true;
+ }
+ }
+ if(!match)
+ {
+ char msg[32+strlen(new.name)];
+ sprintf(msg, "keys: unrecognised name %s", new.name);
+ asb_failsafe(c_err, msg);
+ }
+ free(new.mod);
+ }
+ free(line);
+ }
+ else
+ break;
+ }
+ return;
+}
+
#include "config_check.c"
int def_config(void)
View
@@ -39,6 +39,7 @@ servlist;
#include "text.h"
#include "version.h"
#include "buffer.h"
+#include "keymod.h"
// global settings & state
#include "config_globals.h"
@@ -47,7 +48,11 @@ char *username, *fname, *nick, *portno;
servlist *servs;
name *igns;
char *version;
+int nkeys;
+keymod *kmap;
+int initkeys(void);
+void loadkeys(FILE *);
int conf_check(void); // writes diagnostics to start-buffer
int def_config(void); // set these to their defaults
int rcread(FILE *rcfp); // read & parse the rc file.
View
@@ -8,7 +8,7 @@ PREFIX ?= /usr/local
LIBS := ttyraw.o ttyesc.o irc.o bits.o colour.o buffer.o names.o config.o input.o
INCLUDE := ttyraw.h ttyesc.h irc.h bits.h colour.h buffer.h names.h config.h input.h quirc.h version.h
-all: quirc
+all: quirc doc
install: all
install -D -m0755 quirc $(PREFIX)/bin/quirc
@@ -59,18 +59,21 @@ buffer.h: config.h version.h
config.o: config.c config.h names.h bits.h colour.h text.h version.h
-config.c: config_check.c config_def.c config_need.c config_rcread.c config_pargs.c config_help.c
+config.c: config_check.c config_def.c config_need.c config_rcread.c config_pargs.c config_help.c keymap.c
touch config.c
-config.h: config_globals.h version.h
+config.h: config_globals.h version.h keymod.h
touch config.h
config_%: config.cdl genconfig
./genconfig $@ < config.cdl > $@ || (rm $@ && false)
genconfig: genconfig.c
-input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h
+input.h: keymod.h
+ touch input.h
+
+input.o: input.c input.h ttyesc.h names.h buffer.h irc.h bits.h config.h
input.c: config_set.c
touch input.c
@@ -82,3 +85,11 @@ script.o: script.c script.h bits.h buffer.h
c_init.c: colour.d c_init.awk
$(AWK) -f c_init.awk colour.d > c_init.c
+genkeymap: genkeymap.c
+
+keymod.h: keys genkeymap
+ ./genkeymap h < keys > $@ || (rm $@ && false)
+
+keymap.c: keys genkeymap
+ ./genkeymap c < keys > $@ || (rm $@ && false)
+
Oops, something went wrong.

0 comments on commit 62617ff

Please sign in to comment.