Skip to content

Allowing displaying a prompt during incomplete validation#552

Closed
ejose19 wants to merge 1 commit intokkawakam:masterfrom
ejose19:ej/validationResultIncompleteMsg
Closed

Allowing displaying a prompt during incomplete validation#552
ejose19 wants to merge 1 commit intokkawakam:masterfrom
ejose19:ej/validationResultIncompleteMsg

Conversation

@ejose19
Copy link

@ejose19 ejose19 commented Jul 21, 2021

This change will let consumers write a custom prompt on incomplete validation result, one of the use cases is allowing REPL to display an indicator that it's expecting more input before evaluating (like node multi line displaying ... as pseudo-prompt).

Semver major due the breaking change.

@ejose19 ejose19 force-pushed the ej/validationResultIncompleteMsg branch from 0bef68d to 865d7f8 Compare July 21, 2021 02:16
@ejose19 ejose19 force-pushed the ej/validationResultIncompleteMsg branch from 865d7f8 to eb4d7f7 Compare July 21, 2021 11:55
@ejose19
Copy link
Author

ejose19 commented Jul 21, 2021

I see that:

rustyline/src/command.rs

Lines 145 to 147 in 250c9e6

| (Cmd::AcceptOrInsertLine { .. }, true, false) => {
if valid || !validation_result.has_message() {
s.edit_insert('\n', 1)?;

occurs after the layout change, so even if newline was inserted when there is a message, it won't be seen. Should this be refactored instead to be an option? (ie: incompletePrompt), as current implementation either inserts a new line or show the validation message, not both.

@ejose19 ejose19 marked this pull request as draft July 21, 2021 12:14
@ejose19 ejose19 changed the title Allow specifying a msg for ValidationResult::Incomplete Allowing displaying a prompt during incomplete validation Jul 21, 2021
@gwenn
Copy link
Collaborator

gwenn commented Jul 21, 2021

This change will let consumers write a custom prompt on incomplete validation result, ...

You mean a custom hint ?

@gwenn
Copy link
Collaborator

gwenn commented Jul 21, 2021

as current implementation either inserts a new line or show the validation message, not both.

Yep currently you can't have both.

@ejose19
Copy link
Author

ejose19 commented Jul 21, 2021

This change will let consumers write a custom prompt on incomplete validation result, ...

You mean a custom hint ?

I don't think this would clasify as a hint, since it will appear to the left of user input, and shouldn't disappear once user start typing nor when he enter more lines, ie (\n represents user triggered newlines, and ... would be the "pseudo-prompt" that appears on each incomplete line):

> {\n
... a:1\n
... }\n
{ a: 1 }
>

@gwenn
Copy link
Collaborator

gwenn commented Jul 21, 2021

I don't think this would clasify as a hint, since it will appear to the left of user input

refresh_line_with_msg is used to display a message / hint / suggestion...

@ejose19
Copy link
Author

ejose19 commented Jul 21, 2021

I don't think this would clasify as a hint, since it will appear to the left of user input

refresh_line_with_msg is used to display a message / hint / suggestion...

Yes, I've tried with that, but there's 2 issues:

  1. Input is placed in the same place as the message, given message being ... :
> \n
...
^input is placed in this column (1)
    ^ but should be placed here (5)
  1. As soon the user types something, the message disappear, but the desired behavior is for it to persist, even if new lines are added, the only time it should be removed is if the user deletes that line.

I used this to simplify testing:

ValidationResult::Incomplete(ref msg) => {
  if msg.is_some() {
    self.edit_insert('\n', 1)?;
    self.refresh_line_with_msg(msg.as_deref())?;
  }
}

EDIT: After evaluating this more thoroughly, this may not fit here since rustyline allows to go back to previous lines, and that would let users "complete" a previously incomplete line, which would render the "incomplete msg" in the next line useless.

@ejose19 ejose19 closed this Jul 21, 2021
@gwenn
Copy link
Collaborator

gwenn commented Jul 22, 2021

@ejose19
Copy link
Author

ejose19 commented Jul 22, 2021

@gwenn The only limitation I see is that both prompts must have the same width, which wouldn't apply for > & ... , but it definitely works, thanks for the link.

@ejose19 ejose19 deleted the ej/validationResultIncompleteMsg branch July 22, 2021 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants