mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
![]() Fix issue #484 (hist --replay N isn't stored in history). First, make some small amendments to existing code: * Make helper methods of "hist" command private; * What an irony! Amend the name of the duplicated test in `test_input.rb` ("should not contain duplicated lines" test). Secondly, resolve the issue. There is one notable moment in current implementation. Although `hist --replay` calls are being stored in history, you cannot "replay" entries of this kind (you cannot replay another call request to replay). Let me show an example: [1] pry(main)> hist --show 46894 46894: hist --replay 46675..46677 [2] pry(main)> hist --show 46675..46677 46675: 1+1 46676: a = 100 46677: hist --tail [3] pry(main)> hist --replay 46894 Error: Replay index 46894 points out to another replay call: `hist -r 46675..46677` [4] pry(main)> There are two reasons for that. Reason one or my incompetence ----------------------------- First of all, I simply failed to implement such behaviour. With current state of things (that are introduced in this commit), if you do not raise `Pry::CommandError`, you cannot guarantee that only user's input is getting stored in history. Here's an example when we get unwanted entry in history: [1] pry(main)> hist --show 46894 46894: hist --replay 46675..46677 [2] pry(main)> hist --show 46675..46677 46675: 1+1 46676: a = 100 46677: hist --tail 4 [3] pry(main)> hist --replay 46894 => 2 => 100 47021: hist --show 46894 47022: hist --show 46675..46677 47023: hist --replay 46894 47024: hist --replay 46675..46677 [8] pry(main)> Note that a user typed only `hist --replay 46894`. But the last saved entry in history is the entry to which user's input, actually, pointed out (`hist --replay 46675..46677`). So if you press up-arrow key, you will get not what you expected. Reason two or "Whoa, whoa, boy! There is a real reason" ------------------------------------------------------- But the main reason is that you can fall into a loop trap, when both "hist --replay" calls point to each other. Example of a loop trap: [31] pry(main)> hist --tail 4 47027: hist --tail 47028: hist --replay 47028 47029: hist --tail 47030: hist --replay 47032 [32] pry(main)> hist -r 47030 # We've just fallen into a loop trap. Let's break out of it. ^C [416] pry(main)> hist --tail 5 47409: hist --replay 47032 47410: hist --replay 47030 47411: hist --replay 47032 47412: hist --replay 47030 47413: hist --replay 47032 [417] pry(main)> Note the number of current line (417). Finally, add some unit tests for this commit. Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com> |
||
---|---|---|
.. | ||
amend_line.rb | ||
bang.rb | ||
bang_pry.rb | ||
cat.rb | ||
cd.rb | ||
easter_eggs.rb | ||
edit.rb | ||
edit_method.rb | ||
exit.rb | ||
exit_all.rb | ||
exit_program.rb | ||
find_method.rb | ||
gem_cd.rb | ||
gem_install.rb | ||
gem_list.rb | ||
gist.rb | ||
help.rb | ||
hist.rb | ||
import_set.rb | ||
install_command.rb | ||
jump_to.rb | ||
ls.rb | ||
nesting.rb | ||
play.rb | ||
pry_backtrace.rb | ||
pry_version.rb | ||
raise_up.rb | ||
reload_method.rb | ||
reset.rb | ||
ri.rb | ||
save_file.rb | ||
shell_command.rb | ||
shell_mode.rb | ||
show_command.rb | ||
show_doc.rb | ||
show_input.rb | ||
show_source.rb | ||
simple_prompt.rb | ||
stat.rb | ||
switch_to.rb | ||
toggle_color.rb | ||
whereami.rb | ||
wtf.rb |