stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

[RFC]: add command to display command history in the REPL

Open kgryte opened this issue 1 year ago • 0 comments

Description

This RFC proposes adding support for displaying command history in the REPL. The behavior would be similar to that in IPython: https://ipython.readthedocs.io/en/stable/interactive/magics.html?highlight=magic#magic-history

Potential command signature:

history( [options] )
history( n[, options] )
history( start, stop[, options] )

with the ability to

  • print a specific number of lines n
  • print a range of lines [start, stop]

and options to

  • specify a regex to filter commands to include
  • specify a regex to filter commands to exclude
  • filter based on whether a command succeeded or failed (e.g., a success option)
  • enabling displaying prompts in the output (i.e., the -n option in IPython)
  • control the prompt display (e.g., similar to the p option in IPython, but where one can provide, say, In [%d]: to allow restarting the line numbers, which may be useful when printing REPL examples, etc)
  • include command results in the displayed output.

Related Issues

No.

Questions

  • Presumably, we could have a separate command for saving history to a file. IMO, we should separate the concerns of displaying history from saving history to a file. Whatever APIs we provide can leverage common infrastructure, but they should probably be separate user APIs, with their own set of options and concerns.
  • Including previous command results could be tricky. Maybe this is simple as moving the cursor up and then copying down, but I suspect that this could be more involved. And we cannot simply rely on inspecting the current values of workspace variables, as we'd want to capture the value of the variable at that point in history.
  • Presumably, if a user clears their command history, they shouldn't be able to display the cleared commands. But what if a user clears their terminal screen? How do we effectively capture results/outputs at the time of execution?

Other

No.

Checklist

  • [X] I have read and understood the Code of Conduct.
  • [X] Searched for existing issues and pull requests.
  • [X] The issue name begins with RFC:.

kgryte avatar Mar 27 '24 07:03 kgryte