Skip to content

Commit

Permalink
feat: expose response word wrapping length configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Dec 6, 2024
1 parent 2c188a1 commit 4d940b5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Flags:
-s, --style string markdown format style (ascii, dark, light, pink, notty, dracula) (default "auto")
-t, --term string multi-line input terminator (default "$")
-v, --version version for this command
-w, --wrap int line length for response word wrapping (default 80)
```

## License
Expand Down
6 changes: 4 additions & 2 deletions cmd/gemini/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ func run() int {
var configPath string
rootCmd.Flags().StringVarP(&opts.GenerativeModel, "model", "m", gemini.DefaultModel,
"generative model name")
rootCmd.Flags().StringVarP(&opts.Style, "style", "s", "auto",
"markdown format style (ascii, dark, light, pink, notty, dracula)")
rootCmd.Flags().BoolVar(&opts.Multiline, "multiline", false,
"read input as a multi-line string")
rootCmd.Flags().StringVarP(&opts.LineTerminator, "term", "t", "$",
"multi-line input terminator")
rootCmd.Flags().StringVarP(&opts.StylePath, "style", "s", "auto",
"markdown format style (ascii, dark, light, pink, notty, dracula)")
rootCmd.Flags().IntVarP(&opts.WordWrap, "wrap", "w", 80,
"line length for response word wrapping")
rootCmd.Flags().StringVarP(&configPath, "config", "c", defaultConfigPath,
"path to configuration file in JSON format")

Expand Down
2 changes: 1 addition & 1 deletion internal/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func New(
}

geminiIO := handler.NewIO(terminalIO, terminalIO.Prompt.Gemini)
geminiHandler, err := handler.NewGeminiQuery(geminiIO, session, opts.Style)
geminiHandler, err := handler.NewGeminiQuery(geminiIO, session, opts.rendererOptions())
if err != nil {
return nil, err
}
Expand Down
12 changes: 11 additions & 1 deletion internal/chat/chat_options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package chat

import "github.com/reugn/gemini-cli/internal/handler"

// Opts represents the Chat configuration options.
type Opts struct {
GenerativeModel string
Style string
Multiline bool
LineTerminator string
StylePath string
WordWrap int
}

func (o *Opts) rendererOptions() handler.RendererOptions {
return handler.RendererOptions{
StylePath: o.StylePath,
WordWrap: o.WordWrap,
}
}
7 changes: 5 additions & 2 deletions internal/handler/gemini_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ type GeminiQuery struct {
var _ MessageHandler = (*GeminiQuery)(nil)

// NewGeminiQuery returns a new GeminiQuery message handler.
func NewGeminiQuery(io *IO, session *gemini.ChatSession, style string) (*GeminiQuery, error) {
renderer, err := glamour.NewTermRenderer(glamour.WithStylePath(style))
func NewGeminiQuery(io *IO, session *gemini.ChatSession, opts RendererOptions) (*GeminiQuery, error) {
renderer, err := glamour.NewTermRenderer(
glamour.WithStylePath(opts.StylePath),
glamour.WithWordWrap(opts.WordWrap),
)
if err != nil {
return nil, fmt.Errorf("failed to instantiate terminal renderer: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions internal/handler/renderer_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package handler

// RendererOptions represents configuration options for the terminal renderer.
type RendererOptions struct {
StylePath string
WordWrap int
}

0 comments on commit 4d940b5

Please sign in to comment.