Skip to content

Commit

Permalink
#87
Browse files Browse the repository at this point in the history
  • Loading branch information
adamyg committed Oct 21, 2024
1 parent 9927f35 commit 231b98f
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 20 deletions.
51 changes: 31 additions & 20 deletions macsrc/tty/xterm.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* -*- mode: cr; indent-width: 4; tabs: 8; -*-
* $Id: xterm.cr,v 1.30 2024/09/20 12:15:16 cvsuser Exp $
* $Id: xterm.cr,v 1.33 2024/10/20 16:51:19 cvsuser Exp $
* terminal description file for the xterm window under X11, an VT-100 like emulator.
*
*
Expand All @@ -10,19 +10,19 @@
Example 'xterm' resources allowing full keyboard access.

XTerm*font: 9x15
XTerm*appKeypadDefault: true
XTerm*appKeypadDefault: true
XTerm*scrollKey: true
Xterm*colormode: on

XTerm*VT100.Translations: #override \
~Shift<Key>Home: string(\033[1~)\n\
~Shift<Key>End: string(\033[4~)\n\
~Shift<Key>End: string(\033[4~)\n\
~Shift<Key>Prior: string(\033[5~)\n\
~Shift<Key>Next: string(\033[6~)\n\
Shift<Key>Home: scroll-back(100,page)\n\
Shift<Key>Home: scroll-back(100,page)\n\
Shift<Key>End: scroll-forw(100,page)\n\
Shift<Key>Tab: string("\033 ")\n\
~Shift<Key>Tab: string(" ")\n\
~Shift<Key>Tab: string(" ")\n\
Ctrl<Key>=: string(\033[C=)\n\
Ctrl<Key>-: string(\033[C-)\n\
Ctrl<Key>Insert: string(\033[CR0~)\n\
Expand All @@ -32,7 +32,7 @@ XTerm*VT100.Translations: #override \
Ctrl<Key>Left: string(\033[Ot)\n\
Ctrl<Key>Down: string(\033[Or)\n\
Ctrl<Key>Up: string(\033[Ox)\n\
Ctrl<Key>Right: string(\033[Ov)\n\
Ctrl<Key>Right: string(\033[Ov)\n\
Shift<Key>F1: string(\033[SF1~)\n\
Shift<Key>F2: string(\033[SF2~)\n\
Shift<Key>F3: string(\033[SF3~)\n\
Expand Down Expand Up @@ -68,16 +68,16 @@ XTerm*VT100.Translations: #override \
Meta<Key>F10: string(\033[AF10~)\n\
Meta<Key>F11: string(\033[AF11~)\n\
Meta<Key>F12: string(\033[AF12~)\n\
Shift<Key>KP_0: string(\033OP)\n\
Shift<Key>KP_1: string(\033OQ)\n\
Shift<Key>KP_2: string(\033OR)\n\
Shift<Key>KP_3: string(\033OS)\n\
Shift<Key>KP_4: string(\033OT)\n\
Shift<Key>KP_5: string(\033OU)\n\
Shift<Key>KP_6: string(\033OV)\n\
Shift<Key>KP_7: string(\033OW)\n\
Shift<Key>KP_8: string(\033OX)\n\
Shift<Key>KP_9: string(\033OY)\n\
Shift<Key>KP_0: string(\033OP)\n\
Shift<Key>KP_1: string(\033OQ)\n\
Shift<Key>KP_2: string(\033OR)\n\
Shift<Key>KP_3: string(\033OS)\n\
Shift<Key>KP_4: string(\033OT)\n\
Shift<Key>KP_5: string(\033OU)\n\
Shift<Key>KP_6: string(\033OV)\n\
Shift<Key>KP_7: string(\033OW)\n\
Shift<Key>KP_8: string(\033OX)\n\
Shift<Key>KP_9: string(\033OY)\n\
Ctrl<Key>KP_0: string(\033Op)\n\
Ctrl<Key>KP_1: string(\033Oq)\n\
Ctrl<Key>KP_2: string(\033Or)\n\
Expand Down Expand Up @@ -170,8 +170,7 @@ main(void)
xterm_arrow();
bterm = "aix";

} else if (bterm == "linux" ||
(bterm == "" && (ostype == "linux" || ostype == "linux-gnu" || sysname == "Linux"))) {
} else if (bterm == "linux") {
//
// xterm-linux or linux host.
//
Expand Down Expand Up @@ -282,8 +281,8 @@ main(void)
if (daversion == 115) { /* kconsole */
bterm = "xterm-kconsole";

} else if (daversion == 136) { /* PuTTY (mintty) */
xterm_load("xterm-mintty");
} else if (daversion == 136) { /* putty */
xterm_load("xterm-putty");
return;

} else {
Expand Down Expand Up @@ -330,6 +329,17 @@ main(void)
}
}

if (bterm == "xterm") {
if (ostype == "linux" || ostype == "linux-gnu" || sysname == "Linux") {
//
// xterm-linux or linux host.
//
xterm_locale();
xterm_load("xterm-linux");
return;
}
}

set_term_feature(TF_NAME, bterm);
xterm_graphic();

Expand Down Expand Up @@ -541,3 +551,4 @@ xterm(void)
}

/*end*/

168 changes: 168 additions & 0 deletions macsrc/tty/xterm_putty.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/* -*- mode: cr; indent-width: 4; -*- */
/* $Id: xterm_putty.cr,v 1.3 2024/10/21 14:12:08 cvsuser Exp $
* Putty terminal profile.
*
*
*
*/

#include "tty.h"
#include "tty_xterm.h"


void
main()
{
/*
* Load support functions
*/
set_term_feature(TF_NAME, "xterm-putty");
if (inq_macro("xterm_util") <= 0) {
load_macro("tty/xterm_util", FALSE);
}

/*
* Basic/common configuration
*/
xterm_standard();
xterm_graphic();
xterm_256color(); /* full 256 color is available */

xterm_altmeta_keys();

/*
* Terminal map
*
* keyboard modes:
*
* o Default mode -- labelled ESC [n~, the function keys generate sequences like ESC [11~,
* ESC [12~ and so on. This matches the general behaviour of Digital's terminals.
*
* o Linux mode -- F6 to F12 behave just like the default mode, but F1 to F5 generate ESC [[A
* through to ESC [[E. This mimics the Linux virtual console.
*
* o Xterm R6 mode --- F5 to F12 behave like the default mode, but F1 to F4 generate ESC OP
* through to ESC OS, which are the sequences produced by the top row of the keypad on Digital's
* terminals.
*
* o VT400 mode --- all the function keys behave like the default mode, but the actual top row of
* the numeric keypad generates ESC OP through to ESC OS.
*
* o VT100+ mode -- the function keys generate ESC OP through to ESC O[
*
* o SCO mode (see sco.cr) -- the function keys F1 to F12 generate ESC [M through to ESC [X. Together with
* shift, they generate ESC [Y through to ESC [j. With control they generate ESC [k through to
* ESC [v, and with shift and control together they generate ESC [w through to ESC [{
*
* o Xterm 216 mode -- the unshifted function keys behave the same as Xterm R6 mode. But pressing
* a function key together with Shift or Alt or Ctrl generates a different sequence containing
* an extra numeric parameter of the form (1 for Shift) + (2 for Alt) + (4 for Ctrl) + 1. For
* F1-F4, the basic sequences like ESC OP become ESC [1;bitmapP and similar; for F5 and above,
* ESC[index~ becomes ESC[index;bitmap~.
*
* Cursor modes:
*
* This option affects the arrow keys, if you press one with any of the modifier keys Shift, Ctrl or Alt held down.
*
* o In the default mode, labelled Ctrl toggles app mode, the Ctrl key toggles between the default arrow-key
* sequences like ESC [A and ESC [B, and the sequences Digital's terminals generate in "application cursor keys"
* mode, i.e. ESC O A and so on. Shift and Alt have no effect.
*
* o In the "xterm-style bitmap" mode, Shift, Ctrl and Alt all generate different sequences,
* with a number indicating which set of modifiers is active.
*/
set_term_keyboard(
F1_F12, quote_list( /* default */
"\x1b[11~", "\x1b[12~", "\x1b[13~", "\x1b[14~", "\x1b[15~",
"\x1b[17~", "\x1b[18~", "\x1b[19~", "\x1b[20~", "\x1b[21~",
"\x1b[23~", "\x1b[24~"),
SHIFT_F1_F12, quote_list(
"\x1b[23~", "\x1b[24~", "\x1b[25~", "\x1b[26~", "\x1b[28~",
"\x1b[29~", "\x1b[31~", "\x1b[32~", "\x1b[33~", "\x1b[34~",
NULL, NULL),
ALT_F1_F12, quote_list(
"\x1b\x1b[11~", "\x1b\x1b[12~", "\x1b\x1b[13~", "\x1b\x1b[14~", "\x1b\x1b[15~",
"\x1b\x1b[17~", "\x1b\x1b[18~", "\x1b\x1b[19~", "\x1b\x1b[20~", "\x1b\x1b[21~",
NULL, NULL),
F1_F12, quote_list( /* linux: F1..F5 */
"\x1b[[A", "\x1b[[B", "\x1b[[C", "\x1b[[D", "\x1b[[E",
NULL, NULL, NULL, NULL, NULL,
NULL, NULL),
F1_F12, quote_list( /* xterm: F1..F4 */
"\x1bOP", "\x1bOQ", "\x1bOR", "\x1bOS", NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL),
F1_F12, quote_list( /* vt100: F1..F4 */
"\x1bOP", "\x1bOQ", "\x1bOR", "\x1bOS", NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL),
SHIFT_F1_F12, quote_list( /* xterm-216: SF1..SF12 */
"\x1b[1;2P", "\x1b[1;2Q", "\x1b[1;2R", "\x1b[1;2S", "\x1b[15;2~",
"\x1b[17;2~", "\x1b[18;2~", "\x1b[19;2~", "\x1b[20;2~", "\x1b[21;2~",
"\x1b[23;2~", "\x1b[24;2~"),
CTRL_F1_F12, quote_list( /* xterm-215: CF1..CF12 */
"\x1b[1;5P", "\x1b[1;5Q", "\x1b[1;5R", "\x1b[1;5S", "\x1b[15;5~",
"\x1b[17;5~", "\x1b[18;5~", "\x1b[19;5~", "\x1b[20;5~", "\x1b[21;5~",
"\x1b[23;5~", "\x1b[24;5~"),
// Ins, End, Down, PgDn, Left,
// 5, Right, Home, Up, PgUp,
// Del, Plus, Minus, Star, Divide,
// Equals, Enter, Pause, PrtSc, Scroll,
// NumLock
//
KEYPAD_0_9, quote_list( /* default */
"\x1b[2~", "\x1b[4~", "\x1bOB", "\x1b[6~", "\x1bOD",
"\x1bOE", "\x1bOC", "\x1b[1~", "\x1bOA", "\x1b[5~",
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL),
KEYPAD_0_9, quote_list(
NULL, "\x1bOq", "\x1bOr", "\x1bOs", "\x1bOt",
"\x1bOu", "\x1bOv", "\x1bOw", "\x1bOx", "\x1bOy",
NULL, "\x1bOl", NULL, NULL, NULL,
NULL, "\x1bOM", NULL, NULL, NULL,
NULL),
CTRL_KEYPAD_0_9, quote_list( /* xterm */
NULL, NULL, "\x1b[B", NULL, "\x1b[D",
NULL, "\x1b[C", NULL, "\x1b[A", NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL),
ALT_KEYPAD_0_9, quote_list( /* xterm */
"\x1b\x1b[2~", "\x1b\x1b[4~", "\x1b\x1bOB", "\x1b\x1b[6~", "\x1b\x1bOD",
"\x1b\x1bOE", "\x1b\x1bOC", "\x1b\x1bOH", "\x1b\x1bOA", "\x1b\x1b[5~",
"\x1b\x1b[3~", NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL),
// Miscellaneous
//
BACK_TAB, "\x1b[Z",
KEY_BACKSPACE, "\x7f"
);
}
/*
* xterm-putty
*/
void
putty(void)
{
/*NOTHING*/
}
/*end*/

0 comments on commit 231b98f

Please sign in to comment.