@@ -13,7 +13,7 @@ use log::{debug, warn};
13
13
use nix:: errno:: Errno ;
14
14
use nix:: poll:: { self , PollFlags } ;
15
15
use nix:: sys:: select:: { self , FdSet } ;
16
- use nix :: sys :: termios:: { self , SetArg , SpecialCharacterIndices as SCI , Termios } ;
16
+ use termios:: { tcsetattr , tcgetattr , Termios } ;
17
17
use nix:: unistd:: { close, isatty, read, write} ;
18
18
use unicode_segmentation:: UnicodeSegmentation ;
19
19
use utf8parse:: { Parser , Receiver } ;
@@ -106,7 +106,8 @@ pub type Mode = PosixMode;
106
106
impl RawMode for PosixMode {
107
107
/// Disable RAW mode for the terminal.
108
108
fn disable_raw_mode ( & self ) -> Result < ( ) > {
109
- termios:: tcsetattr ( self . tty_in , SetArg :: TCSADRAIN , & self . termios ) ?;
109
+ let mut termios = self . termios ;
110
+ tcgetattr ( self . tty_in , & mut termios) ?;
110
111
// disable bracketed paste
111
112
if let Some ( out) = self . tty_out {
112
113
write_all ( out, BRACKETED_PASTE_OFF ) ?;
@@ -1202,8 +1203,10 @@ impl SigWinCh {
1202
1203
}
1203
1204
}
1204
1205
1205
- fn map_key ( key_map : & mut HashMap < KeyEvent , Cmd > , raw : & Termios , index : SCI , name : & str , cmd : Cmd ) {
1206
- let cc = char:: from ( raw. control_chars [ index as usize ] ) ;
1206
+ fn map_key (
1207
+ key_map : & mut HashMap < KeyEvent , Cmd > , raw : & Termios , index : usize , name : & str , cmd : Cmd )
1208
+ {
1209
+ let cc = char:: from ( raw. c_cc [ index] ) ;
1207
1210
let key = KeyEvent :: new ( cc, M :: NONE ) ;
1208
1211
debug ! ( target: "rustyline" , "{}: {:?}" , name, key) ;
1209
1212
key_map. insert ( key, cmd) ;
@@ -1326,38 +1329,37 @@ impl Term for PosixTerminal {
1326
1329
1327
1330
fn enable_raw_mode ( & mut self ) -> Result < ( Self :: Mode , PosixKeyMap ) > {
1328
1331
use nix:: errno:: Errno :: ENOTTY ;
1329
- use nix:: sys:: termios:: { ControlFlags , InputFlags , LocalFlags } ;
1330
1332
if !self . is_in_a_tty {
1331
1333
return Err ( ENOTTY . into ( ) ) ;
1332
1334
}
1333
- let original_mode = termios :: tcgetattr ( self . tty_in ) ?;
1334
- let mut raw = original_mode. clone ( ) ;
1335
+ let original_mode = Termios :: from_fd ( self . tty_in ) ?;
1336
+ let mut raw = original_mode;
1335
1337
// disable BREAK interrupt, CR to NL conversion on input,
1336
1338
// input parity check, strip high bit (bit 8), output flow control
1337
- raw. input_flags &= !( InputFlags :: BRKINT
1338
- | InputFlags :: ICRNL
1339
- | InputFlags :: INPCK
1340
- | InputFlags :: ISTRIP
1341
- | InputFlags :: IXON ) ;
1339
+ raw. c_iflag &= !( termios :: BRKINT
1340
+ | termios :: ICRNL
1341
+ | termios :: INPCK
1342
+ | termios :: ISTRIP
1343
+ | termios :: IXON ) ;
1342
1344
// we don't want raw output, it turns newlines into straight line feeds
1343
1345
// disable all output processing
1344
1346
// raw.c_oflag = raw.c_oflag & !(OutputFlags::OPOST);
1345
1347
1346
1348
// character-size mark (8 bits)
1347
- raw. control_flags |= ControlFlags :: CS8 ;
1349
+ raw. c_cflag |= termios :: CS8 ;
1348
1350
// disable echoing, canonical mode, extended input processing and signals
1349
- raw. local_flags &=
1350
- !( LocalFlags :: ECHO | LocalFlags :: ICANON | LocalFlags :: IEXTEN | LocalFlags :: ISIG ) ;
1351
- raw. control_chars [ SCI :: VMIN as usize ] = 1 ; // One character-at-a-time input
1352
- raw. control_chars [ SCI :: VTIME as usize ] = 0 ; // with blocking read
1351
+ raw. c_lflag &=
1352
+ !( termios :: ECHO | termios :: ICANON | termios :: IEXTEN | termios :: ISIG ) ;
1353
+ raw. c_cc [ termios :: VMIN ] = 1 ; // One character-at-a-time input
1354
+ raw. c_cc [ termios :: VTIME ] = 0 ; // with blocking read
1353
1355
1354
1356
let mut key_map: HashMap < KeyEvent , Cmd > = HashMap :: with_capacity ( 4 ) ;
1355
- map_key ( & mut key_map, & raw , SCI :: VEOF , "VEOF" , Cmd :: EndOfFile ) ;
1356
- map_key ( & mut key_map, & raw , SCI :: VINTR , "VINTR" , Cmd :: Interrupt ) ;
1357
- map_key ( & mut key_map, & raw , SCI :: VQUIT , "VQUIT" , Cmd :: Interrupt ) ;
1358
- map_key ( & mut key_map, & raw , SCI :: VSUSP , "VSUSP" , Cmd :: Suspend ) ;
1357
+ map_key ( & mut key_map, & raw , termios :: VEOF , "VEOF" , Cmd :: EndOfFile ) ;
1358
+ map_key ( & mut key_map, & raw , termios :: VINTR , "VINTR" , Cmd :: Interrupt ) ;
1359
+ map_key ( & mut key_map, & raw , termios :: VQUIT , "VQUIT" , Cmd :: Interrupt ) ;
1360
+ map_key ( & mut key_map, & raw , termios :: VSUSP , "VSUSP" , Cmd :: Suspend ) ;
1359
1361
1360
- termios :: tcsetattr ( self . tty_in , SetArg :: TCSADRAIN , & raw ) ?;
1362
+ tcsetattr ( self . tty_in , termios :: TCSADRAIN , & raw ) ?;
1361
1363
1362
1364
self . raw_mode . store ( true , Ordering :: SeqCst ) ;
1363
1365
// enable bracketed paste
0 commit comments