Skip to content

Commit

Permalink
refactor(cmd): Refactor formatCommand to improve command formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgaOzen committed Dec 28, 2024
1 parent d43a2bd commit 8e91ac6
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ func (m RootModel) View() string {
// Render sections
brand := brandStyle.Render("Generating your command...")
header := headerStyle.Render("Here’s your command:")
message := messageStyle.Render(fmt.Sprintf("➤ kivo %s", m.command))

// Format the command
formattedCommand := formatCommand(m.command, 4)
message := messageStyle.Render(fmt.Sprintf("➤ kivo %s", formattedCommand))
prompt := promptStyle.Render("Would you like to use this command? (Y/n):")

// Combine output
Expand Down Expand Up @@ -146,3 +149,25 @@ func r(cfg *config.Config) func(cmd *cobra.Command, args []string) error {
return nil
}
}

// Helper function to format a command
func formatCommand(command string, maxWordsPerLine int) string {
parts := strings.Fields(command) // Split command into words
var result []string
var line []string

for _, part := range parts {
line = append(line, part)
if len(line) >= maxWordsPerLine {
result = append(result, strings.Join(line, " ")+" \\")
line = []string{}
}
}

// Add the remaining words
if len(line) > 0 {
result = append(result, strings.Join(line, " "))
}

return strings.Join(result, "\n ")
}

0 comments on commit 8e91ac6

Please sign in to comment.