Skip to content

Commit

Permalink
feat: improve user input handling and feedback mechanisms (#203)
Browse files Browse the repository at this point in the history
- Add detailed comments for the `initialPrompt` function
- Adjust character limit for the textarea based on the input value
- Dynamically set the width of the textarea based on the longest line in the input value
- Modify confirmation message format and instructions for better clarity

fix #202 

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy authored Dec 13, 2024
1 parent a56347b commit e4b86ad
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cmd/textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@ type model struct {
err error
}

// initialPrompt initializes a textarea model with the given value.
// It sets the character limit to the length of the value plus 100,
// inserts the value into the textarea, and adjusts the width and height
// of the textarea based on the value's content. The textarea is then focused.
//
// Parameters:
// - value: A string to be inserted into the textarea.
//
// Returns:
// - model: A struct containing the initialized textarea and any error encountered.
func initialPrompt(value string) model {
ti := textarea.New()
// origin defaultCharLimit = 400
ti.CharLimit = len(value) + 100
ti.InsertString(value)
ti.SetWidth(80)

maxWidth := 0
for _, line := range strings.Split(value, "\n") {
if len(line) > maxWidth {
maxWidth = len(line)
}
}
ti.SetWidth(maxWidth)
ti.SetHeight(len(strings.Split(value, "\n")))
ti.Focus()

Expand Down Expand Up @@ -65,8 +84,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (m model) View() string {
return fmt.Sprintf(
"Please confirm the following commit message.\n\n%s\n\n%s",
"Please confirm the following commit message:\n\n%s\n\n%s",
m.textarea.View(),
"(ctrl+c to continue.)",
"(Press Ctrl+C to continue.)",
) + "\n\n"
}

0 comments on commit e4b86ad

Please sign in to comment.