### Command-Line Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/INDEX.md Command-line examples are presented using `bash` syntax. This example demonstrates how to use Glow to render a README.md file with a 'dark' style. ```bash glow -s dark README.md ``` -------------------------------- ### Install Glow via Go Source: https://github.com/charmbracelet/glow/blob/master/README.md Install the latest version of Glow using the Go toolchain. ```bash go install github.com/charmbracelet/glow/v2@latest ``` -------------------------------- ### Glow Configuration File Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/README.md Example of a glow.yml configuration file. Customize style, text wrapping, pager, TUI behavior, and display options. ```yaml # Style: "auto", "dark", "light", or path to JSON file style: "dark" # Word-wrap width (0 = no wrap, auto-detect if terminal) width: 100 # Use pager for CLI output pager: false # Use TUI mode by default tui: false # Show all files including hidden/ignored (TUI) all: false # Show line numbers in pager (TUI) showLineNumbers: true # Enable mouse wheel support (TUI) mouse: true # Preserve newlines in output preserveNewLines: false ``` -------------------------------- ### GitLab API Request Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md This demonstrates the GET request format to the GitLab API for fetching project details, which includes the URL for the README file. ```http GET /api/v4/projects/{url_encoded_path} ``` -------------------------------- ### GitHub API Request Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md This is an example of the GET request format to the GitHub API for retrieving repository README information. The 'Accept' header specifies the desired API version. ```http GET /repos/{owner}/{repo}/readme Accept: application/vnd.github.v3.raw ``` -------------------------------- ### Install Glow via Package Managers Source: https://github.com/charmbracelet/glow/blob/master/README.md Commands for installing Glow on various operating systems using their respective package managers. ```bash # macOS or Linux brew install glow ``` ```bash # macOS (with MacPorts) sudo port install glow ``` ```bash # Arch Linux (btw) pacman -S glow ``` ```bash # Void Linux xbps-install -S glow ``` ```bash # Nix shell nix-shell -p glow --command glow ``` ```bash # FreeBSD pkg install glow ``` ```bash # Solus eopkg install glow ``` ```bash # Windows (with Chocolatey, Scoop, or Winget) choco install glow scoop install glow winget install charmbracelet.glow ``` ```bash # Android (with termux) pkg install glow ``` ```bash # Ubuntu (Snapcraft) sudo snap install glow ``` ```bash # Debian/Ubuntu sudo mkdir -p /etc/apt/keyrings curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list sudo apt update && sudo apt install glow ``` ```bash # Fedora/RHEL echo '[charm] name=Charm baseurl=https://repo.charm.sh/yum/ enabled=1 gpgcheck=1 gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo sudo yum install glow ``` -------------------------------- ### Pre-loaded Content in TUI Mode Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md This example shows how to launch TUI mode and provide content directly using the '-c' flag. ```bash glow -t -c "# Content" # When content is provided ``` -------------------------------- ### Initialize TUI Program Configuration Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md This Go code snippet demonstrates how to initialize the configuration for the TUI program, specifying the starting directory and other UI settings. ```go cfg := ui.Config{ Path: ".", // Start directory ShowAllFiles: false, ShowLineNumbers: false, GlamourMaxWidth: 100, GlamourStyle: "auto", EnableMouse: false, PreserveNewLines: false, } program := ui.NewProgram(cfg, "") program.Run() ``` -------------------------------- ### Use Glow CLI Source: https://github.com/charmbracelet/glow/blob/master/README.md Examples of using the Glow CLI to read markdown from files, stdin, GitHub/GitLab, or HTTP URLs. ```bash # Read from file glow README.md # Read from stdin echo "[Glow](https://github.com/charmbracelet/glow)" | glow - # Fetch README from GitHub / GitLab glow github.com/charmbracelet/glow # Fetch markdown from HTTP glow https://host.tld/file.md ``` -------------------------------- ### Go Function Signature Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/INDEX.md Go function signatures are highlighted using `go` syntax. This example shows a typical function signature for retrieving a source. ```go func sourceFromArg(arg string) (*source, error) ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/INDEX.md YAML configurations are highlighted using `yaml` syntax. This snippet shows basic style and width settings for Glow. ```yaml style: "dark" width: 100 ``` -------------------------------- ### Stdin Auto-Detection Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md Demonstrates how to use Glow with piped input versus direct file input. ```bash cat README.md | glow # Auto-reads from stdin glow README.md # Reads file directly ``` -------------------------------- ### GitLab API Response Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md A sample JSON response from the GitLab API. The 'readme_url' field provides the URL to the README file, which needs a slight transformation to get the raw content. ```json { "readme_url": "https://gitlab.com/owner/repo/-/blob/main/README.md", ... } ``` -------------------------------- ### Example Glow Configuration File Source: https://github.com/charmbracelet/glow/blob/master/README.md This YAML configuration file allows users to set default flags for the `glow` command. Options include styling, mouse support, pagination, text wrapping width, and file visibility. ```yaml # style name or JSON path (default "auto") style: "light" # mouse wheel support (TUI-mode only) mouse: true # use pager to display markdown pager: true # at which column should we word wrap? width: 80 # show all files, including hidden and ignored. all: false # show line numbers (TUI-mode only) showLineNumbers: false # preserve newlines in the output preserveNewLines: false ``` -------------------------------- ### CLI Mode Usage: File Rendering Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Examples of rendering local markdown files and directories using Glow in CLI mode. ```bash # File rendering glow README.md glow ./docs/guide.md # Directory with README glow ./project # URL rendering glow https://example.com/README.md # GitHub/GitLab shorthand glow github.com/charmbracelet/glow glow gitlab.com/owner/project ``` -------------------------------- ### Go Error Wrapping Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/errors.md Demonstrates how to wrap errors with context using fmt.Errorf in Go. This preserves the original error chain for detailed logging. ```go return fmt.Errorf("context: %w", err) ``` ```go if err != nil { // The full error chain is preserved log.Error("operation failed", "error", err) } ``` -------------------------------- ### Enable Shell Completions for Glow Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Install shell completions for Glow to improve command-line usability. This is typically done after installing Glow via a package manager. ```bash # Enable completions (if installed via package manager) source /etc/bash_completion.d/glow # Linux ``` ```bash # Enable completions (if installed via package manager) source $(brew --prefix)/etc/bash_completion.d/glow # macOS ``` -------------------------------- ### GitHub API Response Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md A sample JSON response from the GitHub API when requesting a repository's README. The 'download_url' field is crucial for fetching the actual content of the README file. ```json { "download_url": "https://raw.githubusercontent.com/owner/repo/main/README.md", "name": "README.md", ... } ``` -------------------------------- ### Style Validation Error Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md This is an example of an error message displayed when a specified style file does not exist or is not readable. ```text Error: specified style does not exist: /nonexistent/style.json ``` -------------------------------- ### Override Configuration File Width Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md This example demonstrates how to override the 'width' setting from a configuration file using a command-line flag. The CLI flag takes precedence over the config file. ```bash # Config file has: width: 80 # But this overrides it: glow -w 100 README.md ``` -------------------------------- ### CLI Mode Usage: Stdin Rendering Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Examples of piping content to Glow via stdin for rendering in CLI mode. Use '-' to indicate stdin. ```bash # Stdin cat README.md | glow echo "# Header" | glow - ``` -------------------------------- ### Built-in Glamour Style Configuration Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md Example of using a built-in Glamour style like 'dracula'. Sets a specific width. ```yaml # Use built-in Dracula style style: "dracula" width: 88 ``` -------------------------------- ### Directory Argument for Auto-TUI Mode Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Providing a directory argument automatically launches Glow in TUI mode, starting the file browser from the specified directory. ```bash glow . ``` ```bash glow ./docs ``` ```bash glow /path/to/project ``` -------------------------------- ### No Arguments for Auto-TUI Mode Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Running Glow without any arguments automatically launches TUI mode, starting the file browser from the current working directory. ```bash glow ``` -------------------------------- ### Override Configuration File Width with Environment Variable Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md This example shows how an environment variable can override configuration file settings. The GLOW_WIDTH environment variable takes precedence over both the config file and CLI flags. ```bash # And this environment variable would override too: GLOW_WIDTH=120 glow README.md ``` -------------------------------- ### Batch Process Markdown Files with Glow Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Process multiple Markdown files efficiently using parallel execution. Examples show how to use GNU Parallel or xargs with the `find` command to render files in parallel or sequentially. ```bash # Process files in parallel (GNU Parallel) find . -name "*.md" | parallel glow # Process with xargs find . -name "*.md" | xargs -I {} glow {} ``` -------------------------------- ### View Help Source: https://github.com/charmbracelet/glow/blob/master/README.md Display the help menu for additional usage details. ```bash glow --help ``` -------------------------------- ### Build Glow from Source Source: https://github.com/charmbracelet/glow/blob/master/README.md Clone the repository and build the binary from source using Go 1.21+. ```bash git clone https://github.com/charmbracelet/glow.git cd glow go build ``` -------------------------------- ### Get paginator for current section Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/ui-components.md Returns the paginator associated with the current section. ```go func (m stashModel) paginator() *paginator.Model ``` -------------------------------- ### Simple Documentation Server with Auto-Refresh Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md A script to create a simple documentation server that automatically refreshes when the target file is modified. It renders the specified file using Glow. ```bash #!/bin/bash # Simple doc server with auto-refresh while true; do clear glow "$1" 2>/dev/null || echo "File not found or error" inotifywait -e modify "$1" 2>/dev/null || sleep 1 done ``` -------------------------------- ### Get cursor position Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/ui-components.md Returns the current cursor position within the active section. ```go func (m stashModel) cursor() int ``` -------------------------------- ### Display Project Documentation Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Use Glow to view specific files like README, LICENSE, or CHANGELOG, or to browse all markdown documentation in a directory. ```bash # Standard project structure glow README.md # Main readme glow docs/ # Browse documentation glow LICENSE # View license glow CHANGELOG.md # View changelog # Discover available docs glow # TUI mode finds all markdown files ``` -------------------------------- ### Open Glow Configuration File Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md Use this command to open the Glow configuration file in your default editor. If the file does not exist, it will be created. ```bash glow config ``` -------------------------------- ### Get current section Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/ui-components.md Retrieves a pointer to the currently active section within the stash model. ```go func (m stashModel) currentSection() *section ``` -------------------------------- ### Combine with Other Tools Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Use 'find' and 'xargs' to locate markdown files, extract their content, and pipe it to Glow for processing. ```bash find . -name "*.md" | head -1 | xargs cat | glow ``` -------------------------------- ### Multi-file Documentation with Glow Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Browse documentation with line numbers, render all docs to HTML equivalent using a loop, or search documentation content. ```bash # Browse docs with line numbers glow -l ./docs # Render all docs to HTML equivalent for f in docs/*.md; do glow "$f"; done # Search documentation glow docs/ | grep -i "installation" ``` -------------------------------- ### Status Message String Representation Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/types.md Method to get the styled string representation of a status message based on its type. ```go func (s statusMessage) String() string ``` -------------------------------- ### GitHub Actions for Documentation Validation Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Example GitHub Actions workflow to validate all markdown documentation using Glow on pull requests. ```yaml name: Validate Documentation on: [pull_request] jobs: docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: charmbracelet/setup-glow@v0 - run: | for f in docs/**/*.md; do glow "$f" > /dev/null || exit 1 done ``` -------------------------------- ### Configure Desktop Integration for Glow Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Set Glow as the default application for opening markdown files on desktop environments. ```bash # Open markdown files with Glow xdg-mime default glow.desktop text/markdown ``` ```bash # Set as default markdown viewer alias open='glow' # macOS equivalent ``` -------------------------------- ### CLI Mode Usage: Multiple Files Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Demonstrates rendering multiple markdown files sequentially in CLI mode. Output is concatenated. ```bash # Multiple files glow README.md INSTALL.md CHANGELOG.md ``` -------------------------------- ### executeCLI Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Renders markdown source and outputs to writer with configured options. It reads source content, removes YAML frontmatter, initializes the Glamour renderer, and outputs the rendered markdown. ```APIDOC ## Function: executeCLI Renders markdown source and outputs to writer with configured options. ### Parameters: | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | src | *source | true | The markdown source to render | | w | io.Writer | true | Output writer | ### Return: `error` — nil on success ### Behavior: 1. Reads source content 2. Removes YAML frontmatter if present 3. Initializes Glamour renderer with configured style and width 4. Renders markdown to ANSI 5. Outputs to writer, pager, or TUI based on flags ### Example: ```go src, _ := sourceFromArg("README.md") deferrc src.reader.Close() executeCLI(cmd, src, os.Stdout) ``` ``` -------------------------------- ### config Command Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Opens the configuration file (`glow.yml`) in the user's default editor for editing. ```APIDOC ## config Command ### Description Opens the configuration file (`glow.yml`) in the user's `$EDITOR` for editing. The config file location follows the system's standard config directories. ### Method CLI Command ### Endpoint glow config ### Parameters This command does not accept any parameters. ### Request Example ```bash glow config ``` ### Response #### Success Response - **Editor** (string) - Opens the default text editor to the Glow configuration file. #### Response Example (Opens the user's default editor) ``` -------------------------------- ### Expand Tilde and Environment Variables in Path Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md This function expands tilde (~) to the user's home directory and resolves environment variables (e.g., $VAR) within a given path string. It returns the fully expanded absolute path. ```go path := utils.ExpandPath("~/.config/glow/style.json") // Result: "/home/user/.config/glow/style.json" ``` -------------------------------- ### Set Custom Pager Environment Variable Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Examples of setting the PAGER environment variable to use different command-line pagers like 'more', 'vim -', or 'less -i' for case-insensitive search. ```bash export PAGER="more" export PAGER="vim -" export PAGER="less -i" # Case-insensitive search ``` -------------------------------- ### CLI Processing Flow Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Illustrates the step-by-step process Glow follows for rendering markdown in CLI mode, from source to output destination. ```text sourceFromArg() ↓ Read content from source ↓ Remove YAML frontmatter ↓ Initialize Glamour renderer with: - Style (determined by -s flag or auto) - Width (determined by -w flag or detected) - Base URL (for relative links) ↓ Render markdown → ANSI string ↓ Output destination: ├─ stdout (default) ├─ pager (if -p) └─ TUI pager (if -t and file input) ``` -------------------------------- ### Override Configuration with Flags and Environment Variables Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Demonstrates the precedence of configuration settings: Defaults < Config File < CLI Flags < Environment Variables. Shows how environment variables override CLI flags. ```bash # Config: width: 80 # But flag overrides: glow -w 120 README.md # And env var would override flag: GLOW_WIDTH=150 glow -w 120 README.md # Result: width = 150 ``` -------------------------------- ### Cache Glow Rendered Output Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Cache the rendered output of Glow to speed up subsequent views of unchanged files. The example demonstrates writing to a cache file and only re-rendering if the source file is newer. ```bash # Cache rendered output glow README.md > /tmp/readme.cache if [ /tmp/readme.cache -nt README.md ]; then cat /tmp/readme.cache else glow README.md | tee /tmp/readme.cache fi ``` -------------------------------- ### CLI Mode: Error Handling Example Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Demonstrates error handling in CLI mode. If a file fails to process, an error message is printed to stderr, processing stops, and the exit code is non-zero. ```bash glow nonexistent.md && echo "Success" || echo "Failed" # prints: unable to open file: ... # exit code: 1 ``` -------------------------------- ### Execute CLI Rendering Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Renders markdown source to a writer with configured options. Use this function to process markdown content programmatically, handling frontmatter removal and Glamour styling. ```go func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error ``` ```go src, _ := sourceFromArg("README.md") defer src.reader.Close() executeCLI(cmd, src, os.Stdout) ``` -------------------------------- ### Create New UI Program Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Creates a new Bubble Tea program for the TUI with the specified configuration and content. Initializes the UI model and configures mouse support and alternate screen mode. ```go func NewProgram(cfg Config, content string) *tea.Program ``` ```go cfg := ui.Config{ Path: "./docs", GlamourMaxWidth: 100, ShowLineNumbers: true, } program := ui.NewProgram(cfg, "") if _, err := program.Run(); err != nil { log.Fatal(err) } ``` -------------------------------- ### Read from HTTP/HTTPS URLs Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md Use full HTTP or HTTPS URLs to fetch markdown content. Glow performs a GET request and checks for a 200 status code before processing the response body. ```bash glow https://example.com/README.md ``` ```bash glow http://raw.github.com/user/repo/main/README.md ``` -------------------------------- ### Render Markdown from GitHub Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Render a Markdown file directly from a GitHub repository. ```bash # Render from GitHub glow charmbracelet/glow ``` -------------------------------- ### Configure Custom Pager Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Set the PAGER environment variable to specify a custom pager. Glow will use this pager when the -p flag is used. Examples include 'less' with specific flags, 'vim', or 'bat' with themes. ```bash export PAGER="less -i -S" glow -p README.md ``` ```bash export PAGER="vim -" glow -p README.md ``` ```bash export PAGER="bat --theme=Dracula" glow -p README.md ``` -------------------------------- ### Command-line Aliases for Glow Styles and Sizes Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Provides command-line aliases for quick access to common Glow commands, including specific files like README.md, configuration, and documentation, as well as shortcuts for dark/light styles and wide/narrow outputs. ```bash # Quick reference alias grm='glow README.md' alias gcon='glow config' alias gdoc='glow docs' # Style shortcuts alias glow-dark='glow -s dark' alias glow-light='glow -s light' # Size shortcuts alias glow-wide='glow -w 120' alias glow-narrow='glow -w 60' ``` -------------------------------- ### Render Markdown from GitHub Repositories Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Render the README file from a specified GitHub repository. Supports private repositories if authenticated via git credentials. ```bash glow github.com/charmbracelet/glow glow charmbracelet/glow glow github://charmbracelet/glow ``` -------------------------------- ### Dispatcher for README URL Handling Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md Routes a given path to the appropriate handler based on its protocol or hostname. Handles github://, gitlab://, and generic URLs, adding a scheme if missing and routing to specific handlers for GitHub and GitLab. ```go func readmeURL(path string) (*source, error) ``` -------------------------------- ### Enable Mouse Support via Command Line Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/ui-components.md Alternatively, mouse wheel support can be enabled directly from the command line using the -m flag. This provides an alternative to configuration file settings. ```bash glow -m ``` -------------------------------- ### Browse Directory with Custom Style in TUI Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Launch Glow in TUI mode to browse a directory with a custom color style. ```bash # Browse with custom style glow -s dracula ./docs ``` -------------------------------- ### Apply Styles Source: https://github.com/charmbracelet/glow/blob/master/README.md Apply built-in or custom JSON styles to the output. ```bash glow -s [dark|light] ``` ```bash glow -s mystyle.json ``` -------------------------------- ### Browse Directory with Line Numbers in TUI Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Launch Glow in TUI mode to browse a directory, showing line numbers. ```bash # Browse with line numbers glow -l ./docs ``` -------------------------------- ### Browse Directory with Custom Width in TUI Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Launch Glow in TUI mode to browse a directory, setting a custom line width. ```bash # Browse with custom width glow -w 120 ./docs ``` -------------------------------- ### Process Man Pages as Markdown Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Pipe the output of a 'man' command to Glow to render man pages as markdown. ```bash man glow | glow ``` -------------------------------- ### Render Markdown from GitLab Projects Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Render the README file from a specified GitLab project. Supports private projects if authenticated and handles nested project paths. ```bash glow gitlab.com/owner/project glow gitlab.com/group/subgroup/project glow gitlab://owner/project ``` -------------------------------- ### README Rendering Check in CI Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md In CI/CD pipelines, use this script to verify that the README file renders without errors. ```bash #!/bin/bash # Check that README renders without errors glow README.md > /dev/null if [ $? -ne 0 ]; then echo "README rendering failed" exit 1 fi ``` -------------------------------- ### Interactive TUI Browsing Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Launch Glow in interactive TUI mode for browsing Markdown files. ```bash # Interactive browsing glow ``` -------------------------------- ### NewProgram Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Creates and returns a new Bubble Tea program for the TUI, initialized with the provided configuration and content. ```APIDOC ## Function: NewProgram Creates and returns a new Bubble Tea program for the TUI. ### Parameters: - **cfg** (Config) - true - — - TUI configuration - **content** (string) - false - — - Pre-loaded markdown content ### Return: - `*tea.Program` — A configured Bubble Tea program ready to run ### Behavior: - Initializes the UI model with provided config - Enables mouse support if cfg.EnableMouse is true - Configures alternate screen mode ### Example: ```go cfg := ui.Config{ Path: "./docs", GlamourMaxWidth: 100, ShowLineNumbers: true, } program := ui.NewProgram(cfg, "") if _, err := program.Run(); err != nil { log.Fatal(err) } ``` ``` -------------------------------- ### Launch TUI Application Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Launches the TUI application, allowing for interactive browsing of directories or displaying pre-loaded markdown content. Environment variables can configure pager and Glamour styling. ```go func runTUI(path string, content string) error ``` ```go if err := runTUI("./docs", ""); err != nil { log.Fatal(err) } ``` -------------------------------- ### Read from Directories Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md Specify a directory path to have Glow automatically enter TUI mode and search for a README file. It looks for common README filenames in a specific order. ```bash glow . glow ./docs glow /path/to/project ``` ```bash glow ``` -------------------------------- ### ExpandPath Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Expands tilde (~) and environment variables in a given path. It replaces '~' with the user's home directory and expands all '$VAR' environment variables, returning the expanded absolute path. ```APIDOC ## ExpandPath ### Description Expands tilde and environment variables in a path. ### Function Signature ```go func ExpandPath(path string) string ``` ### Parameters #### Path Parameters - **path** (string) - Required - Path with ~ or environment variables ### Return - **string** — Expanded absolute path ### Example ```go path := utils.ExpandPath("~/.config/glow/style.json") // Result: "/home/user/.config/glow/style.json" ``` ``` -------------------------------- ### runTUI Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Launches the TUI application. It can take a path to browse or pre-loaded markdown content. It also parses environment variables for debugging and configures the UI. ```APIDOC ## Function: runTUI Launches the TUI application. ### Parameters: | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | path | string | false | Directory or file path to browse | | content | string | false | Pre-loaded markdown content to display | ### Return: `error` — nil on success, error if TUI fails to run ### Behavior: - Parses environment variables for debugging options - Initializes UI config from flags and environment - Creates and runs Bubble Tea program - Validates and sets glamour style ### Environment Variables: - `GLOW_HIGH_PERFORMANCE_PAGER` (default: true): Enable high-performance rendering - `GLOW_ENABLE_GLAMOUR` (default: true): Enable Glamour styling - `GLAMOUR_STYLE`: Override glamour style ### Example: ```go if err := runTUI("./docs", ""); err != nil { log.Fatal(err) } ``` ``` -------------------------------- ### Root Command Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md The root command is the primary entry point for the Glow CLI. It accepts various source arguments for rendering markdown. ```APIDOC ## Root Command ### Description Primary entry point for Glow. Accepts a source argument that can be: - A file path (local markdown file) - A directory (searches for README files) - A URL (HTTP/HTTPS) - GitHub repository reference (e.g., `github.com/owner/repo`) - GitLab repository reference (e.g., `gitlab.com/owner/repo`) - `-` for stdin input ### Method CLI Command ### Endpoint glow [SOURCE|DIR] ### Parameters #### Path Parameters - **SOURCE|DIR** (string) - Required - The source of the markdown content (file, directory, URL, or repository). ### Flags #### Query Parameters - **--pager, -p** (bool) - Optional - Display output using a pager (less -r or $PAGER). - **--tui, -t** (bool) - Optional - Display using the TUI (textual user interface). - **--style, -s** (string) - Optional - Rendering style (dark, light, or path to JSON file). - **--width, -w** (uint) - Optional - Word-wrap width (0 = no limit, auto-detected if terminal). - **--all, -a** (bool) - Optional - Show hidden and ignored files (TUI-mode only). - **--line-numbers, -l** (bool) - Optional - Show line numbers (TUI-mode only). - **--preserve-new-lines, -n** (bool) - Optional - Preserve newlines in output. - **--mouse, -m** (bool) - Optional - Enable mouse wheel support (TUI-mode only, hidden flag). - **--config** (string) - Optional - Path to config file. ### Request Example ```bash glow README.md glow ./docs glow https://example.com/repo.md glow github.com/owner/repo ``` ### Response #### Success Response - **Output** (string) - Rendered markdown content. #### Response Example ```markdown # Hello World This is a **sample** markdown. ``` ``` -------------------------------- ### Shell Functions for File Viewing and Preview Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md A collection of shell functions for convenient file handling. Includes a `view` function for markdown/code, a `docs` function to browse project documentation, and a `preview` function for quick, narrow previews. ```bash # View any file (auto-detect markdown/code) view() { if [[ "$1" == *.md ]]; then glow "$1" else cat "$1" fi } # Browse project docs docs() { glow "${1:-.}" } # Quick preview preview() { glow -w 60 "$1" } ``` -------------------------------- ### Dark Terminal Configuration with Mouse Support Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md Configure for dark terminals, enabling mouse interaction and showing all files by default. Sets a custom width. ```yaml style: "dark" width: 100 mouse: true all: true ``` -------------------------------- ### Custom Glamour Style Configuration Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md Configure Glow to use a custom Glamour style by specifying the JSON file path in the config. Tilde expansion and environment variables are supported. ```yaml style: "$HOME/.config/glow/mystyle.json" ``` -------------------------------- ### Render Markdown to Stdout Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Basic command to render a Markdown file to standard output. ```bash # Render to stdout glow README.md ``` -------------------------------- ### CLI Mode: Multiple Files Output Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Details the behavior when multiple files are provided as arguments in CLI mode. Each file is rendered and output sequentially, with results concatenated. ```bash glow a.md b.md c.md ``` -------------------------------- ### Enable All Modes Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md Use the -a and -l flags to temporarily enable all modes for a single session. ```bash glow -a -l README.md ``` -------------------------------- ### Create New Pager Model Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/ui-components.md Initializes a new pager model. This function is used to set up the pager with its viewport and file watcher. ```go func newPagerModel(common *commonModel) pagerModel ``` -------------------------------- ### Enable Debug Logging via Config File Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md Enable detailed debug logging for Glow by adding 'debug: true' to the Glow configuration file. ```bash # Or via config file echo "debug: true" >> ~/.config/glow/glow.yml ``` -------------------------------- ### Render Multiple Markdown Files to HTML Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Render multiple Markdown files and redirect the combined output to an HTML file. ```bash # Render multiple files glow *.md > all.html ``` -------------------------------- ### man Command Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Generates and displays the manual page for Glow. ```APIDOC ## man Command ### Description Generates and displays the manual page for Glow. ### Method CLI Command ### Endpoint glow man ### Parameters This command does not accept any parameters. ### Request Example ```bash glow man ``` ### Response #### Success Response - **Manual Page** (string) - Displays the generated manual page for Glow. #### Response Example (Displays the Glow manual page in the terminal) ``` -------------------------------- ### Vim Integration for Markdown Viewing Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Vim mappings to view the current markdown file using Glow. Includes options for viewing with a pager and a custom command. ```vim " In ~/.vimrc " View markdown file with Glow map gm :!glow % " View in pager map gp :!glow -p % " Custom command command! Glow !glow % ``` -------------------------------- ### Check if loading is done Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/ui-components.md Use this method to determine if the file discovery process has completed. ```go func (m stashModel) loadingDone() bool ``` -------------------------------- ### Root Command Definition Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Defines the root command for the Glow CLI application. It specifies the command's usage, a short description, argument constraints, and the main execution function. ```go var rootCmd = &cobra.Command{ Use: "glow [SOURCE|DIR]", Short: "Render markdown on the CLI, with pizzazz!", Args: cobra.MaximumNArgs(1), RunE: execute, } ``` -------------------------------- ### Read from GitHub Repository URLs Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/source-resolution.md Provide GitHub repository paths in shorthand or full format to fetch the README. Glow uses the GitHub API to locate and download the README content. ```bash glow github.com/charmbracelet/glow glow github.charmbracelet/glow glow charmbracelet/glow ``` -------------------------------- ### Integrate Glow in Systemd Service Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Configure a systemd service unit to use Glow for rendering markdown files. ```bash # Use Glow in systemd service [Service] ExecStart=/usr/bin/glow /path/to/docs/ ``` -------------------------------- ### Browse Directory in TUI Mode Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Launch Glow in TUI mode to browse Markdown files within a specific directory. ```bash # Browse specific directory glow ./docs ``` -------------------------------- ### Execute Main Program Logic Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md The main execution function for processing arguments and running the appropriate output mode. It handles reading from stdin if piped, running the TUI on directories, or processing arguments as sources. ```go func execute(cmd *cobra.Command, args []string) error ``` -------------------------------- ### View Man Pages with Glow Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Render man pages as pretty markdown using Glow. An alias can be created for convenient access. ```bash # View man pages as pretty markdown man glow | glow - # Create alias for convenient access alias man-pretty='man "$1" | glow -s auto' man-pretty glow ``` -------------------------------- ### Glow Project Module Definition Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/README.md Defines the Go module path and required Go version for the Glow project. ```go module github.com/charmbracelet/glow/v2 go 1.25 ``` -------------------------------- ### Custom Style and Line Numbers Configuration Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/configuration.md Use this configuration to specify a custom style file path and enable line number display. ```yaml style: "/home/user/.config/glow/mytheme.json" width: 120 showLineNumbers: true ``` -------------------------------- ### Activate Stdin Mode in Glow Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md Shows how to activate Stdin Mode by explicitly using '-' as the input file, relying on auto-detection for piped input, or combining with other flags. ```bash # Explicit stdin marker echo "# Header" | glow - # Auto-detected piped input cat README.md | glow # With flags curl https://example.com/README.md | glow -w 100 -s dark ``` -------------------------------- ### Set Glow Configuration via Environment Variables Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Control Glow's behavior by setting environment variables. This includes styling, debugging, configuration paths, and pager settings. ```bash # Set style export GLAMOUR_STYLE=dark # Enable debugging export GLOW_DEBUG=true # Override config directory export GLOW_CONFIG_HOME=~/.config/glow # Custom pager export PAGER="less -R" ``` ```bash # Disable high-performance rendering for compatibility export GLOW_HIGH_PERFORMANCE_PAGER=false # Disable Glamour styling (plain output) export GLOW_ENABLE_GLAMOUR=false ``` -------------------------------- ### Render Markdown from HTTP/HTTPS URLs Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Fetch and render markdown content directly from web URLs. Glow handles fetching, validation, and preserves relative links. ```bash glow https://example.com/README.md glow https://raw.githubusercontent.com/user/repo/main/README.md ``` -------------------------------- ### TUI State Machine Transitions Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/cli-modes.md This diagram illustrates the state transitions within the Glow TUI, showing how users navigate between the file browser and document pager, and how to exit. ```text stateShowStash (file browser) ↓ (Enter key on file) stateShowDocument (document pager) ↓ (Esc key or q) stateShowStash (back to browser) ↓ (Ctrl+C or q in browser) Exit ``` -------------------------------- ### Config Command Declaration Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/api-reference.md Declares the configuration command for Glow. This command is used to open the Glow configuration file in the user's default editor. ```go var configCmd *cobra.Command ``` -------------------------------- ### Select Specific Styles Source: https://github.com/charmbracelet/glow/blob/master/_autodocs/usage-patterns.md Render markdown content using a predefined or custom visual style. Supports themes like dark, light, Dracula, or a custom JSON style. ```bash glow -s dark README.md # Dark theme glow -s light README.md # Light theme glow -s dracula README.md # Dracula theme glow -s custom.json README.md # Custom JSON style ```