zsh-workers
 help / color / mirror / code / Atom feed
* Keybindings lost in Xterm after top exits
@ 2012-05-30  5:40 Edgar Merino
  2012-05-30 14:58 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Edgar Merino @ 2012-05-30  5:40 UTC (permalink / raw)
  To: zsh-workers

Hello,

     I'm having a problem with ZSH/Xterm/Top whenever top runs and I 
quit the program, all my keybindings are lost, anyone else experiencing 
this?

     I mean, I've got keybindings to fix my home/end keys, also to use 
up-line-or-search/down-line-or-search with up/bottom keys, these 
keybindings are lost when I exit the "top" command line utility, and 
this happens only when using xterm.


Environment information:

OS: Archlinux
top: v3.3.2
xterm: v279
zsh: 4.3.17


Any help is greatly appreciated!
Edgar Merino


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keybindings lost in Xterm after top exits
  2012-05-30  5:40 Keybindings lost in Xterm after top exits Edgar Merino
@ 2012-05-30 14:58 ` Bart Schaefer
  2012-06-06 18:45   ` Edgar Merino
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2012-05-30 14:58 UTC (permalink / raw)
  To: Edgar Merino, zsh-workers@zsh.org 

On May 30, 12:40am, Edgar Merino wrote:
} 
}      I mean, I've got keybindings to fix my home/end keys, also to use 
} up-line-or-search/down-line-or-search with up/bottom keys, these 
} keybindings are lost when I exit the "top" command line utility, and 
} this happens only when using xterm.

This probably means that top is switching the "keypad transmit mode"
setting of the terminal and then leaving it in a different state than
when it began.  This could either be because of a bug (top sets the
state to X at startup and never restores it) or because your terminal
starts out in state X but top resets it to Y at exit anyway.

The manual page for xterm may refer to keypad transmit mode as "the
application keypad mode".  Try this:

Use ctrl-middle-button to bring up the "VT options" menu and examine
the state of the checkmarks for "enable application cursor keys" and
"enable application keypad".

Run top and exit, then look at the state of the menu again.  If those
checkmarks have changed, that's your problem.

You have a couple of choices here:

Use that menu to reset the terminal every time you run top; or

Make sure your keybindings are set the same way for both "normal mode"
and "keypad transmit mode" so zsh doesn't care what top does; or

Create a wrapper function for top that explicitly sets the mode to
the one your bindings expect, after top finishes.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keybindings lost in Xterm after top exits
  2012-05-30 14:58 ` Bart Schaefer
@ 2012-06-06 18:45   ` Edgar Merino
  2012-06-07  4:19     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Edgar Merino @ 2012-06-06 18:45 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

Thank you very much for your solution and in depth explanation of the 
problem, I had no idea how to resolve this. I did the tests you 
mentioned and indeed top was enabling both application cursor keys and 
application keybad.

I would like to wrap top within a function, however I don't know how to 
set the mode back to normal mode from a script, can you point me to any 
source where I could investigate on how to this?


Thanks in advance!

On 30/05/12 09:58, Bart Schaefer wrote:
> On May 30, 12:40am, Edgar Merino wrote:
> }
> }      I mean, I've got keybindings to fix my home/end keys, also to use
> } up-line-or-search/down-line-or-search with up/bottom keys, these
> } keybindings are lost when I exit the "top" command line utility, and
> } this happens only when using xterm.
>
> This probably means that top is switching the "keypad transmit mode"
> setting of the terminal and then leaving it in a different state than
> when it began.  This could either be because of a bug (top sets the
> state to X at startup and never restores it) or because your terminal
> starts out in state X but top resets it to Y at exit anyway.
>
> The manual page for xterm may refer to keypad transmit mode as "the
> application keypad mode".  Try this:
>
> Use ctrl-middle-button to bring up the "VT options" menu and examine
> the state of the checkmarks for "enable application cursor keys" and
> "enable application keypad".
>
> Run top and exit, then look at the state of the menu again.  If those
> checkmarks have changed, that's your problem.
>
> You have a couple of choices here:
>
> Use that menu to reset the terminal every time you run top; or
>
> Make sure your keybindings are set the same way for both "normal mode"
> and "keypad transmit mode" so zsh doesn't care what top does; or
>
> Create a wrapper function for top that explicitly sets the mode to
> the one your bindings expect, after top finishes.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keybindings lost in Xterm after top exits
  2012-06-06 18:45   ` Edgar Merino
@ 2012-06-07  4:19     ` Bart Schaefer
  2012-06-07  4:53       ` Mikael Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2012-06-07  4:19 UTC (permalink / raw)
  To: Edgar Merino; +Cc: zsh-workers

On Jun 6,  1:45pm, Edgar Merino wrote:
}
} I would like to wrap top within a function, however I don't know how to 
} set the mode back to normal mode from a script, can you point me to any 
} source where I could investigate on how to this?

It should work to do this:

    zmodload zsh/terminfo
    top() {
      command top "$@"
      print -r "${terminfo[rmkx]}"
    }

If that does not work, try

    zmodload zsh/termcap
    top() {
      command top "$@"
      print -r "${termcap[ke]}"
    }

If you get something useful from "man terminfo" you should be able to
find a description of "rmkx" there.  (Searching that man page for the
string "keypad" is how I found it.)

As a more general solution it might also work to do

    zmodload zsh/terminfo
    zle-line-init() {
      print -r "${terminfo[rmkx]}"
    }
    zle -N zle-line-init

This will force the terminal into the right keypad mode whenever the line
editor starts up, so it'll work for any command.  However, you might find
some programs that misbehave across suspend with ctrl-Z and resume with fg
if the keypad mode changes while they are stopped.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keybindings lost in Xterm after top exits
  2012-06-07  4:19     ` Bart Schaefer
@ 2012-06-07  4:53       ` Mikael Magnusson
  2012-06-07  5:15         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2012-06-07  4:53 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Edgar Merino, zsh-workers

On 7 June 2012 06:19, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Jun 6,  1:45pm, Edgar Merino wrote:
> }
> } I would like to wrap top within a function, however I don't know how to
> } set the mode back to normal mode from a script, can you point me to any
> } source where I could investigate on how to this?
>
> It should work to do this:
>
>    zmodload zsh/terminfo
>    top() {
>      command top "$@"
>      print -r "${terminfo[rmkx]}"
>    }

You probably want to either add -n to the prints, or just use echoti
rmkx instead. (echotc for the $termcap ones).

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Keybindings lost in Xterm after top exits
  2012-06-07  4:53       ` Mikael Magnusson
@ 2012-06-07  5:15         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2012-06-07  5:15 UTC (permalink / raw)
  To: zsh-workers

On Jun 7,  6:53am, Mikael Magnusson wrote:
}
} >      print -r "${terminfo[rmkx]}"
} 
} You probably want to either add -n to the prints

Er, right.  Doesn't matter much in the case of the top wrapper, but it
might for zle-line-init.

} or just use echoti rmkx instead. (echotc for the $termcap ones).

I don't know why I never think of those.  Just don't do that much with
terminal manipulation from the shell any more.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-07  5:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-30  5:40 Keybindings lost in Xterm after top exits Edgar Merino
2012-05-30 14:58 ` Bart Schaefer
2012-06-06 18:45   ` Edgar Merino
2012-06-07  4:19     ` Bart Schaefer
2012-06-07  4:53       ` Mikael Magnusson
2012-06-07  5:15         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).