@@ -1229,6 +1229,7 @@ pub struct UCommand {
1229
1229
stderr_to_stdout : bool ,
1230
1230
timeout : Option < Duration > ,
1231
1231
terminal_simulation : bool ,
1232
+ terminal_size : Option < libc:: winsize > ,
1232
1233
tmpd : Option < Rc < TempDir > > , // drop last
1233
1234
}
1234
1235
@@ -1415,6 +1416,12 @@ impl UCommand {
1415
1416
self
1416
1417
}
1417
1418
1419
+ pub fn terminal_size ( & mut self , win_size : libc:: winsize ) -> & mut Self {
1420
+ self . terminal_simulation ( true ) ;
1421
+ self . terminal_size = Some ( win_size) ;
1422
+ self
1423
+ }
1424
+
1418
1425
#[ cfg( unix) ]
1419
1426
fn read_from_pty ( pty_fd : std:: os:: fd:: OwnedFd , out : File ) {
1420
1427
let read_file = std:: fs:: File :: from ( pty_fd) ;
@@ -1427,7 +1434,7 @@ impl UCommand {
1427
1434
Err ( e) if e. raw_os_error ( ) . unwrap_or_default ( ) == 5 => { }
1428
1435
Err ( e) => {
1429
1436
eprintln ! ( "Unexpected error: {:?}" , e) ;
1430
- assert ! ( false ) ;
1437
+ panic ! ( "error forwarding output of pty" ) ;
1431
1438
}
1432
1439
}
1433
1440
}
@@ -1600,12 +1607,12 @@ impl UCommand {
1600
1607
1601
1608
#[ cfg( unix) ]
1602
1609
if self . terminal_simulation {
1603
- let terminal_size = libc:: winsize {
1610
+ let terminal_size = self . terminal_size . unwrap_or ( libc:: winsize {
1604
1611
ws_col : 80 ,
1605
1612
ws_row : 30 ,
1606
- ws_xpixel : 800 ,
1607
- ws_ypixel : 300 ,
1608
- } ;
1613
+ ws_xpixel : 80 * 8 ,
1614
+ ws_ypixel : 30 * 10 ,
1615
+ } ) ;
1609
1616
1610
1617
let OpenptyResult {
1611
1618
slave : pi_slave,
@@ -2147,17 +2154,15 @@ impl UChild {
2147
2154
} ;
2148
2155
2149
2156
if let Some ( stdout) = self . captured_stdout . as_mut ( ) {
2150
- stdout
2151
- . reader_thread_handle
2152
- . take ( )
2153
- . map ( |handle| handle. join ( ) . unwrap ( ) ) ;
2157
+ if let Some ( handle) = stdout. reader_thread_handle . take ( ) {
2158
+ handle. join ( ) . unwrap ( ) ;
2159
+ }
2154
2160
output. stdout = stdout. output_bytes ( ) ;
2155
2161
}
2156
2162
if let Some ( stderr) = self . captured_stderr . as_mut ( ) {
2157
- stderr
2158
- . reader_thread_handle
2159
- . take ( )
2160
- . map ( |handle| handle. join ( ) . unwrap ( ) ) ;
2163
+ if let Some ( handle) = stderr. reader_thread_handle . take ( ) {
2164
+ handle. join ( ) . unwrap ( ) ;
2165
+ }
2161
2166
output. stderr = stderr. output_bytes ( ) ;
2162
2167
}
2163
2168
@@ -3597,7 +3602,33 @@ mod tests {
3597
3602
. succeeds ( ) ;
3598
3603
std:: assert_eq!(
3599
3604
String :: from_utf8_lossy( out. stdout( ) ) ,
3600
- "stdin is atty\r \n stdout is atty\r \n stderr is atty\r \n "
3605
+ "stdin is atty\r \n stdout is atty\r \n stderr is atty\r \n terminal size: 30 80\r \n "
3606
+ ) ;
3607
+ std:: assert_eq!(
3608
+ String :: from_utf8_lossy( out. stderr( ) ) ,
3609
+ "This is an error message.\r \n "
3610
+ ) ;
3611
+ }
3612
+
3613
+ #[ cfg( unix) ]
3614
+ #[ test]
3615
+ fn test_simulation_of_terminal_size_information ( ) {
3616
+ let scene = TestScenario :: new ( "util" ) ;
3617
+
3618
+ let out = scene
3619
+ . ccmd ( "env" )
3620
+ . arg ( "sh" )
3621
+ . arg ( "is_atty.sh" )
3622
+ . terminal_size ( libc:: winsize {
3623
+ ws_col : 40 ,
3624
+ ws_row : 10 ,
3625
+ ws_xpixel : 40 * 8 ,
3626
+ ws_ypixel : 10 * 10 ,
3627
+ } )
3628
+ . succeeds ( ) ;
3629
+ std:: assert_eq!(
3630
+ String :: from_utf8_lossy( out. stdout( ) ) ,
3631
+ "stdin is atty\r \n stdout is atty\r \n stderr is atty\r \n terminal size: 10 40\r \n "
3601
3632
) ;
3602
3633
std:: assert_eq!(
3603
3634
String :: from_utf8_lossy( out. stderr( ) ) ,
0 commit comments