janlelis / fancy_irb Goto Github PK
View Code? Open in Web Editor NEWColors & Hash Rockets in IRB
Home Page: https://github.com/janlelis/irbtools
License: MIT License
Colors & Hash Rockets in IRB
Home Page: https://github.com/janlelis/irbtools
License: MIT License
The default options of FancyIrb has:
:colorize => {
:input_prompt => :nothing,
:input => :nothing,
},
Which will cause a strange issue on Linux:
p "It's a very long long long long long long long long long long long long line"
Turn of input prompt colorize like this can avoid the issue.
Irbtools.replace_library_callback :fancy_irb do
FancyIrb.start :colorize => {:input_prompt => nil, :input => nil}
end
Hello, whenever you try to correct something misspelled in irb with fancy_irb active under Windows CMD/PowerShell the delete goes to a point where it stops before the prompt itself. The characters are all deleted, however the output is wrong and it is unclear what characters are actually deleted since the cursor falls back for 2-3 characters instead following properly the string.
irb(main):001:0> p "first command"
irb(main):002:0> p "second command"
Now if I press up twice to remember first command, I get this
irb(main):003:0> p "second command" first
______________________________________^
And I can only delete to here
I then have to control-C to goto a new empty line
In my .irbrc:
require 'fancy_irb'
FancyIrb.start({:colorize => {:input_prompt => [:white]}})
I am running stock irbtools. My ~/.irbrc
: https://gist.github.com/3087362. I am using the bash
shell in Terminal on Mac OS X.
FancyIrb works fine most of the time. But the #=>
is output in the wrong place when a system
command prints output. This is the problem output:
>> system 'pwd'
/Users/roryokane#=> truets/code/prepare-to-edit-Git-repo
And when irbtools is disabled:
irb(main):008:0> system 'pwd'
/Users/roryokane/Documents/code/prepare-to-edit-Git-repo
I can work around it by padding my statement with spaces at the end. It seems that the expression result is just moved one line below where it should be.
>> system 'pwd' # padded
/Users/roryokane/Documents/code/prepare-to-edit-Git-repo #=> true
More test cases:
>> system 'echo'
#=> true
>> system 'echo "line one\nline two"'
line one
line two #=> true
>> puts "line one\nline two" #=> nil
line one
line two
This is strange ... I'm working on venus a 2011 MacMini running MacOS 10.13.6 It has no Xcode installed.
15:50:03 3.2.2 venus:~ $ irb
irb(main):001> x = 1
/Users/dewayne/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fancy_irb-2.1.0/lib/fancy_irb/irb_ext.rb:3:in `output_value': wrong number of arguments (given 1, expected 0) (ArgumentError)
from /Users/dewayne/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fancy_irb-2.1.0/lib/fancy_irb/irb_ext.rb:9:in `signal_status'
from /Users/dewayne/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.8.3/exe/irb:9:in `<top (required)>'
from /Users/dewayne/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/dewayne/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
irb(main):002> exit
15:50:50 3.2.2 venus:~ $ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin17]
15:50:57 3.2.2 venus:~ $ irb --version
irb 1.8.3 (2023-10-14)
15:51:03 3.2.2 venus:~ $ gem list fancy_irb
*** LOCAL GEMS ***
fancy_irb (2.1.0)
15:51:12 3.2.2 venus:~ $
when printing a longline string, rocket prompt go wrong position.
i found one mistake on track_height, but still remain the problem...
def track_height(data)
lines = data.to_s.count("\n")
long_lines = data.to_s.split("\n").inject(0){ |sum, line| sum + (line.size / `tput cols`.to_i) }
Hello!
On Ruby 2.2.2 I get this error:
$ irb
Welcome to IRB. You are using ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]. Have fun ;)
>> "ciao"
NoMethodError: undefined method `[]' for FancyIrb:Module
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/irb-benchmark-0.1.2/lib/irb_benchmark.rb:12:in `print'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/irb-benchmark-0.1.2/lib/irb_benchmark/irb_ext.rb:11:in `evaluate'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/fancy_irb-1.0.0/lib/fancy_irb/irb_ext.rb:31:in `evaluate'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb.rb:489:in `block (2 levels) in eval_input'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb.rb:623:in `signal_status'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/fancy_irb-1.0.0/lib/fancy_irb/irb_ext.rb:19:in `signal_status'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb.rb:486:in `block in eval_input'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:245:in `block (2 levels) in each_top_level_statement'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:231:in `loop'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:231:in `block in each_top_level_statement'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:230:in `catch'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:230:in `each_top_level_statement'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb.rb:485:in `eval_input'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb.rb:395:in `block in start'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb.rb:394:in `catch'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/2.2.0/irb.rb:394:in `start'
from /home/user/.rbenv/versions/2.2.2/bin/irb:11:in `<main>'Maybe IRB bug!
This is my .irbrc:
begin
require 'irbtools/configure'
require 'irb-benchmark'
require 'bond'
Irbtools.remove_library 'boson/console' if RUBY_VERSION >= '2.2.0'
Irbtools.start
Bond.start
rescue LoadError
end
When used in Linux alpine, RbConfig::CONFIG['host_os']
is equal to "linux-musl"
When the constant TPUT
is getting set the RbConfig::CONFIG['host_os'] =~ /linux/
condition passes, attempting to run the script
command, which is not installed on alpine by default.
fancy_irb/lib/fancy_irb/terminal_info.rb
Lines 17 to 47 in 58958f5
This leaves us with an ugly error and a non-colored console, however the console still works fine.
docker-container:~/app$ bundle exec rails c
sh: script: not found
sh: script: not found
sh: script: not found
sh: script: not found
application(production)>
To install script on alpine, you must install the util-linux
package, which is very large, and we are trying to keep our docker containers sizes to a minimum.
If the following block of code is run instead when RbConfig::CONFIG['host_os'] == "linux-musl"
, it will fix this issue.
fancy_irb/lib/fancy_irb/terminal_info.rb
Lines 33 to 38 in 58958f5
When running gem rdoc fancy_irb
RDoc complains with:
RDoc failure in lib/fancy_irb.rb at or around line 89 column 31
$ rails c
Loading development environment (Rails 6.0.3.3)
0.307376 2
0.315706 2
0.321084 3
0.325803 3
Welcome to RAILS. You are using ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]. Have fun ;)
>>
From what I can tell, this is the commit that did it. c569a24
OS is Ubuntu
Is there any possibility this gem will be supported on Windows versions of ruby? I ask only because I'm stuck on Windows for work and am trying to bring Ruby in.
Specifically, in lib/fancy_irb/irb_ext.rb
, I got some errors when trying to FancyIrb.start
:
>> FancyIrb.start
#<Class:0x323c790>: No such file or directory - tput sc
from C:/Ruby187/lib/ruby/gems/1.8/gems/fancy_irb-0.6.4/lib/fancy_irb/irb_ext.rb:12:in ``'
from C:/Ruby187/lib/ruby/gems/1.8/gems/fancy_irb-0.6.4/lib/fancy_irb/irb_ext.rb:12
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/fancy_irb-0.6.4/lib/fancy_irb.rb:89:in `start'
from (irb):2:in `irb_binding'
from C:/Ruby187/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
from C:/Ruby187/lib/ruby/1.8/irb/workspace.rb:52
Maybe IRB bug!!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.