### Install TTY::Box Gem Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Instructions for installing the TTY::Box gem using Bundler or directly via the gem command. This is the first step to using the library in a Ruby project. ```ruby gem "tty-box" ``` ```bash $ bundle ``` ```bash $ gem install tty-box ``` -------------------------------- ### Message Dashboard Example with TTY::Box Source: https://context7.com/piotrmurach/tty-box/llms.txt An example of combining different TTY::Box message types (info, success, warn, error) to create a dashboard-like display in the terminal. This showcases layout capabilities with positioning. ```ruby require "tty-box" print TTY::Cursor.clear_screen # Create a dashboard with all message types puts TTY::Box.info("Deploying application", top: 2, left: 2) puts TTY::Box.success("Tests passed", top: 2, left: 29) puts TTY::Box.warn("Memory usage high", top: 8, left: 2) puts TTY::Box.error("Build failed", top: 8, left: 29) puts ``` -------------------------------- ### Position Boxes Absolutely with TTY::Box.frame (Ruby) Source: https://context7.com/piotrmurach/tty-box/llms.txt Illustrates how to use `top` and `left` options with `TTY::Box.frame` to position boxes at specific coordinates within the terminal. It also shows an example of combining multiple positioned boxes. ```ruby require "tty-box" # Position box at row 5, column 10 box = TTY::Box.frame( top: 5, left: 10, width: 20, height: 5 ) { "Positioned box" } print box # Multiple positioned boxes (for window-like layouts) print TTY::Cursor.clear_screen box1 = TTY::Box.frame( top: 2, left: 10, width: 30, height: 10, border: :thick, align: :center, padding: 3, title: { top_left: " file1 " }, style: { fg: :bright_yellow, bg: :blue, border: { fg: :bright_yellow, bg: :blue } } ) { "Drawing a box in terminal emulator" } box2 = TTY::Box.frame( top: 8, left: 34, width: 30, height: 10, border: :thick, align: :center, padding: 3, title: { top_left: " file2 " }, style: { fg: :bright_yellow, bg: :blue, border: { fg: :bright_yellow, bg: :blue } } ) { "Drawing a box in terminal emulator" } puts box1 + box2 ``` -------------------------------- ### Draw Basic Box with TTY::Box Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Demonstrates how to draw a simple box in the terminal using the TTY::Box gem. It shows the basic usage of the `frame` method with string content and how to print the resulting box. ```ruby box = TTY::Box.frame "Drawing a box in", "terminal emulator", padding: 3, align: :center print box ``` -------------------------------- ### Setting TTY-Box Dimensions Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Explains how to define the size of a TTY-Box using `:width` and `:height` keyword arguments. It also shows how to dynamically set dimensions based on terminal size using `tty-screen`. ```ruby TTY::Box.frame(width: 30, height: 10) ``` ```ruby TTY::Box.frame(width: TTY::Screen.width, height: TTY::Screen.height) ``` -------------------------------- ### Create Info Box with TTY::Box Source: https://context7.com/piotrmurach/tty-box/llms.txt Demonstrates how to create basic, positioned, and custom-width info boxes using TTY::Box.info. This is useful for displaying general information or status updates. ```ruby require "tty-box" # Basic info box box = TTY::Box.info("Deploying application") print box # Output: # ╔ ℹ INFO ═══════════════╗ # ║ ║ # ║ Deploying application ║ # ║ ║ # ╚═══════════════════════╝ # Positioned info box box = TTY::Box.info("Deploying application", top: 2, left: 2) print box # Custom width info box box = TTY::Box.info("System update available", width: 40) print box ``` -------------------------------- ### TTY::Box Frame with Colors and Styling Source: https://context7.com/piotrmurach/tty-box/llms.txt Demonstrates applying foreground and background colors to TTY::Box frames using the `style` option. It covers full styling, forcing color output, and using different colors for content and borders. The 'tty-box' gem is required. ```ruby require "tty-box" # Full styling with MS-DOS look box = TTY::Box.frame( width: 30, height: 10, align: :center, padding: 3, style: { fg: :bright_yellow, bg: :blue, border: { fg: :bright_yellow, bg: :blue } } ) { "Drawing a box in terminal emulator" } print box # Force color output (useful for CI/piped output) box = TTY::Box.frame( enable_color: true, width: 20, height: 5, style: { fg: :white, bg: :green, border: { fg: :white, bg: :green } } ) { "Forced colors" } print box # Different content and border colors box = TTY::Box.frame( width: 25, height: 6, style: { fg: :black, bg: :white, border: { fg: :red, bg: :white } } ) { "Red border, black text" } print box ``` -------------------------------- ### Positioning a TTY-Box Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Demonstrates how to position a TTY-Box absolutely within the terminal window using `:top` and `:left` keyword arguments. This allows precise placement of the box from the top-left corner. ```ruby TTY::Box.frame(top: 5, left: 10) ``` -------------------------------- ### Styling TTY-Box Content and Borders Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Shows how to apply foreground (`:fg`) and background (`:bg`) styles to both the content and borders of a TTY-Box. It also covers forcing color output with `enable_color`. ```ruby style: { fg: :bright_yellow, bg: :blue, border: { fg: :bright_yellow, bg: :blue } } ``` ```ruby TTY::Box.frame({ enable_color: true, # force to always color output style: { border: { fg: :bright_yellow, bg: :blue } } }) ``` -------------------------------- ### Create Box with Dimensions and Block Content Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Demonstrates creating a TTY::Box with specified dimensions (width and height) and populating it with content provided via a block. The content will be wrapped and displayed within the defined box size. ```ruby box = TTY::Box.frame(width: 30, height: 10) do "Drawin a box in terminal emulator" end print box ``` -------------------------------- ### Create Empty Box with Specific Dimensions Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Shows how to create an empty TTY::Box with predefined width and height using the `frame` method. This is useful when you need a box of a certain size without initial content, potentially for later population using cursor positioning. ```ruby box = TTY::Box.frame(width: 30, height: 10) print box ``` -------------------------------- ### Draw Box with Multi-Line Content (Separate Args) Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Shows how to create a TTY::Box with multi-line content by passing each line as a separate string argument to the `frame` method. ```ruby print TTY::Box.frame "Hello", "world!" ``` -------------------------------- ### Display Info Message Box with TTY-Box Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Shows how to create an information-style message box using the `TTY::Box.info` method. This is useful for displaying standard informational messages to the user. ```ruby box = TTY::Box.info("Deploying application") print box ``` -------------------------------- ### Display Warning Message Box with TTY-Box Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Demonstrates how to create a warning-style message box using the `TTY::Box.warn` method. This is suitable for highlighting potential issues or non-critical alerts. ```ruby box = TTY::Box.warn("Deploying application") print box ``` -------------------------------- ### Create Fixed Size Boxes with TTY::Box.frame (Ruby) Source: https://context7.com/piotrmurach/tty-box/llms.txt Shows how to create boxes with specified `width` and `height` using `TTY::Box.frame`. This allows for fixed-size containers where content can wrap. It also mentions integration with `tty-screen` for full terminal dimensions. ```ruby require "tty-box" # Empty box with fixed dimensions box = TTY::Box.frame(width: 30, height: 10) print box # Fixed dimensions with content (auto-wraps) box = TTY::Box.frame(width: 30, height: 10) do "Drawing a box in terminal emulator" end print box # Using tty-screen for full terminal width (requires tty-screen gem) # box = TTY::Box.frame(width: TTY::Screen.width, height: TTY::Screen.height) ``` -------------------------------- ### TTY::Box.info - Information Message Box Source: https://context7.com/piotrmurach/tty-box/llms.txt Demonstrates how to create an information-style message box using `TTY::Box.info`. This box features a blue background and an info icon. It accepts the same customization options as `TTY::Box.frame`. The 'tty-box' gem is required. ```ruby require "tty-box" # Example usage of TTY::Box.info would go here. # For instance: # box = TTY::Box.info("This is an informational message.") # print box ``` -------------------------------- ### Format TTY-Box Content with Padding Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Illustrates how to add padding around content within a TTY-Box frame using the `:padding` keyword. Padding can be specified as a single value for uniform padding or an array for specific top/bottom and left/right padding. ```ruby box = TTY::Box.frame(width: 30, height: 10, align: :center, padding: 3) do "Drawing a box in terminal emulator" end ``` -------------------------------- ### Draw Basic Box with TTY::Box.frame (Ruby) Source: https://context7.com/piotrmurach/tty-box/llms.txt Demonstrates the basic usage of the `TTY::Box.frame` method to draw boxes with string content, multi-line strings, block content, and newlines. The box automatically sizes to fit the content. ```ruby require "tty-box" # Simple box with string content box = TTY::Box.frame("Hello world!") print box # Multi-line content using multiple arguments box = TTY::Box.frame("Line one", "Line two", "Line three") print box # Using a block for content box = TTY::Box.frame { "Content from block" } print box # Multi-line using newlines box = TTY::Box.frame("First line\nSecond line\nThird line") print box ``` -------------------------------- ### Format TTY-Box Content with Alignment Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Demonstrates how to center-align content within a TTY-Box frame using the `:align` keyword. This feature allows for precise control over the horizontal positioning of text inside the box. ```ruby box = TTY::Box.frame(width: 30, height: 10, align: :center) do "Drawing a box in terminal emulator" end ``` -------------------------------- ### Draw Box with Block Content Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Explains how to use a block with the `TTY::Box.frame` method to define the content of the box. This provides an alternative way to specify text that will be rendered inside the box. ```ruby print TTY::Box.frame { "Hello world!" } ``` -------------------------------- ### Display Success Message Box with TTY-Box Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Illustrates how to create a success-style message box using the `TTY::Box.success` method. This is ideal for confirming the completion of a task or operation. ```ruby box = TTY::Box.success("Deploying application") print box ``` -------------------------------- ### TTY::Box Frame with Border Styles Source: https://context7.com/piotrmurach/tty-box/llms.txt Shows how to use different border styles for TTY::Box frames, including `:light` (default), `:thick`, and `:ascii`. It also illustrates customizing individual border segments and disabling borders. The 'tty-box' gem is required. ```ruby require "tty-box" # Thick border style box = TTY::Box.frame(width: 30, height: 5, border: :thick) print box # ASCII border style box = TTY::Box.frame(width: 30, height: 5, border: :ascii) print box # Custom corners using cross character box = TTY::Box.frame( width: 15, height: 4, border: { top_left: :cross, top_right: :cross, bottom_left: :cross, bottom_right: :cross } ) print box # Remove bottom border box = TTY::Box.frame( width: 30, height: 5, border: { type: :thick, bottom: false } ) print box # Connected boxes (removing shared border) box1 = TTY::Box.frame( top: 3, left: 10, width: 15, height: 5, border: { type: :thick, right: false }, align: :center, padding: [1, 2], style: { bg: :red, border: { bg: :red } } ) { "Space" } box2 = TTY::Box.frame( top: 3, left: 25, width: 15, height: 5, border: { type: :thick, top_left: :divider_down, bottom_left: :divider_up }, align: :center, padding: [1, 2], style: { bg: :red, border: { bg: :red } } ) { "Invaders!" } puts box1 + box2 ``` -------------------------------- ### TTY::Box Frame with Alignment and Padding Source: https://context7.com/piotrmurach/tty-box/llms.txt Explains how to control text alignment (`:left`, `:center`, `:right`) and apply padding to content within TTY::Box frames. Padding can be uniform or asymmetric. The 'tty-box' gem is required. ```ruby require "tty-box" # Center-aligned content box = TTY::Box.frame( width: 30, height: 10, align: :center ) { "Drawing a box in terminal emulator" } print box # Right-aligned content box = TTY::Box.frame( width: 30, height: 5, align: :right ) { "Right aligned" } print box # Uniform padding (all sides) box = TTY::Box.frame( width: 30, height: 10, align: :center, padding: 3 ) { "Drawing a box in terminal emulator" } print box # Asymmetric padding [top, right, bottom, left] or [vertical, horizontal] box = TTY::Box.frame( width: 29, height: 7, align: :center, padding: [1, 3] # 1 line top/bottom, 3 spaces left/right ) { "Closes #360\r\n\r\nCloses !217" } print box # Detailed padding box = TTY::Box.frame( width: 30, height: 8, padding: [1, 3, 1, 3] # top: 1, right: 3, bottom: 1, left: 3 ) { "Padded content" } print box ``` -------------------------------- ### Draw Box with Multi-Line Content (Newline Chars) Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Demonstrates creating a TTY::Box with multi-line content by including newline characters (`\n`) within a single string argument to the `frame` method. ```ruby print TTY::Box.frame "Hello\nworld!" ``` -------------------------------- ### Create TTY::Box Frame with Multiple Titles Source: https://context7.com/piotrmurach/tty-box/llms.txt Demonstrates creating a TTY::Box frame with titles positioned at the top-left, top-center, top-right, and bottom-center. It requires the 'tty-box' gem and outputs a framed box with specified dimensions and content. ```ruby require "tty-box" box = TTY::Box.frame( width: 40, height: 8, title: { top_left: " Menu ", top_center: " Navigation ", top_right: " Help ", bottom_center: " Press Q to quit " } ) { "Select an option..." } print box ``` -------------------------------- ### Draw Box with Single Line Content Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Illustrates drawing a terminal box with a single line of text content using TTY::Box. The `frame` method automatically creates a border around the provided string. ```ruby print TTY::Box.frame "Hello world!" ``` -------------------------------- ### Create Warning Box with TTY::Box Source: https://context7.com/piotrmurach/tty-box/llms.txt Shows how to generate warning messages using TTY::Box.warn. These boxes have a yellow background and a warning icon, ideal for alerting users to potential issues. ```ruby require "tty-box" # Basic warning box box = TTY::Box.warn("Deploying application") print box # Output: # ╔ ⚠ WARNING ════════════╗ # ║ ║ # ║ Deploying application ║ # ║ ║ # ╚═══════════════════════╝ # Positioned warning box box = TTY::Box.warn("Low disk space", top: 8, left: 2) print box # Warning with custom styling override box = TTY::Box.warn( "Configuration missing", style: { fg: :black, bg: :yellow, border: { fg: :black, bg: :yellow } } ) print box ``` -------------------------------- ### Create Success Box with TTY::Box Source: https://context7.com/piotrmurach/tty-box/llms.txt Illustrates creating success-style message boxes using TTY::Box.success. These boxes feature a green background and a checkmark icon, suitable for indicating successful operations. ```ruby require "tty-box" # Basic success box box = TTY::Box.success("Deploying application") print box # Output: # ╔ ✔ OK ═════════════════╗ # ║ ║ # ║ Deploying application ║ # ║ ║ # ╚═══════════════════════╝ # Positioned success box box = TTY::Box.success("Deployment complete!", top: 2, left: 29) print box # Multi-line success message box = TTY::Box.success("Build completed\nAll tests passed\n42 files processed") print box ``` -------------------------------- ### Configuring TTY-Box Borders Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Details how to change the border style of a TTY-Box using the `:border` keyword. It covers predefined types like `:ascii`, `:light`, `:thick`, and selective customization of border parts. ```ruby box = TTY::Box.frame(width: 30, height: 10, border: :thick) print box ``` ```ruby box = TTY::Box.frame( width: 10, height: 4, border: { top_left: :cross, top_right: :cross, bottom_left: :cross, bottom_right: :cross } ) print box ``` ```ruby TTY::Box.frame( width: 30, height: 10, border: { type: :thick, bottom: false } ) ``` -------------------------------- ### Display Error Message Box with TTY-Box Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Shows how to create an error-style message box using the `TTY::Box.error` method. This is essential for clearly indicating that an error has occurred. ```ruby box = TTY::Box.error("Deploying application") print box ``` -------------------------------- ### Adding Titles to TTY-Box Source: https://github.com/piotrmurach/tty-box/blob/master/README.md Illustrates how to add titles to a TTY-Box using the `:title` keyword argument. Titles can be placed at various positions like `:top_left`, `:top_center`, `:top_right`, etc. ```ruby box = TTY::Box.frame(width: 30, height: 10, title: {top_left: "TITLE", bottom_right: "v1.0"}) print box ``` -------------------------------- ### Create Error Box with TTY::Box Source: https://context7.com/piotrmurach/tty-box/llms.txt Demonstrates the creation of error messages using TTY::Box.error. These boxes use a red background and an error icon, suitable for highlighting critical failures. ```ruby require "tty-box" # Basic error box box = TTY::Box.error("Deploying application") print box # Output: # ╔ ⨯ ERROR ══════════════╗ # ║ ║ # ║ Deploying application ║ # ║ ║ # ╚═══════════════════════╝ # Positioned error box box = TTY::Box.error("Connection failed", top: 8, left: 29) print box # Error with additional context box = TTY::Box.error("Failed to connect to database\nError code: 1045\nAccess denied") print box ``` -------------------------------- ### Add Titles to Boxes with TTY::Box.frame (Ruby) Source: https://context7.com/piotrmurach/tty-box/llms.txt Demonstrates how to add titles to boxes using the `title` option in `TTY::Box.frame`. It supports six positions: `top_left`, `top_center`, `top_right`, `bottom_left`, `bottom_center`, and `bottom_right`. ```ruby require "tty-box" # Titles at top-left and bottom-right box = TTY::Box.frame( width: 30, height: 10, title: { top_left: "TITLE", bottom_right: "v1.0" } ) print box ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.