-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show a quick preview of inspect result before pager launch #1040
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8cc7c6
Quickly show inspect preview even if pretty_print takes too much time
tompng 80bd464
Show a message "Inspecting..." while generating pretty_print content
tompng fbd071a
Update inspecting message
tompng c5496c5
Update rendering test for preparing inspect message
tompng 4cb7730
Don't show preview if pretty_print does not take time
tompng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: false | ||
require 'irb/pager' | ||
|
||
require_relative 'helper' | ||
|
||
module TestIRB | ||
class PagerTest < TestCase | ||
def test_take_first_page | ||
assert_equal ['a' * 40, true], IRB::Pager.take_first_page(10, 4) {|io| io.puts 'a' * 41; raise 'should not reach here' } | ||
assert_equal ['a' * 39, false], IRB::Pager.take_first_page(10, 4) {|io| io.write 'a' * 39 } | ||
assert_equal ['a' * 39 + 'b', false], IRB::Pager.take_first_page(10, 4) {|io| io.write 'a' * 39 + 'b' } | ||
assert_equal ['a' * 39 + 'b', true], IRB::Pager.take_first_page(10, 4) {|io| io.write 'a' * 39 + 'bc' } | ||
assert_equal ["a\nb\nc\nd\n", false], IRB::Pager.take_first_page(10, 4) {|io| io.write "a\nb\nc\nd\n" } | ||
assert_equal ["a\nb\nc\nd\n", true], IRB::Pager.take_first_page(10, 4) {|io| io.write "a\nb\nc\nd\ne" } | ||
assert_equal ['a' * 15 + "\n" + 'b' * 20, true], IRB::Pager.take_first_page(10, 4) {|io| io.puts 'a' * 15; io.puts 'b' * 30 } | ||
assert_equal ["\e[31mA\e[0m" * 10 + 'x' * 30, true], IRB::Pager.take_first_page(10, 4) {|io| io.puts "\e[31mA\e[0m" * 10 + 'x' * 31; } | ||
end | ||
end | ||
|
||
class PageOverflowIOTest < TestCase | ||
def test_overflow | ||
actual_events = [] | ||
overflow_callback = ->(lines) do | ||
actual_events << [:callback_called, lines] | ||
end | ||
out = IRB::Pager::PageOverflowIO.new(10, 4, overflow_callback) | ||
out.puts 'a' * 15 | ||
out.write 'b' * 15 | ||
|
||
actual_events << :before_write | ||
out.write 'c' * 1000 | ||
actual_events << :after_write | ||
|
||
out.puts 'd' * 1000 | ||
out.write 'e' * 1000 | ||
|
||
expected_events = [ | ||
:before_write, | ||
[:callback_called, ['a' * 10, 'a' * 5 + "\n", 'b' * 10, 'b' * 5 + 'c' * 5]], | ||
:after_write, | ||
] | ||
assert_equal expected_events, actual_events | ||
|
||
expected_whole_content = 'a' * 15 + "\n" + 'b' * 15 + 'c' * 1000 + 'd' * 1000 + "\n" + 'e' * 1000 | ||
assert_equal expected_whole_content, out.string | ||
end | ||
|
||
def test_callback_delay | ||
actual_events = [] | ||
overflow_callback = ->(lines) do | ||
actual_events << [:callback_called, lines] | ||
end | ||
out = IRB::Pager::PageOverflowIO.new(10, 4, overflow_callback, delay: 0.2) | ||
out.write 'a' * 1000 | ||
assert_equal ['a' * 10] * 4, out.first_page_lines | ||
out.write 'b' | ||
actual_events << :before_delay | ||
sleep 0.2 | ||
out.write 'c' | ||
actual_events << :after_delay | ||
out.write 'd' | ||
assert_equal 'a' * 1000 + 'bcd', out.string | ||
assert_equal [:before_delay, [:callback_called, ['a' * 10] * 4], :after_delay], actual_events | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: do you think pager should be part of Reline?
If we position Reline as Ruby's default terminal application utility library, it kinda makes sense for it to have a pager class too 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the basic pager should be in Reline, because it's mainly about command process names(less, more) and options(-R, -X).
The added preview part is IRB specific that we can't assume pretty_print not printing a log.
If we can assume no log while pritty-printing, there is an easy way: just stream the output to pager io.
Making a pure-ruby pager library (key handling, rendering, scrolling, etc): I think it is very interesting.