@@ -108,15 +108,20 @@ enum ControlCharMappingError {
108
108
MultipleChars ,
109
109
}
110
110
111
- enum SpecialSettings {
111
+ enum SpecialSetting {
112
112
Rows ( u16 ) ,
113
113
Cols ( u16 ) ,
114
114
}
115
115
116
+ enum PrintSetting {
117
+ Size ,
118
+ }
119
+
116
120
enum ArgOptions < ' a > {
117
121
Flags ( AllFlags < ' a > ) ,
118
122
Mapping ( ( SpecialCharacterIndices , u8 ) ) ,
119
- Special ( SpecialSettings ) ,
123
+ Special ( SpecialSetting ) ,
124
+ Print ( PrintSetting ) ,
120
125
}
121
126
122
127
impl < ' a > From < AllFlags < ' a > > for ArgOptions < ' a > {
@@ -289,7 +294,7 @@ fn stty(opts: &Options) -> UResult<()> {
289
294
} else if * arg == "rows" {
290
295
if let Some ( rows) = args_iter. next ( ) {
291
296
if let Some ( n) = parse_rows_cols ( rows) {
292
- valid_args. push ( ArgOptions :: Special ( SpecialSettings :: Rows ( n) ) ) ;
297
+ valid_args. push ( ArgOptions :: Special ( SpecialSetting :: Rows ( n) ) ) ;
293
298
} else {
294
299
return Err ( USimpleError :: new (
295
300
1 ,
@@ -302,7 +307,7 @@ fn stty(opts: &Options) -> UResult<()> {
302
307
} else if * arg == "columns" || * arg == "cols" {
303
308
if let Some ( cols) = args_iter. next ( ) {
<
10000
tr class="diff-line-row">304
309
if let Some ( n) = parse_rows_cols ( cols) {
305
- valid_args. push ( ArgOptions :: Special ( SpecialSettings :: Cols ( n) ) ) ;
310
+ valid_args. push ( ArgOptions :: Special ( SpecialSetting :: Cols ( n) ) ) ;
306
311
} else {
307
312
return Err ( USimpleError :: new (
308
313
1 ,
@@ -312,7 +317,9 @@ fn stty(opts: &Options) -> UResult<()> {
312
317
} else {
313
318
return Err ( USimpleError :: new ( 1 , format ! ( "missing argument to '{arg}'" ) ) ) ;
314
319
}
315
- // not a valid control char or flag
320
+ } else if * arg == "size" {
321
+ valid_args. push ( ArgOptions :: Print ( PrintSetting :: Size ) ) ;
322
+ // not a valid option
316
323
} else {
317
324
return Err ( USimpleError :: new ( 1 , format ! ( "invalid argument '{arg}'" ) ) ) ;
318
325
}
@@ -329,6 +336,9 @@ fn stty(opts: &Options) -> UResult<()> {
329
336
ArgOptions :: Special ( setting) => {
330
337
apply_special_setting ( setting, opts. file . as_raw_fd ( ) ) ?;
331
338
}
339
+ ArgOptions :: Print ( setting) => {
340
+ print_special_setting ( setting, opts. file . as_raw_fd ( ) ) ?;
341
+ }
332
342
}
333
343
}
334
344
tcsetattr (
@@ -358,6 +368,17 @@ fn check_flag_group<T>(flag: &Flag<T>, remove: bool) -> bool {
358
368
remove && flag. group . is_some ( )
359
369
}
360
370
371
+ fn print_special_setting ( setting : & PrintSetting , fd : i32 ) -> nix:: Result < ( ) > {
372
+ match setting {
373
+ PrintSetting :: Size => {
374
+ let mut size = TermSize :: default ( ) ;
375
+ unsafe { tiocgwinsz ( fd, & raw mut size) ? } ;
376
+ println ! ( "{} {}" , size. rows, size. columns) ;
377
+ }
378
+ }
379
+ Ok ( ( ) )
380
+ }
381
+
361
382
fn print_terminal_size ( termios : & Termios , opts : & Options ) -> nix:: Result < ( ) > {
362
383
let speed = cfgetospeed ( termios) ;
363
384
@@ -632,7 +653,7 @@ fn apply_char_mapping(termios: &mut Termios, mapping: &(SpecialCharacterIndices,
632
653
termios. control_chars [ mapping. 0 as usize ] = mapping. 1 ;
633
654
}
634
655
635
- fn apply_special_setting ( setting : & SpecialSettings , fd : i32 ) -> nix:: Result < ( ) > {
656
+ fn apply_special_setting ( setting : & SpecialSetting , fd : i32 ) -> nix:: Result < ( ) > {
636
657
let mut size = TermSize :: default ( ) ;
637
658
unsafe { tiocgwinsz ( fd, & raw mut size) ? } ;
638
659
match setting {
0 commit comments