@@ -15,11 +15,11 @@ use nix::sys::termios::{
1515} ;
1616use nix:: { ioctl_read_bad, ioctl_write_ptr_bad} ;
1717use std:: fs:: File ;
18- use std:: io:: { self , Stdout , stdout } ;
18+ use std:: io:: Result ;
1919use std:: ops:: ControlFlow ;
20- use std:: os:: fd:: { AsFd , BorrowedFd } ;
20+ use std:: os:: fd:: AsFd ;
2121use std:: os:: unix:: fs:: OpenOptionsExt ;
22- use std:: os:: unix:: io:: { AsRawFd , RawFd } ;
22+ use std:: os:: unix:: io:: AsRawFd ;
2323use uucore:: error:: { UResult , USimpleError } ;
2424use uucore:: { format_usage, help_about, help_usage} ;
2525
@@ -94,35 +94,12 @@ mod options {
9494struct Options < ' a > {
9595 all : bool ,
9696 save : bool ,
97- file : Device ,
97+ file : File ,
9898 settings : Option < Vec < & ' a str > > ,
9999}
100100
101- enum Device {
102- File ( File ) ,
103- Stdout ( Stdout ) ,
104- }
105-
106- impl AsFd for Device {
107- fn as_fd ( & self ) -> BorrowedFd < ' _ > {
108- match self {
109- Self :: File ( f) => f. as_fd ( ) ,
110- Self :: Stdout ( stdout) => stdout. as_fd ( ) ,
111- }
112- }
113- }
114-
115- impl AsRawFd for Device {
116- fn as_raw_fd ( & self ) -> RawFd {
117- match self {
118- Self :: File ( f) => f. as_raw_fd ( ) ,
119- Self :: Stdout ( stdout) => stdout. as_raw_fd ( ) ,
120- }
121- }
122- }
123-
124101impl < ' a > Options < ' a > {
125- fn from ( matches : & ' a ArgMatches ) -> io :: Result < Self > {
102+ fn from ( matches : & ' a ArgMatches ) -> Result < Self > {
126103 Ok ( Self {
127104 all : matches. get_flag ( options:: ALL ) ,
128105 save : matches. get_flag ( options:: SAVE ) ,
@@ -136,13 +113,14 @@ impl<'a> Options<'a> {
136113 // will clean up the FD for us on exit, so it doesn't
137114 // matter. The alternative would be to have an enum of
138115 // BorrowedFd/OwnedFd to handle both cases.
139- Some ( f) => Device :: File (
140- std:: fs:: OpenOptions :: new ( )
141- . read ( true )
142- . custom_flags ( O_NONBLOCK )
143- . open ( f) ?,
144- ) ,
145- None => Device :: Stdout ( stdout ( ) ) ,
116+ Some ( f) => std:: fs:: OpenOptions :: new ( )
117+ . read ( true )
118+ . custom_flags ( O_NONBLOCK )
119+ . open ( f) ?,
120+ None => std:: fs:: OpenOptions :: new ( )
121+ . read ( true )
122+ . custom_flags ( O_NONBLOCK )
123+ . open ( "/dev/tty" ) ?,
146124 } ,
147125 settings : matches
148126 . get_many :: < String > ( options:: SETTINGS )
0 commit comments