This fixes an error when output is redirected:
```
$ run_ruby -rreline -e '$stderr.puts Reline::Unicode.calculate_width("\u221a").inspect' </dev/null >/dev/null
/home/jeremy/tmp/ruby/lib/reline/ansi.rb:189:in `raw': Operation not supported by device (Errno::ENODEV)
```
The @@encoding -> defined?(@@encoding) changes is necessary because
without that part of the commit, the following error would be raised
by the above command:
```
/home/jeremy/tmp/reline/lib/reline/general_io.rb:10:in `encoding': uninitialized class variable @@encoding in Reline::GeneralIO (NameError)
```
Problem reported and initial patch for Windows provided by
Richard Sharman.
I tested this only on OpenBSD, but hopefully it works for other
operating systems.
Fixes [Bug #17493]
https://github.com/ruby/reline/commit/c001971bb3
This change ensures we use `Reline::IOGate`'s `encoding` when converting
characters from their integer values.
This fixes an issue that may occur if you have UTF characters in your
`.inputrc`, but your default encoding isn't set.
For example:
```
> 127864.ord.chr
RangeError: 127864 out of char range
from (pry):1:in `chr'
> Reline::IOGate.encoding
=> #<Encoding:UTF-8>
> 127864.ord.chr(Reline::IOGate.encoding)
=> "🍸"
```
https://github.com/ruby/reline/commit/cf372fc0fc
As expressions in a gemspec file are evaluated at the build time,
but not the run time, the conditional in the gemspec will not work
as intended.
https://github.com/ruby/reline/commit/c09b7c454a
I confirmed that libvterm supports only which are UTF-8, US ASCII, UK, and
DEC graphics by reading source code, so can't test this patch by
yamatanoorogi gem through vterm gem for now.
This fixesruby/irb#190.
https://github.com/ruby/reline/commit/44596c0cc7
On Unix-like OSes, logs prior to the screen are not editable. When the code
is higher than the screen, the code is only shown on the screen until input
is finished, but when it is finished, all lines are outputted.
https://github.com/ruby/reline/commit/8cd9132a39
Because it's too slow.
The rendering time in IRB has been reduced as follows:
start = Time.now
def each_top_level_statement
initialize_input
catch(:TERM_INPUT) do
loop do
begin
prompt
unless l = lex
throw :TERM_INPUT if @line == ''
else
@line_no += l.count("\n")
next if l == "\n"
@line.concat l
if @code_block_open or @ltype or @continue or @indent > 0
next
end
end
if @line != "\n"
@line.force_encoding(@io.encoding)
yield @line, @exp_line_no
end
break if @io.eof?
@line = ''
@exp_line_no = @line_no
@indent = 0
rescue TerminateLineInput
initialize_input
prompt
end
end
end
end
puts "Duration: #{Time.now - start} seconds"
0.22sec -> 0.14sec
https://github.com/ruby/reline/commit/b8b3dd52c0
When running irb 1.2.1 (2019-12-24) with frozen-string-literal enabled, it crashes in reline with `can't modify frozen String (FrozenError)`
Steps to reproduce:
`RUBYOPT="--enable-frozen-string-literal" irb`
The rendering time in IRB has been reduced as follows:
start = Time.now
def each_top_level_statement
initialize_input
catch(:TERM_INPUT) do
loop do
begin
prompt
unless l = lex
throw :TERM_INPUT if @line == ''
else
@line_no += l.count("\n")
next if l == "\n"
@line.concat l
if @code_block_open or @ltype or @continue or @indent > 0
next
end
end
if @line != "\n"
@line.force_encoding(@io.encoding)
yield @line, @exp_line_no
end
break if @io.eof?
@line = ''
@exp_line_no = @line_no
@indent = 0
rescue TerminateLineInput
initialize_input
prompt
end
end
end
end
puts "Duration: #{Time.now - start} seconds"
0.33sec -> 0.22sec
https://github.com/ruby/reline/commit/496c6a1892
The rendering time in IRB has been reduced as follows:
start = Time.now
[{"_id"=>"5f9072a4589a06d2d74b6028",
"index"=>0,
"guid"=>"6b3051e2-dbc7-4537-bdb9-6cd7bb5358a7",
"isActive"=>true,
"balance"=>"$1,442.84",
"picture"=>"http://placehold.it/32x32",
"age"=>34,
"eyeColor"=>"blue",
"name"=>{"first"=>"Ward", "last"=>"Levy"},
"company"=>"HYPLEX",
"email"=>"ward.levy@hyplex.us",
"phone"=>"+1 (867) 568-3319",
"address"=>"867 Cobek Court, Clara, Maryland, 3254",
"about"=>
"Exercitation eu ex aliqua sit. Pariatur aliquip incididunt sint id non consectetur ullamco Lorem ea mollit duis amet sint labore. Commodo laborum labore commodo officia in cillum adipisicing esse excepteur cupidatat adipisicing ut. Non esse incididunt voluptate aliquip cillum eu aute duis laboris sit et. Amet enim quis tempor occaecat excepteur exercitation excepteur deserunt amet cillum adipisicing.",
"registered"=>"Monday, May 25, 2015 6:51 AM",
"latitude"=>"16.001127",
"longitude"=>"-72.377848",
"tags"=>["dolore", "nostrud", "occaecat", "cillum", "nisi"],
"range"=>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
"friends"=>
[{"id"=>0, "name"=>"Alison Bryant"},
{"id"=>1, "name"=>"Ester Espinoza"},
{"id"=>2, "name"=>"Sullivan Kane"}],
"greeting"=>"Hello, Ward! You have 7 unread messages.",
"favoriteFruit"=>"apple"}]
puts "Duration: #{Time.now - start} seconds"
0.47sec -> 0.34sec
start = Time.now
"Exercitation eu ex aliqua sit. Pariatur aliquip incididunt sint id non consectetur ullamco Lorem ea mollit duis amet sint labore. Commodo laborum labore commodo officia in cillum adipisicing esse excepteur cupidatat adipisicing ut. Non esse incididunt voluptate aliquip cillum eu aute duis laboris sit et. Amet enim quis tempor occaecat excepteur exercitation excepteur deserunt amet cillum adipisicing."
puts "Duration: #{Time.now - start} seconds"
0.11sec -> 0.08sec
start = Time.now
def each_top_level_statement
initialize_input
catch(:TERM_INPUT) do
loop do
begin
prompt
unless l = lex
throw :TERM_INPUT if @line == ''
else
@line_no += l.count("\n")
next if l == "\n"
@line.concat l
if @code_block_open or @ltype or @continue or @indent > 0
next
end
end
if @line != "\n"
@line.force_encoding(@io.encoding)
yield @line, @exp_line_no
end
break if @io.eof?
@line = ''
@exp_line_no = @line_no
@indent = 0
rescue TerminateLineInput
initialize_input
prompt
end
end
end
end
puts "Duration: #{Time.now - start} seconds"
0.40sec -> 0.33sec
Co-authored-by: NARUSE, Yui <naruse@airemix.jp>
https://github.com/ruby/reline/commit/a9e39ddcc4
The rendering time in IRB has been reduced as follows:
start = Time.now
[{"_id"=>"5f9072a4589a06d2d74b6028",
"index"=>0,
"guid"=>"6b3051e2-dbc7-4537-bdb9-6cd7bb5358a7",
"isActive"=>true,
"balance"=>"$1,442.84",
"picture"=>"http://placehold.it/32x32",
"age"=>34,
"eyeColor"=>"blue",
"name"=>{"first"=>"Ward", "last"=>"Levy"},
"company"=>"HYPLEX",
"email"=>"ward.levy@hyplex.us",
"phone"=>"+1 (867) 568-3319",
"address"=>"867 Cobek Court, Clara, Maryland, 3254",
"about"=>
"Exercitation eu ex aliqua sit. Pariatur aliquip incididunt sint id non consectetur ullamco Lorem ea mollit duis amet sint labore. Commodo laborum labore commodo officia in cillum adipisicing esse excepteur cupidatat adipisicing ut. Non esse incididunt voluptate aliquip cillum eu aute duis laboris sit et. Amet enim quis tempor occaecat excepteur exercitation excepteur deserunt amet cillum adipisicing.",
"registered"=>"Monday, May 25, 2015 6:51 AM",
"latitude"=>"16.001127",
"longitude"=>"-72.377848",
"tags"=>["dolore", "nostrud", "occaecat", "cillum", "nisi"],
"range"=>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
"friends"=>
[{"id"=>0, "name"=>"Alison Bryant"},
{"id"=>1, "name"=>"Ester Espinoza"},
{"id"=>2, "name"=>"Sullivan Kane"}],
"greeting"=>"Hello, Ward! You have 7 unread messages.",
"favoriteFruit"=>"apple"}]
puts "Duration: #{Time.now - start} seconds"
0.73sec -> 0.43sec
start = Time.now
"Exercitation eu ex aliqua sit. Pariatur aliquip incididunt sint id non consectetur ullamco Lorem ea mollit duis amet sint labore. Commodo laborum labore commodo officia in cillum adipisicing esse excepteur cupidatat adipisicing ut. Non esse incididunt voluptate aliquip cillum eu aute duis laboris sit et. Amet enim quis tempor occaecat excepteur exercitation excepteur deserunt amet cillum adipisicing."
puts "Duration: #{Time.now - start} seconds"
0.15sec -> 0.10sec
start = Time.now
def each_top_level_statement
initialize_input
catch(:TERM_INPUT) do
loop do
begin
prompt
unless l = lex
throw :TERM_INPUT if @line == ''
else
@line_no += l.count("\n")
next if l == "\n"
@line.concat l
if @code_block_open or @ltype or @continue or @indent > 0
next
end
end
if @line != "\n"
@line.force_encoding(@io.encoding)
yield @line, @exp_line_no
end
break if @io.eof?
@line = ''
@exp_line_no = @line_no
@indent = 0
rescue TerminateLineInput
initialize_input
prompt
end
end
end
end
puts "Duration: #{Time.now - start} seconds"
0.59sec -> 0.38sec
Co-authored-by: NARUSE, Yui <naruse@airemix.jp>
https://github.com/ruby/reline/commit/36bc9e3abb
The rendering time in IRB has been reduced as follows:
start = Time.now
[{"_id"=>"5f9072a4589a06d2d74b6028",
"index"=>0,
"guid"=>"6b3051e2-dbc7-4537-bdb9-6cd7bb5358a7",
"isActive"=>true,
"balance"=>"$1,442.84",
"picture"=>"http://placehold.it/32x32",
"age"=>34,
"eyeColor"=>"blue",
"name"=>{"first"=>"Ward", "last"=>"Levy"},
"company"=>"HYPLEX",
"email"=>"ward.levy@hyplex.us",
"phone"=>"+1 (867) 568-3319",
"address"=>"867 Cobek Court, Clara, Maryland, 3254",
"about"=>
"Exercitation eu ex aliqua sit. Pariatur aliquip incididunt sint id non consectetur ullamco Lorem ea mollit duis amet sint labore. Commodo laborum labore commodo officia in cillum adipisicing esse excepteur cupidatat adipisicing ut. Non esse incididunt voluptate aliquip cillum eu aute duis laboris sit et. Amet enim quis tempor occaecat excepteur exercitation excepteur deserunt amet cillum adipisicing.",
"registered"=>"Monday, May 25, 2015 6:51 AM",
"latitude"=>"16.001127",
"longitude"=>"-72.377848",
"tags"=>["dolore", "nostrud", "occaecat", "cillum", "nisi"],
"range"=>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
"friends"=>
[{"id"=>0, "name"=>"Alison Bryant"},
{"id"=>1, "name"=>"Ester Espinoza"},
{"id"=>2, "name"=>"Sullivan Kane"}],
"greeting"=>"Hello, Ward! You have 7 unread messages.",
"favoriteFruit"=>"apple"}]
puts "Duration: #{Time.now - start} seconds"
2.17sec -> 0.92sec
start = Time.now
"Exercitation eu ex aliqua sit. Pariatur aliquip incididunt sint id non consectetur ullamco Lorem ea mollit duis amet sint labore. Commodo laborum labore commodo officia in cillum adipisicing esse excepteur cupidatat adipisicing ut. Non esse incididunt voluptate aliquip cillum eu aute duis laboris sit et. Amet enim quis tempor occaecat excepteur exercitation excepteur deserunt amet cillum adipisicing."
puts "Duration: #{Time.now - start} seconds"
1.57sec -> 0.22sec
start = Time.now
def each_top_level_statement
initialize_input
catch(:TERM_INPUT) do
loop do
begin
prompt
unless l = lex
throw :TERM_INPUT if @line == ''
else
@line_no += l.count("\n")
next if l == "\n"
@line.concat l
if @code_block_open or @ltype or @continue or @indent > 0
next
end
end
if @line != "\n"
@line.force_encoding(@io.encoding)
yield @line, @exp_line_no
end
break if @io.eof?
@line = ''
@exp_line_no = @line_no
@indent = 0
rescue TerminateLineInput
initialize_input
prompt
end
end
end
end
puts "Duration: #{Time.now - start} seconds"
0.88sec -> 0.77sec
https://github.com/ruby/reline/commit/7d87ac5a12
IRB uses Reline's 3 dynamic real-time callbacks with calling Ripper;
output_modifier_proc, prompt_proc, and auto_indent_proc. These processing
times make the paste time too long.
https://github.com/ruby/reline/commit/beec3399a8
In the XDG Specification, if ~/.config/readline/inputrc exists, then ~/.inputrc
should not be read, but for compatibility with GNU Readline, if ~/.inputrc
exists, then it is given priority.
https://github.com/ruby/reline/commit/97f1e7db04
The previous detection per get_screen_size fails when stdout is passed
to a pipe. That is the case when running ruby tests in parallel ("-j" switch).
In this case Reline believes that it's running on MinTTY and the tests
are running with ANSI IOGate instead of the Windows adapter on MINGW.
So parallel test results were different to that of a single process.
This commit fixes these differencies.
The code is taken from git sources and translated to ruby.
NtQueryObject() is replaced by GetFileInformationByHandleEx(), because
NtQueryObject() is undocumented and is more difficult to use:
c5a03b1e29/compat/winansi.c (L558)
The command prompt on Windows always uses Unicode to take input and print
output but most Reline implementation depends on Encoding.default_external.
This commit introduces an abstracted structure about the encoding of Reline.