[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [shell-script] Console em Shell
From: |
MrBiTs |
Subject: |
RE: [shell-script] Console em Shell |
Date: |
Mon, 3 Jan 2005 09:36:42 -0200 |
<QUOTE>
Estou desenvolvendo em shell script uma console administrativa (intuitiva e
totalmente em português ) para administração de servidores linux de meus
clientes. Deparei-me com um problema que é:
Como pegar quando o usuário pressiona Ctr+C, Crt+L, Ctr+R, Ctr+D, Seta para
Cima, Seta para Baixo, etc ...
</QUOTE>
Olas
Muito boa duvida. O Advanced Bash Scripting Guide, em sua pagina 209, tem o
seguinte exemplo, utilizado para demonstrar a versatilidade do "dd":
#!/bin/bash
# Capture keystrokes without needing to press ENTER.
keypresses=4 # Number of keypresses to capture.
old_tty_setting=$(stty −g) # Save old terminal settings.
echo "Press $keypresses keys."
stty −icanon −echo # Disable canonical mode.
# Disable local echo.
keys=$(dd bs=1 count=$keypresses 2> /dev/null)
# 'dd' uses stdin, if "if" not specified.
stty "$old_tty_setting" # Restore old terminal settings.
echo "You pressed the \"$keys\" keys."
# Thanks, S.C. for showing the way.
exit 0
Entretanto, acho que para o que vc quer, o bash tem um builtin chamado bind (
nao confundir com BIND, que é o servidor de nomes padrao ), que dá ao usuario a
possibilidade de tratar pressionamentos de teclas ( entre outra duzia de
tratamentos ). Seu man é assim:
bind
bind [-m keymap] [-lpsvPSV]
bind [-m keymap] [-q function] [-u function] [-r keyseq]
bind [-m keymap] -f filename
bind [-m keymap] -x keyseq:shell-command
bind [-m keymap] keyseq:function-name
bind readline-command
Display current Readline (see section 8. Command Line Editing) key and function
bindings, bind a key sequence to a Readline function or macro, or set a
Readline variable. Each non-option argument is a command as it would appear in
a a Readline initialization file (see section 8.3 Readline Init File), but each
binding or command must be passed as a separate argument; e.g.,
`"\C-x\C-r":re-read-init-file'. Options, if supplied, have the following
meanings:
-m keymap
Use keymap as the keymap to be affected by the subsequent bindings. Acceptable
keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
vi-command, and vi-insert. vi is equivalent to vi-command; emacs is equivalent
to emacs-standard.
-l
List the names of all Readline functions.
-p
Display Readline function names and bindings in such a way that they can be
used as input or in a Readline initialization file.
-P
List current Readline function names and bindings.
-v
Display Readline variable names and values in such a way that they can be used
as input or in a Readline initialization file.
-V
List current Readline variable names and values.
-s
Display Readline key sequences bound to macros and the strings they output in
such a way that they can be used as input or in a Readline initialization file.
-S
Display Readline key sequences bound to macros and the strings they output.
-f filename
Read key bindings from filename.
-q function
Query about which keys invoke the named function.
-u function
Unbind all keys bound to the named function.
-r keyseq
Remove any current binding for keyseq.
-x keyseq:shell-command
Cause shell-command to be executed whenever keyseq is entered.
The return status is zero unless an invalid option is supplied or an error
occurs.
Esse pode ser um caminho inicial para voce.
- Console em Shell, Felipe Chaves, 2005/01/03
- RE: [shell-script] Console em Shell,
MrBiTs <=