I have been exploring terminfo
and stty
.
If I run stty -a|grep icanon
it appears that canonical mode is set, but if I try to turn it off with stty -icanon
and check again, I see that it is still set.
When I do the same thing under bash, I am able to disable icanon, but I don't notice any change in behaviour.
So I have 2 questions; why am I unable to disable icanon in zsh, and how should it affect the behaviour if I could?
Bash – Does zsh use canonical-mode for the terminal
bashreadlineterminalzsh
Best Answer
That's because bash turns the canonical mode off when reading commands from the user (in order to be able to implement line editing features not offered by the terminal driver -- like inserting text, moving the cursor left and right with the arrow keys, etc), and then restores the previous terminal settings upon running any command line.
To see its effect, run an external command like
cat
:Each key will be repeated, once because
stty echo
is on, and once becausecat
will immediately read it and write it back, instead of having to wait for complete lines.When restoring the previous terminal settings as described above,
zsh
is also enforcing some sane defaults (which include theecho
andicanon
settings). Probably that's because it assumes that, if a command left the canonical mode off upon terminating, it was just an accident (e.g. as when a full screen app likevi
orless
crashed).I wasn't able to find any
zsh
option which would make it work likebash
(and like any other program using the readline library), but if you want to turn the icanon mode off before running a command, you can do it by calling stty from the same command line: