Skip to content

Conversation

@zach-is-my-name
Copy link

@zach-is-my-name zach-is-my-name commented May 30, 2025

Summary

This PR adds zen-mode functionality to Glamour using the proven native Document margin system, providing a clean and consistent reading experience.

Key Features

  • WithZenMode function: Simple API for applying zen-mode margins
  • Native integration: Leverages Glamour's existing Document.Margin system
  • Proven reliability: Uses the same margin mechanism as default styles
  • Minimal footprint: Clean 10-line implementation

Technical Implementation

Final Approach (Latest Commit)

The implementation now uses Glamour's native Document.Margin system:

func WithZenMode(margin uint) TermRendererOption {
    return func(tr *TermRenderer) error {
        tr.ansiOptions.Styles.Document.Margin = &margin
        return nil
    }
}

This approach:

  • ✅ Leverages battle-tested margin rendering
  • ✅ Ensures consistency with existing styles
  • ✅ Minimal code surface for maintenance
  • ✅ Universal compatibility across all elements

Evolution

  • Initial commit: Custom margin/alignment implementation with comprehensive features
  • Final commit: Simplified to use native Document margin system for zen-mode focus

Example Usage

// Apply zen-mode with 20-character margins
renderer, _ := glamour.NewTermRenderer(
    glamour.WithZenMode(20),
)

Cross-Terminal Compatibility

Works seamlessly across all terminal sizes by leveraging Glamour's proven margin system that's already used in default styles.

Ready for zen-mode integration in Glow! 🧘‍♂️

🤖 Generated with Claude Code

This commit adds robust margin and text alignment capabilities to Glamour:

## Core Features
- New WithMargins(left, right) option for configurable left/right margins
- WithCenterAlignment() for centered text with margins
- WithJustifiedAlignment() for justified text with margins

## Key Changes
- Enhanced MarginWriter with center/justify alignment support
- Fixed Width() calculation to account for MarginLeft/MarginRight styles
- Added WordwrapWithIndent for proper continuation line indentation
- Comprehensive test suite for all margin/alignment combinations

## Technical Details
- blockstack.go: Width() now includes MarginLeft/MarginRight in calculations
- margin.go: Enhanced with writeCentered() and writeJustified() methods
- New wordwrap.go: Custom word wrapping that preserves indentation
- Full backwards compatibility maintained

Resolves margin application issues where paragraphs weren't respecting
configured margins due to incorrect width calculations during text wrapping.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Leverages glamour's proven native margin mechanism
- Provides clean API for zen-mode functionality
- Uses Document.Margin for consistent rendering across all elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant