簡潔方式,顯示波特率
sttyspeed 38400 baud; line = 0;
eol = M-^?; eol2 = M-^?; swtch = M-^?;
ixany iutf8
顯示全部設置的命令
stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
重要一點
屬性前面的減號表示被禁止
沒有減號說明使能
上面一堆在struct termios{} 中有對應位,或者對應字符,c_cc[]內為對應字符
在include/asm-i386/termbits.h中定義這個結構及相應位
struct termios {
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
};
輸入模式
c_iflag包含如下標志:
/* c_iflag bits */
#define IGNBRK 0000001
#define BRKINT 0000002
#define IGNPAR 0000004
#define PARMRK 0000010
#define INPCK 0000020
#define ISTRIP 0000040
#define INLCR 0000100
#define IGNCR 0000200
#define ICRNL 0000400
#define IUCLC 0001000
#define IXON 0002000
#define IXANY 0004000
#define IXOFF 0010000
#define IMAXBEL 0020000
#define IUTF8 0040000
brkint 中斷時發(fā)出
INTR 信號。
-brkint 中斷時不發(fā)出
INTR 信號。
icrnl 輸入時將 CR 映射為 NL。
-icrnl 輸入時不將 CR 映射為 NL。
ignbrk 輸入時忽略 BREAK。
-ignbrk 輸入時不忽略 BREAK。
igncr 輸入時忽略 CR。
-igncr 輸入時不忽略 CR。
ignpar 忽略奇偶錯誤。
-ignpar 不忽略奇偶錯誤。
inlcr 輸入時將 NL 映射為 CR。
-inlcr 輸入時不將 NL 映射為 CR。
inpck 啟用奇偶校驗。
-inpck 禁用奇偶校驗。
istrip 將輸入字符剝離到 7 位。
-istrip 不將輸入字符剝離到 7 位。
iuclc 將大寫字母字符映射為小寫。
-iuclc 不將大寫字母字符映射為小寫。
ixany 允許任何字符重新啟動輸出。
-ixany 只允許 START(Ctrl-Q 按鍵順序)重新啟動輸出。
ixoff 當輸入隊列接近空或滿時,發(fā)送 START/STOP 字符。
-ixoff 不發(fā)送 START/STOP 字符。
ixon 啟用 START/STOP 輸出控制。一旦啟用 START/STOP 輸出控制,
您可以按下 Ctrl-S 按鍵順序暫停向工作站的輸出,也可按下 Ctrl-Q 按鍵順序恢復輸出。
-ixon 禁用 START/STOP 輸出控制。
imaxbel 當輸入溢出時,回送 BEL 字符并且廢棄最后的輸入字符。
-imaxbel 當輸入溢出時,廢棄所有輸入。
parmrk 標記奇偶錯誤。
-parmrk 不標記奇偶錯誤[1]。
輸出模式
c_oflag包含如下標志:
/* c_oflag bits */
#define OPOST 0000001
#define OLCUC 0000002
#define ONLCR 0000004
#define OCRNL 0000010
#define ONOCR 0000020
#define ONLRET 0000040
#define OFILL 0000100
#define OFDEL 0000200
#define NLDLY 0000400
#define NL0 0000000
#define NL1 0000400
#define CRDLY 0003000
#define CR0 0000000
#define CR1 0001000
#define CR2 0002000
#define CR3 0003000
#define TABDLY 0014000
#define TAB0 0000000
#define TAB1 0004000
#define TAB2 0010000
#define TAB3 0014000
#define XTABS 0014000
#define BSDLY 0020000
#define BS0 0000000
#define BS1 0020000
#define VTDLY 0040000
#define VT0 0000000
#define VT1 0040000
#define FFDLY 0100000
#define FF0 0000000
#define FF1 0100000
bs0, bs1 為退格符選擇延遲樣式(bs0 表示沒有延遲)。
cr0, cr1, cr2, cr3 為 CR 字符選擇延遲樣式(cr0 表示沒有延遲)。
ff0, ff1 為換頁選擇延遲樣式(ff0 表示沒有延遲)。
nl0, nl1 為 NL 字符選擇延遲樣式(nl0 表示沒有延遲)。
ofill 使用延遲填充字符。
-ofill 使用延遲定時。
ocrnl 將 CR 字符映射為 NL 字符。
-ocrnl 不將 CR 字符映射為 NL 字符。
olcuc 輸出時將小寫字母字符映射為大寫。
-olcuc 輸出時不將小寫字母字符映射為大寫。
onlcr 將 NL 字符映射為 CR-NL 字符。
-onlcr 不將 NL 字符映射為 CR-NL 字符。
onlret 在終端 NL 執(zhí)行 CR 功能。
-onlret 在終端 NL 不執(zhí)行 CR 功能。
onocr 不在零列輸出 CR 字符。
-onocr 在零列輸出 CR 字符。
opost 處理輸出。
-opost 不處理輸出;即忽略所有其它輸出選項。
ofdel 使用 DEL 字符作為填充字符。
-ofdel 使用 NUL 字符作為填充字符。
tab0, tab1, tab2 為水平制表符選擇延遲樣式(tab0 表示沒有延遲)。
tab3 擴展制表符至多個空格。
vt0, vt1 為垂直制表符選擇延遲樣式(vt0 表示沒有延遲)[1]。
控制模式
/* c_cflag bit meaning */
#define CBAUD 0010017
#define B0 0000000 /* hang up */
#define B50 0000001
#define B75 0000002
#define B110 0000003
#define B134 0000004
#define B150 0000005
#define B200 0000006
#define B300 0000007
#define B600 0000010
#define B1200 0000011
#define B1800 0000012
#define B2400 0000013
#define B4800 0000014
#define B9600 0000015
#define B19200 0000016
#define B38400 0000017
#define EXTA B19200
#define EXTB B38400
#define CSIZE 0000060
#define CS5 0000000
#define CS6 0000020
#define CS7 0000040
#define CS8 0000060
#define CSTOPB 0000100
#define CREAD 0000200
#define PARENB 0000400
#define PARODD 0001000
#define HUPCL 0002000
#define CLOCAL 0004000
#define CBAUDEX 0010000
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
#define B460800 0010004
#define B500000 0010005
#define B576000 0010006
#define B921600 0010007
#define B1000000 0010010
#define B1152000 0010011
#define B1500000 0010012
#define B2000000 0010013
#define B2500000 0010014
#define B3000000 0010015
#define B3500000 0010016
#define B4000000 0010017
#define CIBAUD 002003600000 /* input baud rate (not used) */
#define CMSPAR 010000000000 /* mark or space (stick) parity */
#define CRTSCTS 020000000000 /* flow control */
clocal 假定一行沒有調制解調器控制。
-clocal 假定一行帶有調制解調器控制。
cread 啟用接收器。
-cread 禁用接收器。
cstopb 每個字符選擇兩個停止位。
-cstopb 每個字符選擇一個停止位。
cs5, cs6, cs7, cs8 選擇字符大小。
hup, hupcl 最后關閉時掛起撥號連接。
-hup, -hupcl 最后關閉時不掛起撥號連接。
parenb 啟用奇偶性校驗的生成和檢測。
-parenb 禁用奇偶性校驗的生成和檢測。
parodd 選擇奇校驗。
-parodd 選擇偶校驗。
0 立即掛起電話線路。
speed 將工作站輸入和輸出速度設置為指定的 speed 數(以位/秒為單位)。
并不是所有的硬件接口都支持所有的速度。
speed 的可能值有:50、75、110、134、200、300、600、1200、1800、
2400、4800、9600、19200、19.2、38400、38.4、exta 和 extb。
注:
exta、19200 和 19.2 是同義詞;extb、38400 和 38.4 是同義詞。
ispeed speed 將工作站輸入速度設置為指定的 speed 數(以位/秒為單位)。
并不是所有的硬件接口都支持所有的速度,而且并不是所有的硬件接口都支持該選項。
speed 的可能值與 speed 選項相同。
ospeed speed 將工作站輸出速度設置為指定的 speed 數(以位/秒為單位)。
并不是所有的硬件接口都支持所有的速度,而且并不是所有的硬件接口都支持該選項。
speed 的可能值與 speed 選項相同[1]。
本地模式
/* c_lflag bits */
#define ISIG 0000001
#define ICANON 0000002
#define XCASE 0000004
#define ECHO 0000010
#define ECHOE 0000020
#define ECHOK 0000040
#define ECHONL 0000100
#define NOFLSH 0000200
#define TOSTOP 0000400
#define ECHOCTL 0001000
#define ECHOPRT 0002000
#define ECHOKE 0004000
#define FLUSHO 0010000
#define PENDIN 0040000
#define IEXTEN 0100000
echo 回送每個輸入的字符。
-echo 不回送字符。
echoctl 以 ^X(Ctrl-X)回送控制字符,X 是將 100 八進制加到控制字符代碼中給出的字符。
-echoctl 不以 ^X(Ctrl-X)回送控制字符。
echoe 以“backspace space backspace”字符串回送 ERASE 字符。
注:
該模式不保持對列位置的跟蹤,因此您可能在擦除制表符和轉義序列等符號時得到意外的結果。
-echoe 不回送 ERASE 字符,只回送退格符。
echok 在 KILL 字符后回送 NL 字符。
-echok 在 KILL 字符后不回送 NL 字符。
echoke 通過擦除輸出行上的每個字符,回送 KILL 字符。
-echoke 只回送 KILL 字符。
echonl 回送 NL 字符。
-echonl 不回送 NL 字符。
echoprt 以 /(斜杠)和 \ (反斜杠) 向后回送擦除的字符。
-echoprt 不以 /(斜杠)和 \ (反斜杠) 向后回送擦除的字符。
icanon 啟用規(guī)范輸入(規(guī)范輸入允許使用 ERASE 和 KILL 字符進行輸入行的編輯)。
請參閱 AIX 5L Version 5.2 Communications Programming Concepts 中的
Line Discipline Module (ldterm) 中關于 canonical mode input 的討論。
-icanon 禁用規(guī)范輸入。
iexten 指定從輸入數據中識別實現(xiàn)性定義的功能。
要識別以下控制字符,
需要設置 iexten:eol2、dsusp、reprint、discard、werase、lnext。
與這些模式關聯(lián)的功能也需要設置 iexten:imaxbel、echoke、echoprt、echoctl。
-iexten 指定從輸入數據中識別實現(xiàn)性定義的功能。
isig 啟用對特殊控制字符(
INTR、SUSP 和 QUIT 特殊控制字符)的字符檢查。
-isig 禁用對特殊控制字符(
INTR、SUSP 和 QUIT 特殊控制字符)的字符檢查。
noflsh 不清除
INTR、SUSP 或 QUIT 控制字符之后的緩沖區(qū)。
-noflsh 清除
INTR、SUSP 或 QUIT 控制字符之后的緩沖區(qū)。
pending 下次讀操作暫掛或輸入到達時,要重新輸入從原始模式轉換為規(guī)范模式后被暫掛的輸入。
暫掛是一個內部狀態(tài)位。
-pending 沒有文本暫掛。
tostop 為背景輸出發(fā)出 SIGTOU 信號。
-tostop 不為背景輸出發(fā)出 SIGTOU 信號。
xcase 在輸入中回送大寫字符,并在輸出顯示的大寫字符之前加上 \ (反斜杠)。
-xcase 不在輸入時回送大寫字符[1]。
控制字符
/* c_cc characters */
#define VINTR 0
#define VQUIT 1
#define VERASE 2
#define VKILL 3
#define VEOF 4
#define VTIME 5
#define VMIN 6
#define VSWTC 7
#define VSTART 8
#define VSTOP 9
#define VSUSP 10
#define VEOL 11
#define VREPRINT 12
#define VDISCARD 13
#define VWERASE 14
#define VLNEXT 15
#define VEOL2 16
控制指定
要將一個控制字符指定到某字符串中,請輸入:
stty Control String
其中,Control 參數可以是
INTR、QUIT、ERASE、KILL、EOF、EOL、EOL2、START、STOP、
SUSP、DSUSP、REPRINT、DISCARD、WERASE、
LNEXT、MIN 或 TIME 參數。(使用字符 MIN 和 TIME 時,請加上 -icanon 選項。)[1]
試驗
打印出終端的行數和列數
stty size
24 80
即24行,80列
stty cols 25
把列設為25行,發(fā)現(xiàn)輸出變窄
stty -a
speed 38400 baud;
rows 24; columns 25;
line = 0;
intr = ^C; quit = ^\;
erase = ^?; kill = ^U;
eof = ^D; eol = <undef>;
eol2 = <undef>;
swtch = <undef>;
start = ^Q; stop = ^S;
susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V;
flush = ^O;
min = 1; time = 0;
-parenb -parodd cs8 hupcl
-cstopb cread -clocal
-crtscts
-ignbrk brkint ignpar
-parmrk -inpck istrip
-inlcr -igncr icrnl ixon
-ixoff -iuclc -ixany
imaxbel -iutf8
opost -olcuc -ocrnl onlcr
-onocr -onlret -ofill
-ofdel nl0 cr0 tab0 bs0
vt0 ff0
isig icanon iexten echo
echoe echok -echonl
-noflsh -xcase -tostop
-echoprt echoctl echoke
stty speed
顯示速率
stty intr c
c變?yōu)橹袛噫I,想輸入c不可能了。
stty raw
發(fā)現(xiàn)ctrl+c不管用了,輸出混亂
允許原始模式輸入(不包括輸入處理,例如 erase、kill 或 interrupt);傳回奇偶(校驗)位。
stty -raw
允許規(guī)范輸入方式。
在命令行下,禁止輸出大寫的方法
stty iuclc #開啟
stty -iuclc #恢復
在命令行下禁止輸出小寫
stty olcuc #開啟
stty -olcuc#恢復
stty sane
將參數重新設置為合理的值。
忽略回車符
stty igncr #開啟
發(fā)現(xiàn)enter不起作用了,要顯示執(zhí)行效果,需用ctrl+j
stty -igncr#恢復,要顯示執(zhí)行效果,需用ctrl+j
stty erase x
退格刪除鍵變成x,想輸入x,不可能了,因為x是退格鍵
stty erase ^?返回原來退格鍵
stty -echo
發(fā)現(xiàn)按鍵,什么也沒有出現(xiàn)
stty echo
輸入顯示
stty -icanon
關閉驅動程序中的規(guī)范模式處理,跳過緩沖層,用戶不能刪除字符,
測試一下
gui.c
#include<stdio.h>
main()
{
char c;
FILE *fp_tty;
fp_tty=fopen("/dev/tty","r");
if(fp_tty==NULL)
exit(1);
while((c=getc(fp_tty))!=EOF)
{
printf("%d",c);
}
}
gcc gui.c -o gui
stty icanon
./gui
d
10010f
10210d
10010f
10210
可以用退格鍵,并且顯示數字還得按回車鍵, 從10( enter)就可以看出來
stty -icanon
./gui
d100f102g103h104
10
關閉規(guī)范模式后發(fā)現(xiàn),按退格鍵不管用,并且直接顯示,不用按回車鍵