Skip to content
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

Always use rectangular prompt for multi-line input #338

Merged
merged 4 commits into from
Mar 4, 2020

Conversation

tailhook
Copy link
Contributor

This commit changes multi-line input support in the following way:

  • If there is no highlighter, the prompt is used in the first line and
    next lines are prepended by amount of spaces equal to the first line
    prompt
  • If highlighter is used, the original prompt is passed for every line
    to the highlighter, and highlighter is free to change color or
    characters of the prompt as long as its length is the same (usual
    contract for the highlighter)

Internally this changes layout object to contain cursor position
without prompt size (this should make it easier to allow non-rectangular
prompts in future).

This mostly fixes #311

I've only implemented this thing for unix terminal. I'll take a look on windows support if this general approach is fine.

This commit changes multi-line input suport in the following way:
* If there is no highlighter, the prompt is used in the first line and
  next lines are prepended by amount of spaces equal to the first line
  prompt
* If highlighter is used, the original prompt is passed for every line
  to the highlighter, and highlighter is free to change color or
  characters of othe prompt as long as it's length is the same (usual
  contract for the highlighter)

Internally this changes `layout` object to contain cursor position
without prompt size (this should make it easier to allow non-rectangular
prompts in future).

This mostly fixes kkawakam#311
@gwenn
Copy link
Collaborator

gwenn commented Feb 29, 2020

We should be able to keep the current behaviour (no continuation prompt, no space alignment).

@tailhook
Copy link
Contributor Author

tailhook commented Mar 2, 2020

Is there are good use cases for that? Or is this just for backwards compatibility?

I can do that, just not sure if it worth the complexity. In particular, how to configure that?

  1. Highlighter::has_continuation_prompt ?
  2. Editor::set_rectrangular_prompt(true) ?
  3. if highlighter.highlight_prompt(..).is_empty() ?

Another question is how cursor should work? In the master, LineUp behaves as if prompt is rectangular (i.e. it keeps cursor column relative to the text, regardless of the length of the prompt).

@gwenn
Copy link
Collaborator

gwenn commented Mar 2, 2020

As a readline alternative, we should try to keep a similar behaviour when possible.
And the screen size/resolution may be limited. Using extra space may be wasteful.

Highlighter::has_continuation_prompt seems fine.

I guess that LineUp and LineDown are the only commands that depend on the layout / number of columns. If we have a mix of long wrapped lines and short lines, we should have the same problem, no ?

@tailhook
Copy link
Contributor Author

tailhook commented Mar 2, 2020

Highlighter::has_continuation_prompt seems fine.

Okay.

I guess that LineUp and LineDown are the only commands that depend on the layout / number of columns.

Yes, as far as I understand for now. It will change if/when we have rectangular selection.

If we have a mix of long wrapped lines and short lines, we should have the same problem, no ?

Yes. Vim has two different commands to handle wrapped lines gk and gj vs k and j. But implementing those requires handling line wrapping by rustyline which isn't the case now as far as I know.


Perhaps, it's fine to keep cursor movement as the current master, and recommend using continuation prompt in case multi-line statements are frequent enough and where column structure matters (i.e. where input is something properly indented or a table).

Will update PR with has_continuation_prompt

@tailhook tailhook closed this Mar 2, 2020
@tailhook tailhook reopened this Mar 2, 2020
@gwenn
Copy link
Collaborator

gwenn commented Mar 2, 2020

I am sorry to not be more helpful right now.

@tailhook
Copy link
Contributor Author

tailhook commented Mar 3, 2020

Done. Let me know if anything else needs to be changed.

@gwenn gwenn merged commit 148e1ee into kkawakam:master Mar 4, 2020
@gwenn
Copy link
Collaborator

gwenn commented Mar 4, 2020

Thanks.

@tailhook tailhook deleted the prompt branch March 5, 2020 12:45
@gwenn gwenn mentioned this pull request Mar 28, 2020
gwenn added a commit to gwenn/rustyline that referenced this pull request Mar 29, 2020
Currently, assertions are completly buggy because of regression
introduced by kkawakam#338.
gwenn added a commit to gwenn/rustyline that referenced this pull request Apr 1, 2020
This reverts commit 148e1ee, reversing
changes made to e7bf901.
gwenn added a commit that referenced this pull request Apr 1, 2020
Revert "Merge pull request #338 from tailhook/prompt"
tailhook added a commit to tailhook/rustyline that referenced this pull request Apr 22, 2020
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
tailhook added a commit to tailhook/rustyline that referenced this pull request Apr 22, 2020
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
tailhook added a commit to tailhook/rustyline that referenced this pull request Apr 22, 2020
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
tailhook added a commit to tailhook/rustyline that referenced this pull request Apr 23, 2020
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
tailhook added a commit to tailhook/rustyline that referenced this pull request Apr 23, 2020
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
tailhook added a commit to tailhook/rustyline that referenced this pull request Jul 9, 2020
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
tailhook added a commit to tailhook/rustyline that referenced this pull request Sep 30, 2020
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
tailhook added a commit to tailhook/rustyline that referenced this pull request Apr 30, 2021
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
ayazhafiz pushed a commit to ayazhafiz/rustyline that referenced this pull request Dec 27, 2021
This is a reimplementation of kkawakam#338 which was reverted.

When `Highligher::has_continuation_prompt` returns true, rustyline
enables a special mode that passes the original prompt for every line to
the highlighter, and highlighter is free to change color or characters
of the prompt as long as it's length is the same (usual contract for the
highlighter)

Note:
1. Wrapped lines are not prefixed by prompt (this may be fixed in future
   releases either by prepending them, or by collapsing and scrolling
   lines wider than terminal).
2. Unlike kkawakam#338 this PR doesn't change the meaning of `cursor` and `end`
   fields of the `Layout` structure.
@aljazerzen aljazerzen mentioned this pull request Oct 21, 2024
3 tasks
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.

Multi-line prompts
2 participants