Skip to content

feat: add better prompt marker in REPL's multi-line mode #1818

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/node_modules/@stdlib/repl/lib/display_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ var repeat = require( '@stdlib/string/repeat' );
var leadingWhitespaceRegExp = require( './regexp_leading_whitespace.js' );


// VARIABLES //

var BASE_PROMPT = '...: ';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this work when a user provides a custom prompt? This assumes that the prompt is of the form In [%d]:, but that is not necessarily the case. See https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/repl#repl-options-.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g., the prompt could be changed to > or $ or something else entirely. In which case, this implementation is making an assumption about the form of the prompt which is not guaranteed to be true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I messed up there. One solution can be, the prompt can just consist of spaces/dots the length of the input prompt, the lines would still align , there would be no ...: in the prompt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgryte something like this:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this returns us to whether a continuation prompt is necessary. For example, if we support SHIFT+ENTER or some other modifier, then

In [5]:
function func() {
	console.log( 'hello world' );
}

should be possible which achieves alignment, without requiring special prompt handling or the loss of terminal columns with unused whitespace. For the latter in particular, while some terminal applications are good in handling text overflow, others are not, thus making horizontal real estate something of a precious commodity. If we followed IPython and provided a continuation prompt which indents based on the parent prompt, we limit full use of all possible real estate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.. I'll close this issue and PR👍



// MAIN //

/**
Expand All @@ -50,7 +55,7 @@ function displayPrompt( repl, preserveCursor ) {
repl._rli.prompt( preserveCursor );
return;
}
repl._rli.setPrompt( '' );
repl._rli.setPrompt( repeat( ' ', 2 + String( repl._count ).length ) + BASE_PROMPT );
repl._rli.prompt( preserveCursor );

// Prepend the leading whitespace of the previous line:
Expand Down