[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
console-ncurses discoveries / Alt-F# console selection patch.
From: |
David Walter |
Subject: |
console-ncurses discoveries / Alt-F# console selection patch. |
Date: |
Mon, 26 Aug 2002 13:16:36 -0400 |
User-agent: |
Gnus/5.090007 (Oort Gnus v0.07) XEmacs/21.4 (Honest Recruiter, i386-unknown-gnu0.2) |
I am liking console-ncurses the more I use it, the more I am liking
it.
I have found that the multi-attach feature protects sessions between
x11 failures.
Here's a scenario:
I login start console-ncurses and start xemacs on vc1, scrollz(irc
client) on vc2.
Quit console-ncurses.
start x (xinit ..)
rxvt resize to 80x25 and attach console-ncurses.
Now i have the text sessions back.
gnuclient -display host:0
An XEmacs frame.
c-a-backspace: kill the x server (how rude!)
re attach to console-ncurses. whew wipe the sweat off, I didn't even
lose where my cursor was? :)
Nice!
Of course if xemacs kills x (I don't know yet why it wants to do this)
then all bets are off (usually xemacs dies then too. dum dum da dum
dah dah dah da da dah dum (funeral march:))
I think I have exposed some minor bug though, I notice that the text
client for xemacs moves the cursor one character forward when it does
a display-time update, but this doesn't seem to happen when running
under a normal console, so I don't know if this is an xemacs problem
or the console client problem.
And because emacs is more or less my home I wanted to ask if the
following --compatibility option would be acceptable as a patch.
Rationale: C-w is cut a region, I use this more than A-F# keys in
emacs.
Notice: For no particular reason, I have set it to allow up to 12
virtual consoles (12 function keys on the pc keyboard), these
keystrokes work in both rxvt terms and on the Hurd console, I didn't
figure out key combinations for this to work using the C-w escape
sequence.
2002-08-26 David Walter <dwalter@syr.edu>
* opts-std-startup.c: added boolean_t compatibility option for
using A-F# keys for selecting console, linux console users will
_not_ want to use this.
2002-08-26 David Walter <dwalter@syr.edu>
* console-ncurses.c: reorganized the keystroke handling and added
--compatibilty (conflicts with linux console so remote linux users
won't want to use this) option for allowing Alt-F# keystroke,
Alt-] to quit. Works under console or in an rxvt, (xterm wants a
different set of keystrokes for A-F#)
Index: opts-std-startup.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libcons/opts-std-startup.c,v
retrieving revision 1.1
diff --unified -w -i -r1.1 opts-std-startup.c
--- opts-std-startup.c 22 Aug 2002 19:24:19 -0000 1.1
+++ opts-std-startup.c 26 Aug 2002 17:02:35 -0000
@@ -36,6 +36,7 @@
/* Number of records the client is allowed to lag behind the
server. */
int _cons_slack = DEFAULT_SLACK;
+boolean_t compatibility = FALSE;
/* The filename of the console server. */
char *_cons_file;
@@ -43,6 +44,7 @@
static const struct argp_option
startup_options[] =
{
+ { "compatibility", 'c', 0, 0, "emacs compatibility"},
{ "slack", OPT_SLACK, "RECORDS", 0, "Max number of records the client is"
" allowed to lag behind the server (default " DEFAULT_SLACK_STRING ")" },
{ 0, 0 }
@@ -74,6 +76,8 @@
/* Not enough arguments. */
argp_usage (state);
break;
+
+ case 'c': compatibility = TRUE; break;
default:
return ARGP_ERR_UNKNOWN;
Index: console-ncurses.c
===================================================================
RCS file: /cvsroot/hurd/hurd/utils/console-ncurses.c,v
retrieving revision 1.1
diff --unified -w -i -r1.1 console-ncurses.c
--- console-ncurses.c 22 Aug 2002 21:33:02 -0000 1.1
+++ console-ncurses.c 26 Aug 2002 17:01:25 -0000
@@ -42,6 +42,14 @@
const char *cons_client_version = HURD_VERSION;
+extern boolean_t compatibility;
+
+#define CONSOLE_F0 ('0' - 1)
+#define CONSOLE_F(x) (CONSOLE_F0+x)
+#define ESCAPE_KEY 27
+#define CONTROL_W 23
+
+
struct curses_kc_to_cons_kc
{
int curses;
@@ -279,47 +287,91 @@
return 0;
}
-any_t
-input_loop (any_t unused)
-{
- int fd = 0;
- fd_set rfds;
- int w_escaped = 0;
-
- FD_ZERO (&rfds);
- FD_SET (fd, &rfds);
-
- while (1)
- {
- int ret;
-
- FD_SET (fd, &rfds);
-
- ret = select (fd + 1, &rfds, 0, 0, 0);
- if (ret == 1)
+void
+handle_compatible_key(int key, char*buf, int *size){
+ switch (key)
{
- char buffer[100];
- char *buf = buffer;
- size_t size = 0;
-
+ case ']':
+ endwin ();
+ exit (0);
+ break;
+ case ESCAPE_KEY: /* for the emacs command ESC ESC ESC */
+/*
+ * lose if we do something like esc a-F# -> esc esc # get left over
+ * garbage # */
+ assert (*size < 100);
+ buf[(*size)++] = key;
+ assert (*size < 100);
+ buf[(*size)++] = key;
+ break;
+/*
+ * For meta-F# console returns the following sequence ESC 79
+ * (CONSOLE_F0 + #) */
+ case 79:
+ key = getch();
+ if (key == ERR)
+ break;
+ switch(key)
+ {
+ case CONSOLE_F(1):
+ case CONSOLE_F(2):
+ case CONSOLE_F(3):
+ case CONSOLE_F(4):
+ case CONSOLE_F(5):
+ case CONSOLE_F(6):
+ case CONSOLE_F(7):
+ case CONSOLE_F(8):
+ case CONSOLE_F(9):
+ case CONSOLE_F(10):
+ case CONSOLE_F(11):
+ case CONSOLE_F(12):
+ /* Avoid a dead lock. */
+ mutex_unlock (&ncurses_lock);
+ /* XXX: We ignore any error here. */
+ cons_switch (active_vcons->cons, 2 + (key - '1'), 0);
mutex_lock (&ncurses_lock);
- while ((ret = getch ()) != ERR)
- {
- int i;
- int found;
-
- if (w_escaped)
+ break;
+ default:
+ ungetch(key);
+ break;
+ } // switch (extended key code)
+ break;
+/*
+ * For meta-F# XWindows returns the following sequence KEY_F0+# */
+ case KEY_F(1):
+ case KEY_F(2):
+ case KEY_F(3):
+ case KEY_F(4):
+ case KEY_F(5):
+ case KEY_F(6):
+ case KEY_F(7):
+ case KEY_F(8):
+ case KEY_F(9):
+ case KEY_F(10):
+ case KEY_F(11):
+ case KEY_F(12):
+ /* Avoid a dead lock. */
+ mutex_unlock (&ncurses_lock);
+ /* XXX: We ignore any error here. */
+ cons_switch (active_vcons->cons, 1 + (key - 265), 0);
+ mutex_lock (&ncurses_lock);
+ break;
+ default:
+ assert(*size < 100);
+ buf[(*size)++]=ESCAPE_KEY; /* insert escape sequence */
+ assert(*size < 100);
+ buf[(*size)++]=key;
+ }
+}
+void
+handle_console_key(int key, char*buf, int *size)
{
- switch (ret)
+ switch (key)
{
case 'x':
endwin ();
exit (0);
break;
- case 23: /* ^W */
- assert (size < 100);
- buf[size++] = ret;
- break;
case '1':
case '2':
case '3':
@@ -332,31 +384,31 @@
/* Avoid a dead lock. */
mutex_unlock (&ncurses_lock);
/* XXX: We ignore any error here. */
- cons_switch (active_vcons->cons, 1 + (ret - '1'), 0);
+ cons_switch (active_vcons->cons, 1 + (key - '1'), 0);
mutex_lock (&ncurses_lock);
break;
default:
+ assert(*size < 100);
+ buf[(*size)++] = key;
break;
}
- w_escaped = 0;
}
- else
- switch (ret)
+
+void
+handle_default_key(int key, char* buf, int *size)
{
- case 23: /* ^W */
- w_escaped = 1;
- break;
- default:
- found = 0;
+
+ int found = 0;
+ int i;
for (i =0; i < sizeof(keycodes) / sizeof(keycodes[0]); i++)
{
- if (keycodes[i].curses == ret)
+ if (keycodes[i].curses == key)
{
if (keycodes[i].cons)
{
- assert (size < 101 - strlen(keycodes[i].cons));
- strcpy (&buf[size], keycodes[i].cons);
- size += strlen (keycodes[i].cons);
+ assert (*size < 101 - strlen(keycodes[i].cons));
+ strcpy (&buf[*size], keycodes[i].cons);
+ *size += strlen (keycodes[i].cons);
}
found = 1;
break;
@@ -364,10 +416,60 @@
}
if (!found)
{
- assert (size < 100);
- buf[size++] = ret;
+ assert (*size < 100);
+ buf[(*size)++] = key;
+ }
}
+any_t
+input_loop (any_t unused)
+{
+ int fd = 0;
+ fd_set rfds;
+ boolean_t console_escape_mode = TRUE;
+
+ FD_ZERO (&rfds);
+ FD_SET (fd, &rfds);
+
+ while (1)
+ {
+ int ret;
+
+ FD_SET (fd, &rfds);
+
+ ret = select (fd + 1, &rfds, 0, 0, 0);
+
+ if (ret == 1)
+ {
+ char buffer[100];
+ char *buf = buffer;
+ size_t size = 0;
+
+ mutex_lock (&ncurses_lock);
+ while ((ret = getch ()) != ERR)
+ {
+ if (console_escape_mode)
+ {
+ if (compatibility)
+ handle_compatible_key(ret, buf, &size);
+ else
+ handle_console_key(ret, buf, &size);
+ console_escape_mode = FALSE;
+ }
+ else
+ {
+ switch(ret)
+ {
+ case CONTROL_W:
+ if (!compatibility)
+ console_escape_mode = TRUE;
break;
+ case ESCAPE_KEY:
+ if (compatibility)
+ console_escape_mode = TRUE;
+ break;
+ }
+ if (!console_escape_mode)
+ handle_default_key(ret, buf, &size);
}
}
mutex_unlock (&ncurses_lock);
--
/^\
\ / ASCII RIBBON CAMPAIGN
X AGAINST HTML MAIL
/ \
- console-ncurses discoveries / Alt-F# console selection patch.,
David Walter <=