Skip to content

Commit e4b86ad

Browse files
authored
feat: improve user input handling and feedback mechanisms (#203)
- 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 <[email protected]>
1 parent a56347b commit e4b86ad

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

cmd/textarea.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,29 @@ type model struct {
1515
err error
1616
}
1717

18+
// initialPrompt initializes a textarea model with the given value.
19+
// It sets the character limit to the length of the value plus 100,
20+
// inserts the value into the textarea, and adjusts the width and height
21+
// of the textarea based on the value's content. The textarea is then focused.
22+
//
23+
// Parameters:
24+
// - value: A string to be inserted into the textarea.
25+
//
26+
// Returns:
27+
// - model: A struct containing the initialized textarea and any error encountered.
1828
func initialPrompt(value string) model {
1929
ti := textarea.New()
30+
// origin defaultCharLimit = 400
31+
ti.CharLimit = len(value) + 100
2032
ti.InsertString(value)
21-
ti.SetWidth(80)
33+
34+
maxWidth := 0
35+
for _, line := range strings.Split(value, "\n") {
36+
if len(line) > maxWidth {
37+
maxWidth = len(line)
38+
}
39+
}
40+
ti.SetWidth(maxWidth)
2241
ti.SetHeight(len(strings.Split(value, "\n")))
2342
ti.Focus()
2443

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

6685
func (m model) View() string {
6786
return fmt.Sprintf(
68-
"Please confirm the following commit message.\n\n%s\n\n%s",
87+
"Please confirm the following commit message:\n\n%s\n\n%s",
6988
m.textarea.View(),
70-
"(ctrl+c to continue.)",
89+
"(Press Ctrl+C to continue.)",
7190
) + "\n\n"
7291
}

0 commit comments

Comments
 (0)