📄 term.c
字号:
#ifndef lintstatic const char rcsid[] = "$Id: term.c,v 1.1.1.1 2001/03/08 00:01:47 efalk Exp $" ;#endif/* Terminal I/O control. * * characters are buffered between ports. There may be times when * writes to a port would fail because the port is not ready to accept * more data, or has asserted flow control. If the buffers fill, * serialmon will stop reading data until conditions improve. */#include <stdio.h>#include <string.h>#include <stdlib.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <termcap.h>#include <sys/termios.h>#include <sys/types.h>#include <sys/uio.h>#include <sys/time.h>#include "gcomm.h"static struct termios old_settings ;static int old_fcntl0 ;static char termcap_buf[1024] ;static char *getTermStr() ;extern char *tgetstr() ; char *setInverse = "" ; char *setNormal = "" ; char *clearScreen = "" ;voidTermInfo(){ int j ; if( tcgetattr(0, &old_settings) < 0 ) { perror("TermInfo: tcgetattr") ; } old_fcntl0 = fcntl(0, F_GETFL, 0) ; /* Set non-blocking I/O */ j = fcntl(0, F_SETFL, old_fcntl0|O_NDELAY) ; if( tgetent(termcap_buf, getenv("TERM")) != -1 ) { clearScreen = getTermStr("cl") ; setInverse = getTermStr("so") ; setNormal = getTermStr("se") ; } else /* punt */ { clearScreen = "\f" ; setInverse = "" ; setNormal = "" ; }}static char *getTermStr(name) char *name ;{ char buffer[1024] ; char *rval, *ptr = buffer ; rval = tgetstr(name, &ptr) ; return rval != NULL ? strdup(rval) : "" ;}intTermInit(){ struct termios new ; /* set terminal as transparent as we can */ /* TODO: local ^S/^Q? */ new = old_settings ; new.c_iflag &= ~(ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF) ; new.c_lflag = localEcho ? ECHO : 0 ; new.c_cc[VMIN] = 16 ; new.c_cc[VTIME] = 1 ; if( tcsetattr(0, TCSADRAIN, &new) < 0 ) { perror("TermInit: tcsetattr") ; return -1 ; } return 0 ;} /* set local echo */voidTermEcho(){ struct termios new ; if( tcgetattr(0, &new) < 0 ) { perror("TermInit: tcgetattr") ; return ; } new.c_lflag = localEcho ? ECHO : 0 ; if( tcsetattr(0, TCSADRAIN, &new) < 0 ) { perror("TermInit: tcsetattr") ; }} /* put terminal in normal mode after disconnect */intTermTerm(){ if( tcsetattr(0, TCSADRAIN, &old_settings) < 0 ) perror("TermTerm: tcsetattr") ; if( tcsetattr(1, TCSADRAIN, &old_settings) < 0 ) perror("TermTerm: tcsetattr") ; return 0 ;}voidTermExit(){ int j ; TermTerm() ; j = fcntl(0, F_SETFL, old_fcntl0) ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -