pry--pry/lib/pry/commands
Kyrylo Silin 704cc6e859 Store `hist --replay <i>` calls in history
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>
2012-08-23 02:27:02 +03:00
..
amend_line.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
bang.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
bang_pry.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
cat.rb filename completion for cat and shell 2012-08-21 00:44:26 -07:00
cd.rb Revert "Revert "Merge pull request #678 from jasonLaster/tabcomplete"" 2012-08-12 00:38:44 -04:00
easter_eggs.rb Remove extended_commands, default_commands -> commands 2012-08-11 17:39:25 -07:00
edit.rb Bond completion includes commands 2012-08-20 23:57:51 -07:00
edit_method.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
exit.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
exit_all.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
exit_program.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
find_method.rb Remove extended_commands, default_commands -> commands 2012-08-11 17:39:25 -07:00
gem_cd.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
gem_install.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
gem_list.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
gist.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
help.rb Remove extended_commands, default_commands -> commands 2012-08-11 17:39:25 -07:00
hist.rb Store `hist --replay <i>` calls in history 2012-08-23 02:27:02 +03:00
import_set.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
install_command.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
jump_to.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
ls.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
nesting.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
play.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
pry_backtrace.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
pry_version.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
raise_up.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
reload_method.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
reset.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
ri.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
save_file.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
shell_command.rb filename completion for cat and shell 2012-08-21 00:44:26 -07:00
shell_mode.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
show_command.rb DEPRACTED --> DEPRECATED 2012-08-19 12:32:10 +12:00
show_doc.rb Depracated show-command and moved its functionality to show-source 2012-08-14 00:18:53 -04:00
show_input.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
show_source.rb Depracated show-command and moved its functionality to show-source 2012-08-14 00:18:53 -04:00
simple_prompt.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
stat.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
switch_to.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
toggle_color.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00
whereami.rb Remove extended_commands, default_commands -> commands 2012-08-11 17:39:25 -07:00
wtf.rb Restore groups, convert most commands to class syntax 2012-08-11 18:27:26 -07:00