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

Unexpected history when using single vs multi arrow ups #827

Closed
ngty opened this Issue Jan 25, 2013 · 7 comments

Comments

Projects
None yet
3 participants
@ngty

ngty commented Jan 25, 2013

While playing w pry, i've observed that the pry history doesn't show the expected entries when single arrow up is applied, vs multi arrow ups:

Without any arrow up:

$ a = 1
$ b = 2
$ Pry.history.to_a[- 10 .. -1]
=> [(hidden),
  "a = 1",
  "b = 2",
  "Pry.history.to_a[- 10 .. -1]"]

With 1 arrow up (note that "b = 2" only appears once, should not it be twice ?):

$ a = 1
$ b = 2
OA
$ Pry.history.to_a[- 10 .. -1]
=> [(hidden),
  "a = 1",
  "b = 2",
  "Pry.history.to_a[- 10 .. -1]"]

With 2 arrows up (note that "a = 2" appears twice):

$ a = 1
$ b = 2
OAOA
$ Pry.history.to_a[- 10 .. -1]
=> [(hidden),
  "a = 1",
  "b = 2",
  "a = 1",
  "Pry.history.to_a[- 10 .. -1]"]
@kyrylo

This comment has been minimized.

Show comment
Hide comment
@kyrylo

kyrylo Jan 25, 2013

Member

Could you record a showterm? I don't follow your description.

% gem install showterm
% showterm pry
Member

kyrylo commented Jan 25, 2013

Could you record a showterm? I don't follow your description.

% gem install showterm
% showterm pry
@rf-

This comment has been minimized.

Show comment
Hide comment
@rf-

rf- Jan 25, 2013

Member

Pry deliberately doesn't record duplicated lines into history. From skimming the linked issue, it sounds like you might be interested in _in_ (also accessible as _pry_.input_array or by running cat -i).

Member

rf- commented Jan 25, 2013

Pry deliberately doesn't record duplicated lines into history. From skimming the linked issue, it sounds like you might be interested in _in_ (also accessible as _pry_.input_array or by running cat -i).

@rf-

This comment has been minimized.

Show comment
Hide comment
@rf-

rf- Jan 25, 2013

Member

Oh, now that I've actually read it, I think what you really want is just to use Pry.line_buffer instead of the history. Every source_location that refers to (pry) will have a corresponding entry in line_buffer (which is how Pry itself shows source for methods defined in the REPL), and it doesn't omit duplicates.

Member

rf- commented Jan 25, 2013

Oh, now that I've actually read it, I think what you really want is just to use Pry.line_buffer instead of the history. Every source_location that refers to (pry) will have a corresponding entry in line_buffer (which is how Pry itself shows source for methods defined in the REPL), and it doesn't omit duplicates.

@ngty

This comment has been minimized.

Show comment
Hide comment
@ngty

ngty Jan 26, 2013

@rf- thank you for the pointer.

I've tried Pry.line_buffer & it works great. Except for the case when i need to access the latest line in the buffer. Using the simpliest example i can think of:

[1] pry(main)> a = 1
=> 1
[2] pry(main)> p Pry.line_buffer
["", "a = 1\n"]
=> ["", "a = 1\n", "p Pry.line_buffer\n"]

The last line => ["", "a = 1\n", "p Pry.line_buffer\n"] is exactly what i was hoping to see, yet, i don't understand why there is an intermediate ["", "a = 1\n"].

Any thoughts ?

ngty commented Jan 26, 2013

@rf- thank you for the pointer.

I've tried Pry.line_buffer & it works great. Except for the case when i need to access the latest line in the buffer. Using the simpliest example i can think of:

[1] pry(main)> a = 1
=> 1
[2] pry(main)> p Pry.line_buffer
["", "a = 1\n"]
=> ["", "a = 1\n", "p Pry.line_buffer\n"]

The last line => ["", "a = 1\n", "p Pry.line_buffer\n"] is exactly what i was hoping to see, yet, i don't understand why there is an intermediate ["", "a = 1\n"].

Any thoughts ?

@ngty

This comment has been minimized.

Show comment
Hide comment
@ngty

ngty Jan 26, 2013

@kyrylo thanks for mentioning showterm, here's one for the original history problem ~ http://showterm.io/0de4ef82c38744da6c2dc#fast

ngty commented Jan 26, 2013

@kyrylo thanks for mentioning showterm, here's one for the original history problem ~ http://showterm.io/0de4ef82c38744da6c2dc#fast

@ngty

This comment has been minimized.

Show comment
Hide comment
@ngty

ngty Jan 26, 2013

I finally resorted to doing:

lines = [Pry.line_buffer, Pry.history.to_a[-1]].flatten

to reliably obtain all the lines in the current pry session, up till the last line entered.

ngty commented Jan 26, 2013

I finally resorted to doing:

lines = [Pry.line_buffer, Pry.history.to_a[-1]].flatten

to reliably obtain all the lines in the current pry session, up till the last line entered.

@kyrylo kyrylo closed this Jan 26, 2013

@kyrylo kyrylo reopened this Jan 26, 2013

@ngty

This comment has been minimized.

Show comment
Hide comment
@ngty

ngty Jan 27, 2013

Closing this issue as it should now be Pry.line_buffer related, see #830

ngty commented Jan 27, 2013

Closing this issue as it should now be Pry.line_buffer related, see #830

@ngty ngty closed this Jan 27, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment