[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Windows Telnet

Once upon a time will trillich said...
> On Fri, Jan 03, 2003 at 10:12:51AM +1100, Cameron Hutchison wrote:
> > 
> > With a combination of Xt resources (translations) and control sequences,
> > I've been able to do nifty things like bind function keys to change the
> > font and resize the xterm and to change the cursor colour from the
> > prompt so that when I'm root, the cursor is red, and when not, it is the
> > same colour as the foreground text.
> care to jot down a quick "hot-to-do-that"? we'd love to learn
> about it :)

Sure, although the cursor colour stuff is only for bash. You'll need to
re-work it for tcsh.

. Setting the root cursor to red in an xterm(1)

Add the following to your bashrc. It sets the variable $col_cursor to
an escape sequence that sets the cursor colour. If you're root, the
colour will be red, otherwise a bit of trickery is done to get back the
text foreground colour and to set the cursor colour to the foreground

Then just use \[$col_cursor\] in your prompt.

You need to have this same setup stuff in roots .bashrc

Americans, please substitute color for colour :-)

--- cut here ---

# set up the prompt
if [ "${TERM}" == "xterm" ] ; then
  ESC=$(echo -ne "\E")
  CTLG=$(echo -ne "\007")
  if [ "${EUID}" = 0 ] ; then
    # set the cursor colour to be the same as the fg text.
    # the ]10;? escape sequence causes the terminal to echo back an escape
    # string to set the foreground colour to the current colour. Using sed
    # we make it change the cursor colour.
    stty -echo; echo -n "$ESC]10;?$CTLG"; read -rs -d $CTLG fg_colour; stty echo
    col_cursor=$(echo -ne "$fg_colour$CTLG" | sed 's/]10;/]12;/')
    unset fg_colour
  unset ESC CTLG

PS1="\[$col_cursor]... "

--- cut here ---

. Changing font size and resizing xterm on keypress

In your .Xresources (or .Xdefaults), add this:

--- cut here ---
#define XTERM_RESIZE_TALL       "\033[8;64;80t"
#define XTERM_RESIZE_BIG        "\033[8;41;80t"
#define XTERM_RESIZE_STD        "\033[8;25;80t"
XTerm.VT100.font4:              fixed
XTerm.VT100.font6:              10x20
XTerm.VT100*Translations:       #override \n\
       ~Shift   <Key>F7:        set-vt-font(4) interpret(XTERM_RESIZE_TALL)\n\
       ~Shift   <Key>F8:        set-vt-font(6) interpret(XTERM_RESIZE_BIG)\n\
        Shift   <Key>F7:        set-vt-font(4) interpret(XTERM_RESIZE_STD)\n\
        Shift   <Key>F8:        set-vt-font(6) interpret(XTERM_RESIZE_STD)
--- cut here ---

This sets up xterm so that when F7 is pressed, the font is set to "fixed"
(font 4), and the size to 80x64. When F8 is pressed, the font is set to
"10x20" (font 6) and the size to 80x41. Shift-F7 is fixed/80x25,
Shift-F8 is 10x20/80x25

I #define the escape sequences because I use them in multiple places,
and set them differently depending on the size of the screen. eg.
#if   (HEIGHT == 1024)
# define XTERM_RESIZE_TALL      "\033[8;64;80t"
# define XTERM_RESIZE_BIG       "\033[8;41;80t"
#elif (HEIGHT == 768)
# define XTERM_RESIZE_TALL      "\033[8;54;80t"
# define XTERM_RESIZE_BIG       "\033[8;35;80t"

. Setting up Insert to paste the selection

In your .Xresources (or .Xdefaults), add this:

--- cut here ---
XTerm.VT100*Translations:       #override \n\
                <Key>Insert:    insert-selection(PRIMARY, CUT_BUFFER0)
--- cut here ---

When you press Insert, the currently selected text is pasted. If nothing
is selected, the content of CUT_BUFFER0 are pasted.

I find this really handy as I can paste while keeping my hands on the

The contents of this post are in the public domain. You may use it in
any script or document as you see fit.

Reply to: