-
Notifications
You must be signed in to change notification settings - Fork 518
Add comprehensive zen-mode with configurable margins #774
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
Open
zach-is-my-name
wants to merge
6
commits into
charmbracelet:master
Choose a base branch
from
zach-is-my-name:zen-mode-margins
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add comprehensive zen-mode with configurable margins #774
zach-is-my-name
wants to merge
6
commits into
charmbracelet:master
from
zach-is-my-name:zen-mode-margins
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds a complete zen-mode feature for Glow with: ## Features - `--zen`/`-z` flag for zen-mode reading experience - `--zen-width` flag for custom line width (default: auto-detected) - `--zen-margin` flag for margin percentage (default: 20%) ## Implementation - Auto-detects terminal width and applies percentage-based margins - Universal compatibility across all terminal sizes (80-200+ columns) - Uses Glamour's WithMargins() for proper text layout - Configurable width and margin percentages for customization ## Examples ```bash # Default zen-mode (20% margins, auto width) glow -z README.md # Custom margins glow -z --zen-margin=30 README.md # Custom width and margins glow -z --zen-width=100 --zen-margin=25 README.md ``` Provides VSCode/Neovim-style zen reading experience with centered text and comfortable margins for focused markdown consumption. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Change from WithMargins() back to WithZenMode() - Restores true centering behavior using glamour's native Document margin system - WithMargins() only sets individual element margins, WithZenMode() provides global centering 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Respect PAGER environment variable as documented in README - Fall back to 'less -r' when PAGER is not set (upstream specification) - Parse pager commands with arguments using strings.Fields() - Maintain backward compatibility with existing behavior This completes the zen-mode implementation with proper pager integration as specified in the upstream documentation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Zen-mode now properly detects terminal width even when config files set explicit width values. This ensures zen-mode margins are calculated based on actual terminal size rather than fixed config values. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
## New Features - **Custom zen flag type**: Supports both -z and -z=12 syntax as documented in PR - **Optional margin values**: -z uses config/default margin, -z=12 uses explicit margin - **Config file integration**: Priority order: CLI -z=12 > CLI -z + config > default ## Config Override Behavior - **Width override**: Zen mode ignores config width and uses terminal width for proper centering - **Style preservation**: Config style settings (tokyo-night, etc.) still respected - **Margin integration**: -z without value uses config zenMarginPercent if available ## Validation & Safety - **Conflict prevention**: Cannot use --width with --zen (returns clear error message) - **Help documentation**: Updated zen flag help to warn about config width override - **Backward compatibility**: Preserves existing width detection for non-zen usage ## Usage Examples ```bash # Default zen mode (uses config margin or 20% default) glow -z README.md # Explicit margin percentage glow -z=12 README.md # Config integration (if zenMarginPercent: 15 in config) glow -z README.md # Uses 15% margins from config # Error case glow -z -w 100 README.md # Returns error: cannot use --width with --zen ``` ## Recommendation for Config Users When using zen mode, set style/pager preferences as CLI flags instead of config: ```bash glow -z=12 -s tokyo-night -p document.md ``` This avoids relying on config file width settings that zen mode overrides. Fulfills PR description promise of "glow -z=12" syntax while maintaining compatibility with existing glow/glamour width detection systems. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
When using zen mode (-z), style and width flags now operate in session-only mode without creating or modifying config files. This addresses the issue where `glow -z -s tokyo-night` would persist settings to ~/.config/glow/glow.yml, breaking the zen experience. Changes: - Conditional viper flag binding skips style/width when zen mode enabled - Manual style flag handling in zen mode bypasses viper persistence - Maintains full compatibility for non-zen mode users - Enables true session-only zen mode operation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
gustavosbarreto
pushed a commit
to drera-labs/glow
that referenced
this pull request
Jun 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive zen-mode support to glow with configurable margins for comfortable reading, plus PAGER environment variable support for seamless integration with custom pagers.
Key Features
-z,--zen): Enables zen-mode with auto margins or accepts optional value for fixed character marginsless -RUsage Examples
✨ Session-Only Zen Mode Behavior
Major Enhancement: When using zen-mode (
-zor-z=12), glow now operates in session-only mode for style and width settings:No Config File Pollution
-s tokyo-nightdon't create or modify config filesClean User Experience
Backward Compatibility
glow -s tokyo-nightstill saves to config as before-z) enables session-only behaviorTechnical Implementation
Session-Only Config Handling
Margin Priority Order
-z=12(uses 12% margins)-zwithzenMarginPercent: 15in config (uses 15%)-zwith no config margin (uses 20% default)Maximally Minimal Zen-Mode
This PR pairs perfectly with gwsw/less#629 which adds the
-H/--hide-promptoption to less for accessibility. Together, these PRs enable a maximally minimal zen-mode reading experience:Technical Details
less -Rwhen PAGER is not setstrings.Fields()-z) and valued (-z=12) syntaxTesting
Tested with various terminal sizes, margin configurations, custom pagers, and config file combinations. Verified that zen mode with style flags creates no config files while maintaining all functionality. Works seamlessly with accessibility-focused pagers and provides clean session-only operation.
🤖 Generated with Claude Code