Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: additional atmos docs parameters for specifying width, using auto-styling and color profile, and preserving new lines #757

Merged
merged 12 commits into from
Nov 11, 2024

Conversation

RoseSecurity
Copy link
Member

@RoseSecurity RoseSecurity commented Nov 1, 2024

what

atmos_docs

  • Add an additional atmos docs flag for specifying the width of markdown output
  • Utilizing auto-styling based on light or dark mode preferences instead of hardcoding to dark
  • Preserving new lines with rendered markdown

why

  • Enhance the user experience for interacting with documentation. The width parameter is useful for users who prefer seeing wider output for Terraform docs-generated tables and is defined in the atmos.yaml:
settings:
  docs:
    max-width: 200

future development

  • The goal of this PR is to continue to iterate on the command with future improvements including text searching and pagination

references

Summary by CodeRabbit

  • New Features

    • Introduced a new command option to customize the maximum width for documentation output, enhancing readability.
    • Added a new configuration field for documentation settings within the CLI configuration.
  • Bug Fixes

    • Improved error handling for component path checks in documentation commands.
  • Documentation

    • Enhanced documentation rendering with improved styling and word wrapping capabilities.

additional parameter for specifying the width of markdown outputs, and
maintain a consistent color profile
Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the docsCmd command in the cmd/docs.go file by adding a maxWidth variable to manage terminal output width. It checks for terminal size and utilizes a new term renderer from the glamour package for improved documentation formatting. Additionally, a new Docs structure is added to the CliSettings in pkg/schema/schema.go, allowing for configuration of documentation settings, specifically the maximum width for word wrapping.

Changes

File Change Summary
cmd/docs.go - Added variable maxWidth for terminal width management.
- Introduced command flag for setting word-wrap width.
- Updated error handling for component path checks.
- Modified documentation rendering using glamour with new options.
pkg/schema/schema.go - Added new structure Docs with field MaxWidth.
- Updated CliSettings to include Docs field, marked as optional in YAML/JSON.

Possibly related PRs

Suggested reviewers

  • Gowiem
  • aknysh
  • osterman

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6e184f2 and 8e5db24.

📒 Files selected for processing (2)
  • cmd/docs.go (3 hunks)
  • pkg/schema/schema.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/docs.go
  • pkg/schema/schema.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 9cbe499 and 6a09356.

📒 Files selected for processing (1)
  • cmd/docs.go (5 hunks)
🔇 Additional comments (3)
cmd/docs.go (3)

11-11: LGTM: Clean import and variable declaration

The new lipgloss import and width variable are appropriately declared for the enhanced functionality.

Also applies to: 21-21


50-50: LGTM: Improved error message clarity

The consolidated error message provides clear context about the component and its expected location.


67-77: LGTM: Well-structured renderer configuration

The new glamour renderer configuration properly implements all required features with appropriate error handling.

cmd/docs.go Outdated Show resolved Hide resolved
@RoseSecurity RoseSecurity marked this pull request as draft November 1, 2024 13:59
@RoseSecurity RoseSecurity marked this pull request as ready for review November 1, 2024 14:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range comments (1)
go.mod (1)

Line range hint 3-3: Invalid Go version specified

The Go version 1.23 specified in the go.mod file is not valid. The latest stable version of Go is 1.22.

Apply this change:

-go 1.23
+go 1.22
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 6a09356 and 0a5122a.

📒 Files selected for processing (2)
  • cmd/docs.go (5 hunks)
  • go.mod (1 hunks)
🔇 Additional comments (5)
go.mod (1)

44-44: LGTM: Appropriate dependency addition for terminal operations

The addition of golang.org/x/term as a direct dependency is appropriate for implementing the terminal width customization feature. This is a well-maintained package from the Go ecosystem.

cmd/docs.go (4)

11-13: Appropriate Addition of Imports for New Functionality

The inclusion of lipgloss and golang.org/x/term packages is necessary to support color profile handling and terminal size detection.


22-23: Declaration of 'width' Variable

Introducing the width variable enables dynamic word-wrap configuration based on terminal width.


44-61: Implementation of Dynamic Terminal Width Detection

The logic for detecting terminal width when the width flag is not set is well-implemented, with appropriate error handling and sensible defaults.


86-95: Enhanced Glamour Renderer with Additional Styling Options

The updated renderer configuration improves the documentation output by applying color profiles, auto-styling, preserving new lines, and dynamically wrapping text based on the width variable.

cmd/docs.go Outdated Show resolved Hide resolved
cmd/docs.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 0a5122a and 6aacedd.

📒 Files selected for processing (1)
  • cmd/docs.go (5 hunks)
🧰 Additional context used
📓 Learnings (1)
cmd/docs.go (1)
Learnt from: RoseSecurity
PR: cloudposse/atmos#757
File: cmd/docs.go:52-54
Timestamp: 2024-11-01T14:45:32.417Z
Learning: In `cmd/docs.go`, capping the terminal width at 120 columns is considered acceptable and preferred after testing.
🔇 Additional comments (4)
cmd/docs.go (4)

44-60: LGTM! Robust terminal width detection implementation

The implementation properly handles terminal detection with appropriate fallbacks, following the recommended approach from glow.


52-54: LGTM! Width capping is appropriate

The 120-column cap has been tested and confirmed as an acceptable value.


69-69: LGTM! Clear error message

The error message is concise and informative.


86-96: LGTM! Comprehensive renderer configuration

The glamour renderer is well-configured with appropriate options for color profile, styling, and formatting. However, let's verify the renderer's behavior with different terminal types.

✅ Verification successful

Let me gather more context about the terminal handling in the codebase.


Terminal handling is properly implemented

The code correctly handles terminal detection and width adjustment:

  • Checks if output is to a terminal using term.IsTerminal
  • Dynamically adjusts width based on terminal size with term.GetSize
  • Falls back gracefully when terminal detection fails
  • Configures glamour renderer with appropriate terminal-aware settings (color profile, auto-style)
  • Implements sensible width limits (capped at 120)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the code handles different terminal types appropriately
# Test: Search for terminal-specific handling
rg -l "term.IsTerminal|term.GetSize|glamour.WithColorProfile|glamour.WithAutoStyle"

Length of output: 97


Script:

#!/bin/bash
# Get the full context of terminal-related code in docs.go
rg -B 5 -A 5 "term.IsTerminal|term.GetSize|glamour.WithColorProfile|glamour.WithAutoStyle" cmd/docs.go

Length of output: 783

cmd/docs.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 6aacedd and 0a087a3.

📒 Files selected for processing (1)
  • cmd/docs.go (4 hunks)
🧰 Additional context used
📓 Learnings (1)
cmd/docs.go (1)
Learnt from: RoseSecurity
PR: cloudposse/atmos#757
File: cmd/docs.go:52-54
Timestamp: 2024-11-01T14:45:32.417Z
Learning: In `cmd/docs.go`, capping the terminal width at 120 columns is considered acceptable and preferred after testing.
🔇 Additional comments (3)
cmd/docs.go (3)

11-11: LGTM: Import changes are appropriate.

The new imports for terminal detection (term) and styling (lipgloss) are correctly added and used in the implementation.

Also applies to: 13-13


68-68: LGTM: Error message formatting is improved.

The simplified error message formatting maintains clarity while reducing code complexity.


125-125: LGTM: Width flag implementation.

The flag implementation is complete with a clear description and appropriate default value.

cmd/docs.go Outdated Show resolved Hide resolved
cmd/docs.go Outdated Show resolved Hide resolved
cmd/docs.go Outdated Show resolved Hide resolved
@RoseSecurity RoseSecurity marked this pull request as draft November 1, 2024 19:33
@RoseSecurity RoseSecurity marked this pull request as ready for review November 4, 2024 16:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
pkg/schema/schema.go (1)

35-37: Consider adding field documentation.

The Docs struct implementation looks good! Consider adding a comment to document the purpose and valid range of MaxWidth.

 type Docs struct {
+    // MaxWidth specifies the maximum width for markdown output rendering.
+    // Valid range: 1-120, defaults to 80 if not specified.
     MaxWidth int `yaml:"max-width" json:"max_width" mapstructure:"max-width"`
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0a087a3 and f4785b8.

📒 Files selected for processing (3)
  • cmd/docs.go (3 hunks)
  • go.mod (1 hunks)
  • pkg/schema/schema.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/docs.go
  • go.mod
🔇 Additional comments (1)
pkg/schema/schema.go (1)

32-33: LGTM! Clean addition of Docs field.

The field is properly integrated into the CliSettings struct with consistent tag naming and proper use of omitempty.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 4, 2024
cmd/docs.go Outdated Show resolved Hide resolved
cmd/docs.go Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 4, 2024
cmd/docs.go Outdated Show resolved Hide resolved
cmd/docs.go Outdated Show resolved Hide resolved
cmd/docs.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
cmd/docs.go (1)

42-59: Consider using more descriptive variable names.

While the logic is solid, variable names like w could be more descriptive. Consider renaming for better clarity:

-				w, _, err := term.GetSize(int(os.Stdout.Fd()))
-				if err == nil && w > 0 {
-					screenWidth = w
+				termWidth, _, err := term.GetSize(int(os.Stdout.Fd()))
+				if err == nil && termWidth > 0 {
+					screenWidth = termWidth
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b8326f3 and a9a2e41.

📒 Files selected for processing (2)
  • cmd/docs.go (3 hunks)
  • go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • go.mod
🧰 Additional context used
📓 Learnings (1)
cmd/docs.go (1)
Learnt from: RoseSecurity
PR: cloudposse/atmos#757
File: cmd/docs.go:42-59
Timestamp: 2024-11-01T15:44:12.617Z
Learning: In `cmd/docs.go`, when implementing width detection for the `docsCmd` command, it's acceptable to keep the code inline without extracting it into a separate function, as per the user's preference for compact readability and maintainability in Go code.
🔇 Additional comments (4)
cmd/docs.go (4)

11-11: LGTM! Required imports added correctly.

The new imports for lipgloss and term packages are necessary for color profile management and terminal size detection respectively.

Also applies to: 13-13


42-59: LGTM! Width detection logic implemented correctly.

The implementation follows the agreed approach:

  1. Uses maxWidth from CLI config
  2. Detects terminal width if available
  3. Applies appropriate fallbacks
  4. Handles edge cases properly

68-68: LGTM! Clear and informative error message.

The error message provides good context by including both the component name and the path.


85-95: LGTM! Comprehensive renderer configuration.

The term renderer is well-configured with:

  • Color profile management
  • Auto-styling
  • New line preservation
  • Word wrapping
  • Enhanced error handling

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 4, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 4, 2024
@osterman
Copy link
Member

osterman commented Nov 5, 2024

Unfriendly error message: (this is more debug log level)

Component folder does not exist. We should instead say, "Component vpc not found"
image

Good error message:

(no README.md file exists in a valid component folder)

image

@osterman
Copy link
Member

osterman commented Nov 5, 2024

It does not appear to be detecting the full width of my terminal. Maybe we should add some debug messages to see what the max width is determined as and what width is selected.

image

Note, the screen is much wider, and the text is not wrapping and is truncated.

@osterman osterman added the minor New features that do not break anything label Nov 6, 2024
@RoseSecurity
Copy link
Member Author

It does not appear to be detecting the full width of my terminal. Maybe we should add some debug messages to see what the max width is determined as and what width is selected.

image Note, the screen is much wider, and the text is not wrapping and is truncated.

Just removed the logic that defaults back to 120 for the maximum width, allowing the word wrap to dynamically adjust to the terminal size. I think it looks a little less clean when rendered this way but feel free to check it out

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
cmd/docs.go (1)

84-94: Consider enhancing the renderer error message.

While the renderer configuration is solid, the error message could be more specific about which option caused the failure.

-				u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("failed to initialize markdown renderer: %w", err))
+				u.LogErrorAndExit(schema.CliConfiguration{}, fmt.Errorf("failed to initialize markdown renderer with width %d: %w", screenWidth, err))
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1e6d6a9 and 6e184f2.

📒 Files selected for processing (1)
  • cmd/docs.go (3 hunks)
🧰 Additional context used
📓 Learnings (1)
cmd/docs.go (1)
Learnt from: RoseSecurity
PR: cloudposse/atmos#757
File: cmd/docs.go:42-59
Timestamp: 2024-11-01T15:44:12.617Z
Learning: In `cmd/docs.go`, when implementing width detection for the `docsCmd` command, it's acceptable to keep the code inline without extracting it into a separate function, as per the user's preference for compact readability and maintainability in Go code.
🔇 Additional comments (3)
cmd/docs.go (3)

11-11: LGTM! Imports are well-organized.

The new imports for lipgloss and term packages are correctly placed and support the enhanced terminal rendering features.

Also applies to: 13-13


42-59: Well implemented terminal width detection!

The implementation aligns perfectly with the discussed approach:

  • Respects user-configured maxWidth from atmos.yaml
  • Gracefully falls back to terminal width when available
  • Uses sensible defaults (120 characters)
  • Maintains clean, compact code structure

67-67: Error messages are now more user-friendly!

The improved error messages clearly indicate the specific issue:

  • Component not found message includes the searched path
  • Separate message for missing README vs component not found

Also applies to: 75-75

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 7, 2024
@osterman
Copy link
Member

osterman commented Nov 7, 2024

It appears there's some fudge factor needed with the width calculation. It's off by 2 characters. I'm wondering if it's related to something like \r\n

CleanShot 2024-11-07 at 11 39 51

I think it looks a little less clean when rendered this way but feel free to check it out

Maybe this is what you're referring to. But this is a bug, not a result of limiting the width. That causes an extra line feed between each row.

If I expand my screen by 2 characters, I get
image

Which is clean.

characters which appears to be a subtle padding effect at the terminal
boundaries
@RoseSecurity
Copy link
Member Author

It appears there's some fudge factor needed with the width calculation. It's off by 2 characters. I'm wondering if it's related to something like \r\n

CleanShot 2024-11-07 at 11 39 51

I think it looks a little less clean when rendered this way but feel free to check it out

Maybe this is what you're referring to. But this is a bug, not a result of limiting the width. That causes an extra line feed between each row.

If I expand my screen by 2 characters, I get image

Which is clean.

Thanks for the great find! Interesting that there is a subtle padding effect at the terminal boundaries like that. I adjusted accordingly and added a comment for the width subtraction in the code!

@osterman
Copy link
Member

Perfect, LGTM!

image

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @RoseSecurity

@aknysh aknysh merged commit 1250929 into main Nov 11, 2024
22 checks passed
@aknysh aknysh deleted the enhance-markdown-rendering-in-docs-cmd branch November 11, 2024 17:04
Copy link

These changes were released in v1.103.0.

@osterman
Copy link
Member

Regarding the incorrect screen width calculations (which we resolved with a hack), it might be related to this recently opened issue.

@M0hammadUsman
Copy link

Regarding the incorrect screen width calculations (which we resolved with a hack), it might be related to this recently opened issue.

@osterman It has been resolved in bubbletea 1.2.1, now the issue is still open there because there is something else.

See my last comment on that issue to get more insight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants