- Subject: Re: [slang-users] Reconstructing the last key sequence
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Wed, 3 Mar 2004 10:50:16 -0500
Thomas Schultz <tststs@xxxxxx> wrote:
>One drawback of the approach I'm considering would be that each lookup
>involves a number of string comparisons; but I expect that I will not use
>it so extensively that the cost of this becomes a problem. Of course, I'm
>happy to hear about better suggestions.
When you say lookup, do you mean finding the key that produced the
escape sequence? If so, have you considered using something like an
associative array? For example, jed's keydefs contains a number of
declarations such as
variable Key_F1 = setkey_via_terminfo ("k1","^[[11~");
You might want to change this to:
create_key ("Key_F1", "k1", "^[[11~");
where create_key is something like:
static variable Reverse_Map = Assoc_Type[String_Type];
static define create_key (key_name, tcap, key_sequence)
{
key_sequence = setkey_via_terminfo (tcap, key_sequence);
eval (sprintf ("public variable %s = \"%s\";", key_name, key_sequence));
Reverse_Map[key_sequence] = key_name;
}
Then it is easy to create a function that returns the keyname given
the sequence, e.g.,
define lookup_keyname (key_sequence)
{
if (assoc_key_exists (Reverse_Map, key_sequence))
return Reverse_Map[key_sequence];
return key_sequence;
}
You may have to map a key sequence to a canonical form, e.g., replace
the two characters "^[" by a literal escape character.
I hope this helps.
Thanks,
--John
_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html
[2004 date index]
[2004 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]