Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Conversation

@doringeman
Copy link
Collaborator

@doringeman doringeman commented Sep 18, 2025

To try it locally, checkout this branch and run:

make install

E.g.,
Screenshot 2025-09-19 at 11 52 22

In the second commit I added a --color flag to choose whether you want the output to be colored and formatted:

Options:
      --color string                  Use colored output (auto|yes|no) (default "auto")

I decided to also display the token usage:
Screenshot 2025-09-19 at 12 44 10

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@ericcurtin
Copy link
Contributor

ericcurtin commented Sep 18, 2025

In the CLI case, we may not want to blindly add color/md, we should check that the terminal supports color, that we are not redirecting to a file, etc. Because in these cases you want to use plain-old text, an example of how you do this is here:

ggml-org/llama.cpp#15792 (common_log_should_use_colors_auto function)

grep, systemd, ramalama would be other reference implementations of this.

@ericcurtin ericcurtin requested a review from Copilot September 18, 2025 11:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Markdown rendering functionality to the chat feature, replacing the previous text output with styled Markdown rendering using the glamour library.

  • Removes the fatih/color dependency and replaces it with charmbracelet/glamour for Markdown rendering
  • Refactors the Chat method to return response content instead of directly printing to stdout
  • Adds terminal-aware Markdown rendering with automatic width detection and fallback to plain text

Reviewed Changes

Copilot reviewed 4 out of 783 changed files in this pull request and generated 1 comment.

File Description
go.mod Adds glamour and related dependencies, removes fatih/color dependency
desktop/desktop.go Refactors Chat method to return response content and removes direct console output
desktop/desktop_test.go Updates test to handle Chat method's new return signature
commands/run.go Adds Markdown rendering functionality with terminal width detection and fallback handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +83 to +86
var (
markdownRenderer *glamour.TermRenderer
lastWidth int
)
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global variables markdownRenderer and lastWidth are not thread-safe. If multiple goroutines call getMarkdownRenderer() concurrently, this could lead to race conditions when checking and updating these variables.

Copilot uses AI. Check for mistakes.
@doringeman
Copy link
Collaborator Author

In the CLI case, we may not want to blindly add color/md, we should check that the terminal supports color, that we are not redirecting to a file, etc. Because in these cases you want to use plain-old text, an example of how you do this is here:

ggml-org/llama.cpp#15792 (common_log_should_use_colors_auto function)

grep, systemd, ramalama would be other reference implementations of this.

Good point. Thanks!
Moreover, I was thinking of also adding a --disable-markdown flag to disable the formatting. WDYT?

@ericcurtin
Copy link
Contributor

ericcurtin commented Sep 18, 2025

In the CLI case, we may not want to blindly add color/md, we should check that the terminal supports color, that we are not redirecting to a file, etc. Because in these cases you want to use plain-old text, an example of how you do this is here:
ggml-org/llama.cpp#15792 (common_log_should_use_colors_auto function)
grep, systemd, ramalama would be other reference implementations of this.

Good point. Thanks! Moreover, I was thinking of also adding a --disable-markdown flag to disable the formatting. WDYT?

If it was me, I would do both like llama-server/grep does:

--color [auto|yes|no]

with auto being the default.

I do wonder about markdown for the CLI in general, that makes sense to me for the UI, but for CLI, people may not want that. Syntax highlighting I think makes sense though for code blocks etc.

If you want --color and --markdown to be one combined flag or separate flags, I'll let you make that choice but I suggest making it a flag with 3 options with auto being the default:

[on|off|auto] 

@xenoscopic
Copy link
Contributor

I also think auto is the right default here. The criteria that github.com/fatih/color uses are probably the most battle tested for Go:

https://github.com/fatih/color/blob/1c8d8706604ee5fb9a464e5097ba113101828a75/color.go#L16-L23

You could either add it back as a dependency (I'm sure we can find other uses) and use its NoColor variable or emulate the same rules. I don't see anything automatic in glamour.

@ericcurtin
Copy link
Contributor

I also think auto is the right default here. The criteria that github.com/fatih/color uses are probably the most battle tested for Go:

https://github.com/fatih/color/blob/1c8d8706604ee5fb9a464e5097ba113101828a75/color.go#L16-L23

You could either add it back as a dependency (I'm sure we can find other uses) and use its NoColor variable or emulate the same rules. I don't see anything automatic in glamour.

Yup, that's super similar to what we did in llama-server

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@doringeman doringeman marked this pull request as draft September 19, 2025 07:12
@doringeman
Copy link
Collaborator Author

This breaks the streaming experience. I need to come up with a solution to keep streaming the text and only block for a bit while, for example, a Markdown code block is completed.

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
Signed-off-by: Dorin Geman <dorin.geman@docker.com>
Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@doringeman doringeman marked this pull request as ready for review September 19, 2025 08:52
Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@ericcurtin ericcurtin merged commit a224872 into docker:main Sep 19, 2025
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants