stdlib-js / stdlib-js/stdlib

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

Aperta
#2,071 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
difficulty: 3 Enhancement JavaScript Needs Discussion priority: Normal REPL RFC
Lingua principale
JavaScript
Stelle
6k
Fork
1.3k
Merge medio
1g 3h
PR unite (30g)
611

Descrizione

### 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:`.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.