From 4d940b5845c81587302389e7c533efafc161823a Mon Sep 17 00:00:00 2001 From: reugn Date: Fri, 6 Dec 2024 16:57:47 +0200 Subject: [PATCH] feat: expose response word wrapping length configuration --- README.md | 1 + cmd/gemini/main.go | 6 ++++-- internal/chat/chat.go | 2 +- internal/chat/chat_options.go | 12 +++++++++++- internal/handler/gemini_query.go | 7 +++++-- internal/handler/renderer_options.go | 7 +++++++ 6 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 internal/handler/renderer_options.go diff --git a/README.md b/README.md index 6e5d290..f0ab9ad 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/gemini/main.go b/cmd/gemini/main.go index ab46131..3a9e628 100644 --- a/cmd/gemini/main.go +++ b/cmd/gemini/main.go @@ -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") diff --git a/internal/chat/chat.go b/internal/chat/chat.go index 39024fe..aac00d7 100644 --- a/internal/chat/chat.go +++ b/internal/chat/chat.go @@ -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 } diff --git a/internal/chat/chat_options.go b/internal/chat/chat_options.go index 51d1f66..3ef9977 100644 --- a/internal/chat/chat_options.go +++ b/internal/chat/chat_options.go @@ -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, + } } diff --git a/internal/handler/gemini_query.go b/internal/handler/gemini_query.go index c35a35c..3a73f3d 100644 --- a/internal/handler/gemini_query.go +++ b/internal/handler/gemini_query.go @@ -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) } diff --git a/internal/handler/renderer_options.go b/internal/handler/renderer_options.go new file mode 100644 index 0000000..e499947 --- /dev/null +++ b/internal/handler/renderer_options.go @@ -0,0 +1,7 @@ +package handler + +// RendererOptions represents configuration options for the terminal renderer. +type RendererOptions struct { + StylePath string + WordWrap int +}