### Install CLI UI Gem Source: https://github.com/shopify/cli-ui/blob/main/README.md Instructions for installing the CLI UI gem using `gem install` or by adding it to your Gemfile. After installation, you typically need to require the library in your Ruby code and enable `CLI::UI::StdoutRouter` for most features. ```Bash gem install cli-ui ``` ```Ruby gem 'cli-ui' ``` -------------------------------- ### Ruby CLI UI Example with Nested Frames, Spinners, and Formatted Text Source: https://github.com/shopify/cli-ui/blob/main/README.md This Ruby example demonstrates the use of the `cli-ui` gem, showcasing nested frames, multi-threaded spinners, and formatted text output. It includes error handling for spinner groups and proper stdout routing. ```ruby require 'cli/ui' CLI::UI::StdoutRouter.enable CLI::UI::Frame.open('{{*}} {{bold:a}}', color: :green) do CLI::UI::Frame.open('{{i}} b', color: :magenta) do CLI::UI::Frame.open('{{?}} c', color: :cyan) do CLI::UI::SpinGroup.new do |sg| sg.add('wow') do |spinner| sleep(2.5) spinner.update_title('second round!') sleep (1.0) end sg.add('such spin') { sleep(1.6) } sg.add('many glyph') { sleep(2.0) } end end end CLI::UI::Frame.divider('{{v}} lol') puts CLI::UI.fmt '{{info:words}} {{red:oh no!}} {{green:success!}}' CLI::UI::SpinGroup.new do |sg| sg.add('more spins') { sleep(0.5) ; raise 'oh no' } end end ``` -------------------------------- ### Prompt User with Selectable Options in CLI UI Source: https://github.com/shopify/cli-ui/blob/main/README.md Shows how to prompt the user to select from a predefined list of options. Users can navigate using arrow keys, Vim bindings, or numbers. Includes an example of assigning callbacks to each option for custom logic. ```Ruby CLI::UI.ask('What language/framework do you use?', options: %w(rails go ruby python)) ``` ```Ruby CLI::UI::Prompt.ask('What language/framework do you use?') do |handler| handler.option('rails') { |selection| selection } handler.option('go') { |selection| selection } handler.option('ruby') { |selection| selection } handler.option('python') { |selection| selection } end ``` -------------------------------- ### Customize Frame Styles in CLI UI Source: https://github.com/shopify/cli-ui/blob/main/README.md Demonstrates how to change the visual style of frames, either globally or for individual frames. Examples include `:box` (default) and `:bracket` styles, allowing for different aesthetic presentations of framed content. ```Ruby CLI::UI.frame_style = :box ``` ```Ruby CLI::UI.frame('New Style!', frame_style: :bracket) { puts "It's pretty cool!" } ``` ```Ruby CLI::UI.frame_style = :bracket CLI::UI::StdoutRouter.enable CLI::UI::Frame.open('Frame 1') do CLI::UI::Frame.open('Frame 2') { puts "inside frame 2" } puts "inside frame 1" end ``` -------------------------------- ### Format Text with Colors in CLI UI Source: https://github.com/shopify/cli-ui/blob/main/README.md Illustrates how to apply color formatting to text output using simple tags within a string. Supports various predefined colors to enhance readability. ```Ruby puts CLI::UI.fmt "{{red:Red}} {{green:Green}}" ``` -------------------------------- ### Create Nested Frames in CLI UI Source: https://github.com/shopify/cli-ui/blob/main/README.md Demonstrates how to create nested frames to organize and visually separate content in the command-line interface. Requires `CLI::UI::StdoutRouter.enable` to be called for proper output routing. ```Ruby CLI::UI::StdoutRouter.enable CLI::UI::Frame.open('Frame 1') do CLI::UI::Frame.open('Frame 2') { puts "inside frame 2" } puts "inside frame 1" end ``` -------------------------------- ### Manage Multi-Threaded Processes with CLI UI Spinner Groups Source: https://github.com/shopify/cli-ui/blob/main/README.md Demonstrates how to use spinner groups to manage and display the status of multiple concurrent processes. Output is suppressed unless an issue occurs, and spinner titles can be updated dynamically to reflect state changes. ```Ruby CLI::UI::SpinGroup.new do |spin_group| spin_group.add('Title') { |spinner| sleep 3.0 } spin_group.add('Title 2') { |spinner| sleep 3.0; spinner.update_title('New Title'); sleep 3.0 } end ``` -------------------------------- ### Prompt User for Free-Form Text Input in CLI UI Source: https://github.com/shopify/cli-ui/blob/main/README.md Allows prompting the user for a free-form text response, with an option to provide a default value. Useful for collecting arbitrary user input. ```Ruby CLI::UI.ask('Is CLI UI Awesome?', default: 'It is great!') ``` -------------------------------- ### Set Instruction Text Color for CLI UI Prompts Source: https://github.com/shopify/cli-ui/blob/main/README.md Configures the color of the instruction text displayed in CLI UI prompts, enhancing readability and visual consistency. ```Ruby CLI::UI::Prompt.instructions_color = CLI::UI::Color::GRAY ``` -------------------------------- ### Format Text with Symbols/Glyphs in CLI UI Source: https://github.com/shopify/cli-ui/blob/main/README.md Shows how to embed special symbols or glyphs into text output using specific tags. Useful for adding visual cues like stars, checkmarks, or question marks. ```Ruby puts CLI::UI.fmt "{{*}} {{v}} {{?}} {{x}}" ``` -------------------------------- ### Show Progress Bar in CLI UI Source: https://github.com/shopify/cli-ui/blob/main/README.md Provides a simple way to display a progress bar for operations with a known number of steps. The bar visually updates as `tick` is called. ```Ruby CLI::UI::Progress.progress do |bar| 100.times do bar.tick end end ``` -------------------------------- ### Display Status Widget in CLI UI Spinner Source: https://github.com/shopify/cli-ui/blob/main/README.md Integrates a dynamic status widget within a spinner, allowing for real-time updates of multiple metrics or values during a long-running operation. ```Ruby CLI::UI::Spinner.spin("building packages: {{@widget/status:1:2:3:4}}") do |spinner| # spinner.update_title(...) sleep(3) end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.