-
Notifications
You must be signed in to change notification settings - Fork 140
Implement history command
#761
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e8d0fbf
Implement `history` command
garyhtou e240eb9
Add tests for `history` command
garyhtou 61dc0e5
Address feedback: `puts` with multiple arguments instead of `join`ing
garyhtou 214fc8a
Address feedback: Handle nil from splitting an empty input string
garyhtou 648d86d
Refactor line truncation
garyhtou ddb8acf
Add `-g` grep option to `history` command
garyhtou 1c8a67a
Add `history` command to README
garyhtou 6ebd08c
Remove unused `*args` parameter
garyhtou c48b70c
Allow spaces to be included in grep
garyhtou e3bafe0
Allow `/` to be included in grep regex
garyhtou 5b64a5b
Handle `input` being an empty string
garyhtou 9e38cb2
Exclude "#{index}: " from matching the grep regex
garyhtou f2c3d9a
Add new line after joining
garyhtou 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 hidden or 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,40 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "stringio" | ||
| require_relative "nop" | ||
| require_relative "../pager" | ||
|
|
||
| module IRB | ||
| # :stopdoc: | ||
|
|
||
| module ExtendCommand | ||
| class History < Nop | ||
| category "IRB" | ||
| description "Show the input history." | ||
|
|
||
| def execute(*) | ||
| output = StringIO.new | ||
| irb_context.io.class::HISTORY.each_with_index.reverse_each do |input, index| | ||
| header = "#{index}: " | ||
| header_length = header.size | ||
|
|
||
| lines = input.split("\n") | ||
| first_line = header + lines[0] | ||
|
|
||
| truncated_input = lines[1..1] | ||
| truncated_input << "..." if lines.size > 2 | ||
|
|
||
| truncated_input = truncated_input.map do |line| | ||
| " " * header_length + line | ||
| end | ||
|
|
||
| output.puts [first_line, *truncated_input].join("\n") | ||
garyhtou marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| Pager.page_content(output.string) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # :startdoc: | ||
| end | ||
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.