mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	[ruby/irb] Ensure stdout is a TTY before calling winsize
When outputting a (possibly truncated) value, IRB will query the
window size.  However, if IRB was piped to another process, stdout
will no longer be a TTY and will not support the `winsize` method.
This fix ensure that stdout is a TTY.
125de5eeea
			
			
This commit is contained in:
		
							parent
							
								
									846a6bb60f
								
							
						
					
					
						commit
						e0bfdb23af
					
				
					 2 changed files with 13 additions and 5 deletions
				
			
		|  | @ -39,7 +39,7 @@ module IRB | |||
|     public :gets | ||||
| 
 | ||||
|     def winsize | ||||
|       if instance_variable_defined?(:@stdout) | ||||
|       if instance_variable_defined?(:@stdout) && @stdout.tty? | ||||
|         @stdout.winsize | ||||
|       else | ||||
|         [24, 80] | ||||
|  |  | |||
|  | @ -30,10 +30,6 @@ module TestIRB | |||
|       def reset | ||||
|         @line_no = 0 | ||||
|       end | ||||
| 
 | ||||
|       def winsize | ||||
|         [10, 20] | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|     def setup | ||||
|  | @ -135,6 +131,18 @@ module TestIRB | |||
|         ], out) | ||||
|     end | ||||
| 
 | ||||
|     def test_output_to_pipe | ||||
|       input = TestInputMethod.new(["n=1"]) | ||||
|       input.instance_variable_set(:@stdout, StringIO.new) | ||||
|       irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) | ||||
|       irb.context.echo_on_assignment = :truncate | ||||
|       out, err = capture_output do | ||||
|         irb.eval_input | ||||
|       end | ||||
|       assert_empty err | ||||
|       assert_equal "=> 1\n", out | ||||
|     end | ||||
| 
 | ||||
|     def test_eval_object_without_inspect_method | ||||
|       verbose, $VERBOSE = $VERBOSE, nil | ||||
|       all_assertions do |all| | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Peter Jones
						Peter Jones