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

textarea: support dynamic prompts #211

Merged
merged 2 commits into from
Sep 2, 2022
Merged

Conversation

knz
Copy link
Contributor

@knz knz commented Aug 14, 2022

The secondary prompt is displayed on every line after the first.
See for example:
asciicast

Used in https://github.com/knz/bubbline

cc @maaslalani

@knz knz mentioned this pull request Aug 15, 2022
34 tasks
@knz
Copy link
Contributor Author

knz commented Aug 19, 2022

ping @maaslalani

@maaslalani
Copy link
Contributor

maaslalani commented Aug 19, 2022

Hey @knz,

This change seems very specific for line editing, the textarea bubble is meant to emulate the HTML textarea so that people are familiar with it and it is easy to understand / use.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea

I can totally see why this is useful for a line editing application.

One more generic implementation that comes to mind (not saying this is the correct approach) is to perhaps allow a PromptFunc to be defined that passes the line number and allows the prompt to be defined as a function of the line number (func (lineNumber int) string) that way it is at least a bit more generic i.e. people can implement alternating prompts for even or odd lines, or hide the prompt past line 5, or make the first and last prompts a special characters, and this next prompt logic could be implemented.

@knz
Copy link
Contributor Author

knz commented Aug 19, 2022

PromptFunc works for me!

@knz
Copy link
Contributor Author

knz commented Aug 19, 2022

i'll make the change

@maaslalani
Copy link
Contributor

Thanks @knz, much appreciated!

@knz
Copy link
Contributor Author

knz commented Aug 25, 2022

Hi @maaslalani I have changed the logic to use a dynamic prompt as you suggested!

@knz knz changed the title textarea: support secondary prompts textarea: support dynamic prompts Aug 25, 2022
knz added a commit to knz/bubbline that referenced this pull request Aug 26, 2022
@maaslalani
Copy link
Contributor

This looks absolutely fantastic @knz, thank you so much!

Another use case I just thought of for having the PromptFunc take a line number is to show diagnostics / error warnings for certain line numbers that have parse errors on them. So this change will be extremely useful for that!

@maaslalani maaslalani merged commit 09e1f00 into charmbracelet:master Sep 2, 2022
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