### Development Setup and Commands in Bash Source: https://github.com/amscotti/glimmer/blob/main/CONTRIBUTING.md This snippet details the essential commands for setting up the Glimmer development environment. It includes cloning the repository, installing dependencies, running tests, linting, formatting, and building the project. These commands are crucial for local development and ensuring code quality. ```bash git clone https://github.com/your-username/glimmer cd glimmer shards install crystal spec bin/ameba crystal tool format make check shards build ``` -------------------------------- ### Install Glimmer from Source Source: https://github.com/amscotti/glimmer/blob/main/README.md Instructions to clone the Glimmer repository, navigate into the directory, and build the release version using Shards, Crystal's package manager. The final binary will be located in the 'bin/glimmer' path. ```bash git clone https://github.com/amscotti/glimmer cd glimmer shards build --release ``` -------------------------------- ### Glimmer Configuration File Example Source: https://github.com/amscotti/glimmer/blob/main/README.md An example of the Glimmer configuration file (`~/.config/glimmer/glimmer.yml`). It shows settings for style (auto, dark, light, ascii), width, and pager preference. Setting width to 0 enables automatic detection. ```yaml # Glimmer configuration file # Available styles: auto, dark, light, ascii # Set width to 0 for automatic detection style: auto width: 0 pager: false ``` -------------------------------- ### Glimmer Library: Choosing a Theme Source: https://github.com/amscotti/glimmer/blob/main/README.md Crystal code example showing how to instantiate the `TermRenderer` with the dark theme, which is suitable for dark terminal backgrounds. This is the default theme if none is explicitly provided. ```crystal # Dark theme (default) - for dark terminal backgrounds renderer = Glimmer::Renderer::TermRenderer.new(theme: Glimmer::Style::Theme.dark) ``` -------------------------------- ### Enable Syntax Highlighting for Multiple Languages with Glimmer Source: https://context7.com/amscotti/glimmer/llms.txt Shows how to use Glimmer's LexerRegistry to get lexers for various programming languages (e.g., Ruby, JavaScript, Python) and then tokenize and format code snippets. It also demonstrates how Glimmer automatically highlights code in Markdown fenced blocks. ```crystal require "glimmer" # Get a lexer for a specific language ruby_lexer = Glimmer::Highlight::LexerRegistry.for_language("ruby") js_lexer = Glimmer::Highlight::LexerRegistry.for_language("javascript") python_lexer = Glimmer::Highlight::LexerRegistry.for_language("python") # Supported language aliases crystal_lexer = Glimmer::Highlight::LexerRegistry.for_language("cr") # "crystal" or "cr" shell_lexer = Glimmer::Highlight::LexerRegistry.for_language("bash") # "shell", "bash", "sh", "zsh" typescript_lexer = Glimmer::Highlight::LexerRegistry.for_language("ts") # "typescript" or "ts" # Tokenize and format code directly code = <<-CODE def fibonacci(n) return n if n <= 1 fibonacci(n - 1) + fibonacci(n - 2) end puts fibonacci(10) CODE if lexer = ruby_lexer tokens = lexer.tokenize(code) highlighted = Glimmer::Highlight::Formatter.format( tokens, Glimmer::Style::Theme.dark, Glimmer::Style::ColorProfile::TrueColor ) puts highlighted end # Languages are automatically highlighted in fenced code blocks markdown_with_code = <<-MD ```python def greet(name: str) -> str: return f"Hello, {name}!" print(greet("World")) ``` MD renderer = Glimmer::Renderer::TermRenderer.new puts renderer.render(markdown_with_code) ``` -------------------------------- ### Add Glimmer Dependency to Crystal Shard Source: https://github.com/amscotti/glimmer/blob/main/README.md Instructions for adding Glimmer as a dependency to a Crystal project by modifying the `shard.yml` file. After adding the dependency, run `shards install` to fetch it. ```yaml dependencies: glimmer: github: amscotti/glimmer ``` -------------------------------- ### Read from Standard Input Source: https://context7.com/amscotti/glimmer/llms.txt Shows how to initialize a StdinSource to read and render Markdown content piped into the application. ```crystal require "glimmer" source = Glimmer::Source::StdinSource.new content = source.read renderer = Glimmer::Renderer::TermRenderer.new puts renderer.render(content) ``` -------------------------------- ### Development and Build Commands Source: https://github.com/amscotti/glimmer/blob/main/README.md Standard shell commands for setting up the environment, running tests, linting, and building the Glimmer project. ```bash git clone https://github.com/amscotti/glimmer cd glimmer shards install crystal spec bin/ameba crystal tool format make check shards build shards build --release ``` -------------------------------- ### Basic Glimmer Command-Line Usage Source: https://github.com/amscotti/glimmer/blob/main/README.md Demonstrates fundamental ways to use the Glimmer command-line tool. This includes rendering a local markdown file, reading from standard input, fetching content from GitHub, applying a specific theme, setting the output width, and utilizing the system pager. ```bash # Render a markdown file glimmer README.md # Read from stdin echo "# Hello World" | glimmer - # Fetch from GitHub glimmer github.com/crystal-lang/crystal # Use a specific theme glimmer -s light README.md # Set custom width (default is 78) glimmer -w 60 README.md # Use system pager glimmer -p README.md ``` -------------------------------- ### CLI Usage Patterns Source: https://context7.com/amscotti/glimmer/llms.txt Common command-line interface commands for rendering Markdown, managing themes, and configuring the application. ```bash glimmer README.md echo "# Hello\n\nWorld" | glimmer - glimmer -s dark README.md glimmer -w 120 README.md glimmer -p README.md glimmer github.com/crystal-lang/crystal glimmer glimmer config ``` -------------------------------- ### Apply Built-in Themes Source: https://context7.com/amscotti/glimmer/llms.txt Shows how to switch between Glimmer's built-in themes (dark, light, and ascii) to adjust the visual output for different terminal environments. ```crystal require "glimmer" dark_renderer = Glimmer::Renderer::TermRenderer.new( theme: Glimmer::Style::Theme.dark ) light_renderer = Glimmer::Renderer::TermRenderer.new( theme: Glimmer::Style::Theme.light ) ascii_renderer = Glimmer::Renderer::TermRenderer.new( theme: Glimmer::Style::Theme.ascii ) markdown = "# Title\n\nHello :wave: **world**!" puts "=== Dark Theme ===" puts dark_renderer.render(markdown) puts "\n=== Light Theme ===" puts light_renderer.render(markdown) puts "\n=== ASCII Theme ===" puts ascii_renderer.render(markdown) ``` -------------------------------- ### Run Glimmer Locally Source: https://github.com/amscotti/glimmer/blob/main/README.md Execute the Glimmer CLI to render a markdown file directly from the source or via the compiled binary. ```bash crystal run src/glimmer/cli.cr -- README.md ./bin/glimmer README.md ``` -------------------------------- ### Detect and Read Markdown Sources Source: https://context7.com/amscotti/glimmer/llms.txt Demonstrates how to programmatically detect the type of input source (URL, file, or stdin) and render its content to the terminal. ```ruby input = "github.com/amscotti/glimmer" case Glimmer::Source::URLSource.detect_source(input) when :stdin puts "Reading from stdin" when :url source = Glimmer::Source::URLSource.new(input) content = source.read puts Glimmer::Renderer::TermRenderer.new.render(content) when :file source = Glimmer::Source::FileSource.new(input) content = source.read puts Glimmer::Renderer::TermRenderer.new.render(content) end ``` -------------------------------- ### Render Markdown to ANSI with TermRenderer Source: https://context7.com/amscotti/glimmer/llms.txt Demonstrates how to initialize the TermRenderer with specific themes, widths, and color profiles to convert Markdown strings or parsed documents into styled terminal output. ```crystal require "glimmer" markdown = <<-MD # Hello World This is **bold** and *italic* text with `inline code`. ```ruby def greet(name) puts "Hello, #{name}!" end ``` - List item one - List item two - Nested item MD renderer = Glimmer::Renderer::TermRenderer.new( theme: Glimmer::Style::Theme.dark, width: 80, profile: Glimmer::Style::ColorProfile.detect, expand_emojis: true ) output = renderer.render(markdown) puts output options = Markd::Options.new(smart: true, gfm: true) document = Markd::Parser.parse(markdown, options) output = renderer.render(document) puts output ``` -------------------------------- ### Launch Interactive TUI Mode Source: https://context7.com/amscotti/glimmer/llms.txt Programmatically initializes and runs the Glimmer TUI application for interactive file navigation and reading. ```crystal require "glimmer" app = Glimmer::TUI::App.new( start_dir: Dir.current, theme: Glimmer::Style::Theme.dark ) app.run ``` -------------------------------- ### Fetch Markdown from URLs with Glimmer's URLSource Source: https://context7.com/amscotti/glimmer/llms.txt Explains how to use Glimmer::Source::URLSource to fetch Markdown content from web URLs. It supports direct URLs, GitHub/GitLab repository shorthand, specific branches, and specific files within repositories. ```crystal require "glimmer" # Fetch from a direct URL url_source = Glimmer::Source::URLSource.new("https://example.com/README.md") # GitHub repository shorthand - automatically fetches README.md github_source = Glimmer::Source::URLSource.new("github.com/crystal-lang/crystal") # GitHub with specific branch branch_source = Glimmer::Source::URLSource.new( "https://github.com/user/repo/tree/develop" ) # GitHub specific file file_source = Glimmer::Source::URLSource.new( "https://github.com/user/repo/blob/main/docs/guide.md" ) # GitLab support works similarly gitlab_source = Glimmer::Source::URLSource.new("gitlab.com/user/project") ``` -------------------------------- ### Basic Markdown Rendering with Glimmer Library Source: https://github.com/amscotti/glimmer/blob/main/README.md A Crystal code snippet demonstrating how to use the Glimmer library for basic markdown rendering. It initializes a `TermRenderer` with a dark theme and a specified width, then renders a simple markdown string. ```crystal require "glimmer" markdown = "# Hello World\n\nThis is **bold** and *italic* text." renderer = Glimmer::Renderer::TermRenderer.new( theme: Glimmer::Style::Theme.dark, width: 80 ) puts renderer.render(markdown) ``` -------------------------------- ### Manage Application Configuration Source: https://context7.com/amscotti/glimmer/llms.txt Handles loading, modifying, and saving persistent YAML configuration settings for the Glimmer application. ```crystal require "glimmer" config = Glimmer::CLI::Config.load puts "Style: #{config.style}" puts "Width: #{config.width}" puts "Pager: #{config.pager?}" config.style = "dark" config.width = 100 config.pager = true config.save Glimmer::CLI::Config.create_default Glimmer::CLI::Config.open_in_editor ``` -------------------------------- ### Configure Terminal Color Profiles with Glimmer Source: https://context7.com/amscotti/glimmer/llms.txt Demonstrates how to initialize Glimmer's TermRenderer with different color profiles (TrueColor, ANSI256, ANSI, Ascii) to control the color output in the terminal. It renders a Markdown string using the TrueColor profile. ```ruby truecolor_renderer = Glimmer::Renderer::TermRenderer.new( profile: Glimmer::Style::ColorProfile::TrueColor # 24-bit color ) ansi256_renderer = Glimmer::Renderer::TermRenderer.new( profile: Glimmer::Style::ColorProfile::ANSI256 # 256 colors ) ansi_renderer = Glimmer::Renderer::TermRenderer.new( profile: Glimmer::Style::ColorProfile::ANSI # 16 colors ) ascii_renderer = Glimmer::Renderer::TermRenderer.new( profile: Glimmer::Style::ColorProfile::Ascii # No colors ) markdown = "# Hello\n\nThis is **bold** with `code`." puts truecolor_renderer.render(markdown) ``` -------------------------------- ### Read Markdown from Local Files with Glimmer's FileSource Source: https://context7.com/amscotti/glimmer/llms.txt Illustrates how to use Glimmer::Source::FileSource to read Markdown content from a local file path. It includes validation to check if the file is readable before attempting to read and render its content. ```crystal require "glimmer" # Read from a local file source = Glimmer::Source::FileSource.new("README.md") if source.valid? content = source.read renderer = Glimmer::Renderer::TermRenderer.new puts renderer.render(content) else puts "Cannot read file: #{source.name}" end ``` -------------------------------- ### Build Custom Styles with StylePrimitive Source: https://context7.com/amscotti/glimmer/llms.txt Utilizes the fluent StylePrimitive API to create custom text styles, including foreground/background colors, text decorations, and prefix/suffix additions. It also demonstrates how to merge multiple styles. ```crystal require "glimmer" custom_style = Glimmer::Style::StylePrimitive.new .with_foreground(Glimmer::Style::ANSI256Color.new(39)) .with_background(Glimmer::Style::ANSI256Color.new(236)) .with_bold .with_prefix(">> ") .with_suffix(" <<") profile = Glimmer::Style::ColorProfile::TrueColor styled_text = custom_style.render("Important message", profile) puts styled_text truecolor_style = Glimmer::Style::StylePrimitive.new .with_foreground(Glimmer::Style::TrueColor.new(255, 100, 50)) .with_italic .with_underline puts truecolor_style.render("TrueColor styled text", profile) base_style = Glimmer::Style::StylePrimitive.new.with_bold accent_style = Glimmer::Style::StylePrimitive.new .with_foreground(Glimmer::Style::ANSI256Color.new(203)) .with_italic combined = base_style.merge(accent_style) puts combined.render("Combined styles", profile) ``` -------------------------------- ### Expand Emoji Shortcodes to Unicode with Glimmer Source: https://context7.com/amscotti/glimmer/llms.txt Demonstrates the Glimmer::Emoji.expand method for converting text-based emoji shortcodes (e.g., :smile:) into their corresponding Unicode characters. It also shows how emoji expansion is enabled by default in TermRenderer and can be optionally disabled. ```crystal require "glimmer" # Expand emoji shortcodes in text text = "Hello :wave: Welcome to Glimmer :sparkles:" expanded = Glimmer::Emoji.expand(text) puts expanded # => "Hello 👋 Welcome to Glimmer ✨" # Common shortcodes examples = [ ":+1:", # 👍 ":heart:", # ❤️ ":rocket:", # 🚀 ":fire:", # 🔥 ":star:", # ⭐ ":coffee:", # ☕ ":warning:", # ⚠️ ":white_check_mark:", # ✅ ] examples.each do |shortcode| puts "#{shortcode} => #{Glimmer::Emoji.expand(shortcode)}" end # Emoji expansion is enabled by default in TermRenderer renderer = Glimmer::Renderer::TermRenderer.new(expand_emojis: true) markdown = "# :rocket: Getting Started\n\n:point_right: Read the docs!" puts renderer.render(markdown) # Disable emoji expansion if needed renderer_no_emoji = Glimmer::Renderer::TermRenderer.new(expand_emojis: false) puts renderer_no_emoji.render(markdown) # Keeps :rocket: as-is ``` -------------------------------- ### Configure Terminal Renderer Themes Source: https://github.com/amscotti/glimmer/blob/main/README.md Initialize the Glimmer TermRenderer with specific visual themes such as light or ascii modes. ```crystal renderer = Glimmer::Renderer::TermRenderer.new(theme: Glimmer::Style::Theme.light) renderer = Glimmer::Renderer::TermRenderer.new(theme: Glimmer::Style::Theme.ascii) ``` -------------------------------- ### Launch Glimmer TUI Mode Source: https://github.com/amscotti/glimmer/blob/main/README.md Command to launch Glimmer in its interactive Terminal User Interface (TUI) mode. This mode provides a file browser for navigating markdown files and a pager for reading them, with support for vim-style keybindings. ```bash glimmer ``` -------------------------------- ### Detect Terminal Color Capabilities Source: https://context7.com/amscotti/glimmer/llms.txt Illustrates how to automatically detect the host terminal's color support level using the ColorProfile utility. ```crystal require "glimmer" profile = Glimmer::Style::ColorProfile.detect puts "Detected profile: #{profile}" ``` -------------------------------- ### Render Markdown and Syntax Highlighting Source: https://github.com/amscotti/glimmer/blob/main/README.md Render markdown strings with automatic syntax highlighting or manually invoke the lexer and formatter for specific code blocks. ```crystal markdown = <<-MD ```ruby def greet(name) puts "Hello, #{name}!" end ``` MD renderer = Glimmer::Renderer::TermRenderer.new puts renderer.render(markdown) code = "def hello; puts 'hi'; end" lexer = Glimmer::Highlight::LexerRegistry.for_language("ruby") if lexer tokens = lexer.tokenize(code) output = Glimmer::Highlight::Formatter.format( tokens, Glimmer::Style::Theme.dark, Glimmer::Style::ColorProfile::TrueColor ) puts output end ``` -------------------------------- ### Wrap Text with ANSI Support Source: https://context7.com/amscotti/glimmer/llms.txt Utilizes the WordWrapper class to format text to a specific width while preserving ANSI escape sequences for styling. ```crystal require "glimmer" wrapper = Glimmer::Renderer::WordWrapper.new(width: 40, break_long_words: true) text = "This is a long paragraph that needs to be wrapped to fit within the specified width limit." lines = wrapper.wrap(text) lines.each { |line| puts line } styled_text = "\e[1mBold text\e[0m and \e[32mgreen text\e[0m in a long line" wrapped = wrapper.wrap(styled_text) wrapped.each { |line| puts line } ``` -------------------------------- ### Expand Emoji Shortcodes Source: https://github.com/amscotti/glimmer/blob/main/README.md Convert emoji shortcodes within a string into their corresponding unicode characters using the Glimmer::Emoji module. ```crystal text = "Hello :wave: welcome :rocket:" puts Glimmer::Emoji.expand(text) ``` -------------------------------- ### Control Terminal Color Profiles Source: https://github.com/amscotti/glimmer/blob/main/README.md Override default terminal color detection by forcing specific color profiles like ANSI256, TrueColor, or ASCII. ```crystal renderer = Glimmer::Renderer::TermRenderer.new(profile: Glimmer::Style::ColorProfile::ANSI256) renderer = Glimmer::Renderer::TermRenderer.new(profile: Glimmer::Style::ColorProfile::TrueColor) renderer = Glimmer::Renderer::TermRenderer.new(profile: Glimmer::Style::ColorProfile::Ascii) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.