pry--pry/lib/pry
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
..
commands Store `hist --replay <i>` calls in history 2012-08-23 02:27:02 +03:00
helpers Depracated show-command and moved its functionality to show-source 2012-08-14 00:18:53 -04:00
cli.rb Improve `-I` option support 2012-08-16 03:05:34 +03:00
code.rb Remember the initial pwd [Fixes #675] 2012-08-12 22:58:40 -07:00
command.rb Bond completion includes commands 2012-08-20 23:57:51 -07:00
command_set.rb Bond completion includes commands 2012-08-20 23:57:51 -07:00
commands.rb Remove extended_commands, default_commands -> commands 2012-08-11 17:39:25 -07:00
completion.rb Bond completion includes commands 2012-08-20 23:57:51 -07:00
config.rb Add Bond completion (when available) cirwin++ 2012-08-18 22:49:20 +00:00
core_extensions.rb Fixed typo in a comment 2012-07-22 23:48:04 +02:00
custom_completions.rb added file-mode toggle command, brings in filesystem completion and 2011-04-07 05:38:18 +12:00
helpers.rb Move all commands into individual files 2012-08-11 17:33:37 -07:00
history.rb passing extra prompt data via an OpenStruct 2012-07-13 02:53:19 +12:00
history_array.rb implement cat --in (fixes #330) 2011-11-06 01:00:37 -07:00
hooks.rb Fix various mangled documentation 2012-06-26 22:30:00 -07:00
indent.rb Add Module.nesting extraction to Pry::Indent 2012-07-28 14:31:20 -07:00
method.rb Fix various mangled documentation 2012-06-26 22:30:00 -07:00
module_candidate.rb Fix warnings 2012-07-01 23:10:50 -07:00
pager.rb Add API documentation. 2012-08-09 22:52:13 +01:00
plugins.rb Removed double trailing new-lines (really just because it's done automatically) 2012-07-22 23:30:40 +02:00
pry_class.rb Don't load ./.pryrc when it is ~/.pryrc [Fixes #682] 2012-08-05 12:05:35 -07:00
pry_instance.rb Store `hist --replay <i>` calls in history 2012-08-23 02:27:02 +03:00
rbx_method.rb define a Pry::Method#source_location, fixes #524 2012-04-13 18:39:04 +12:00
rbx_path.rb Workaround for rubinius binding __FILE__ bug #1581 2012-03-02 04:02:51 +13:00
repl_file_loader.rb provide CLI 'pry my_file.rb' functionality to load file through REPL loop 2012-06-20 02:10:18 +12:00
version.rb version 0.9.10 release 2012-07-15 00:00:50 +12:00
wrapped_module.rb Change wrapped method to public 2012-07-22 22:26:19 -04:00