Skip to content

textarea: support dynamic prompts#211

Merged
maaslalani merged 2 commits intocharmbracelet:masterfrom
knz:nextprompt
Sep 2, 2022
Merged

textarea: support dynamic prompts#211
maaslalani merged 2 commits intocharmbracelet:masterfrom
knz:nextprompt

Conversation

@knz
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

knz commented Aug 19, 2022

ping @maaslalani

@maaslalani
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

knz commented Aug 19, 2022

PromptFunc works for me!

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Aug 19, 2022

i'll make the change

@maaslalani
Copy link
Copy Markdown
Contributor

Thanks @knz, much appreciated!

@knz
Copy link
Copy Markdown
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
Copy Markdown
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