stdlib-js / stdlib-js/stdlib

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

Open
#2,071 0 comments 0 reactions 0 assignees View on GitHub
difficulty: 3 Enhancement JavaScript Needs Discussion priority: Normal REPL RFC
Dominant language
JavaScript
Stars
6k
Forks
1.3k
Avg merge
1d 3h
Merged PRs (30d)
611

Description

### 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](https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md).
- [X] Searched for existing issues and pull requests.
- [X] The issue name begins with `RFC:`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.