### Install Huh Ruby Gem Dependencies Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Command to install the necessary dependencies for the Huh Ruby gem using Bundler. This is a prerequisite for running the gem and its associated tools. ```bash bundle install ``` -------------------------------- ### Theming Examples in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Demonstrates how to apply visual themes to forms and fields using built-in themes or custom theme creation. Shows examples of applying themes to forms and standalone spinners, and how to define custom styles. ```ruby # Available built-in themes form = Huh.form(Huh.group(Huh.input.key("name").title("Name"))) form.with_theme(Huh::Themes.base) # Minimal styling form.with_theme(Huh::Themes.charm) # Indigo and fuchsia form.with_theme(Huh::Themes.dracula) # Dark purple form.with_theme(Huh::Themes.catppuccin) # Pastel colors form.with_theme(Huh::Themes.base16) # Terminal colors # Apply theme to standalone field spinner = Huh.spinner .title("Loading...") .with_theme(Huh::Themes.charm) .action { sleep(1) } spinner.run # Create custom theme theme = Huh::Theme.new theme.focused.title = Lipgloss::Style.new.bold(true).foreground("#00FF00") theme.focused.description = Lipgloss::Style.new.foreground("#888888") form.with_theme(theme) ``` -------------------------------- ### Apply Built-in Theme to Form in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Shows how to apply a pre-defined theme to a form for custom styling. The 'charm' theme is used as an example. ```ruby form = Huh.form( Huh.group( Huh.input.key("name").title("Name") ) ).with_theme(Huh::Themes.charm) ``` -------------------------------- ### Spinner Field Example in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Demonstrates the use of a spinner field to indicate loading or background processes. Examples cover basic usage, different spinner types, and error handling during the action. ```ruby # Basic spinner spinner = Huh.spinner .title("Loading data...") .type(:dots) .action { sleep(2) } error = spinner.run puts "Failed: #{error.message}" if error # Different spinner types types = [:line, :dots, :mini_dot, :moon, :globe, :monkey, :meter, :pulse, :points, :hamburger, :ellipsis] spinner = Huh.spinner .title("Processing...") .type(:moon) .action do # Perform background work result = fetch_data_from_api process_result(result) end # With error handling spinner = Huh.spinner .title("Saving...") .action do raise "Connection failed" unless connected? save_data end if (error = spinner.run) puts "Error: #{error.message}" else puts "Saved successfully!" end ``` -------------------------------- ### Note Field Example in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Shows how to implement a display-only note field for informational text. Examples include a note with a 'Next' button for wizard flows and a simple informational note without navigation. ```ruby note = Huh.note .title("Welcome!") .description("This wizard will guide you through the setup process.\n\nPress Enter to continue.") .next(true) .next_label("Get Started") # Note without navigation (just displays text) info = Huh.note .title("Important Notice") .description("Your session will expire in 5 minutes.") form = Huh.form( Huh.group(note), Huh.group( Huh.input.key("name").title("Name") ) ) form.run ``` -------------------------------- ### MultiSelect Field Example in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Demonstrates how to create a multi-select field allowing users to choose multiple options from a list, with an optional limit on the number of selections. It shows configuration for key, title, description, options, and selection limit. ```ruby multi = Huh.multi_select .key("toppings") .title("Choose your toppings") .description("Select up to 3") .options( Huh.option("Cheese", :cheese), Huh.option("Pepperoni", :pepperoni), Huh.option("Mushrooms", :mushrooms), Huh.option("Olives", :olives), Huh.option("Onions", :onions) ) .limit(3) .height(6) form = Huh.form(Huh.group(multi)) form.run puts "Toppings: #{form["toppings"].inspect}" # => [:cheese, :pepperoni] ``` -------------------------------- ### Input Validation Examples in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Provides examples of using built-in validators and custom validation functions for input fields. Covers required fields, length constraints, format validation, allowed values, and custom block-based validation. ```ruby # Built-in validators input = Huh.input.key("field") # Required (not empty) input.validate(Huh::Validation.not_empty) # Length constraints input.validate(Huh::Validation.min_length(3)) input.validate(Huh::Validation.max_length(100)) input.validate(Huh::Validation.length(3, 20)) # Range # Format validators input.validate(Huh::Validation.email) input.validate(Huh::Validation.integer) input.validate(Huh::Validation.range(1, 100)) # Numeric range # Regex pattern matching input.validate(Huh::Validation.matches(/^[a-z]+$/, message: "must be lowercase letters")) # Allowed values input.validate(Huh::Validation.one_of("small", "medium", "large")) # Combine multiple validators input.validate( Huh::Validation.all( Huh::Validation.not_empty, Huh::Validation.min_length(3), Huh::Validation.max_length(20) ) ) # Custom validation with block input.validate do |value| raise Huh::ValidationError, "must start with @" unless value.start_with?("@") end # Block navigation until valid (must fix errors before proceeding) form = Huh.form( Huh.group( Huh.input.key("email").title("Email").validate(Huh::Validation.email) ) ).with_validate_on_submit(true) ``` -------------------------------- ### Confirm Field Example in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Illustrates the creation of a confirmation field for Yes/No prompts, allowing customization of button labels. It also shows an example of an inline confirmation for horizontal button display. ```ruby confirm = Huh.confirm .key("agree") .title("Do you agree to the terms?") .description("Please read the terms carefully") .affirmative("I agree") .negative("I disagree") # Inline mode for horizontal buttons inline_confirm = Huh.confirm .key("continue") .title("Continue?") .inline(true) form = Huh.form(Huh.group(confirm)) form.run if form["agree"] puts "User agreed" else puts "User disagreed" end ``` -------------------------------- ### Install Huh-Ruby Gem Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Add the huh-ruby gem to your project's Gemfile to include the library. This allows you to use its functionalities for building terminal forms. ```ruby gem "huh", github: "marcoroth/huh-ruby" ``` -------------------------------- ### Create Multi-Page Forms with Groups and Layouts in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Organize form fields into groups for multi-page forms and apply various layouts. This example demonstrates creating three pages with different input types and configuring form dimensions and accessibility. ```ruby form = Huh.form( # Page 1: Personal info Huh.group( Huh.input.key("name").title("Name"), Huh.input.key("email").title("Email") ).title("Personal Information").description("Enter your details"), # Page 2: Work info Huh.group( Huh.input.key("company").title("Company"), Huh.input.key("role").title("Role") ).title("Work Information"), # Page 3: Preferences Huh.group( Huh.select.key("theme").title("Theme").options(*Huh.options("Light", "Dark")), Huh.confirm.key("notifications").title("Enable notifications?") ).title("Preferences") ) # Layout options form.with_layout(Huh::Layout.stack) # Default: vertical stacking form.with_layout(Huh::Layout.columns(2)) # Two-column layout # Form configuration form.with_width(80) form.with_height(24) form.with_show_help(true) form.with_accessible(false) form.run ``` -------------------------------- ### Create Forms with Dynamic Content in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Build forms where titles, descriptions, and options can dynamically update based on the form's state or external data. This example shows dynamic titles, options from an array, and dynamic placeholders. ```ruby count = 0 items = ["Item A", "Item B", "Item C"] form = Huh.form( Huh.group( # Dynamic title updates as user types Huh.input .key("item") .title_func { "Item #{count + 1}" } .description_func { "You've added #{count} items so far" }, # Dynamic options from external data Huh.select .key("selection") .title("Choose item") .options_func { Huh.options(*items) }, # Dynamic placeholder Huh.input .key("search") .placeholder_func { "Search #{items.length} items..." } ) ) form.run ``` -------------------------------- ### Configure and Use Huh Select Fields in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Demonstrates the configuration of single-selection select fields in the Huh library. It covers using custom option objects, simple values, enabling filtering/search, and using inline mode for horizontal display. Examples include running selects within a form. ```ruby # Using Huh.option for custom display/value pairs select = Huh.select .key("color") .title("Pick a color") .options( Huh.option("Red", "#ff0000"), Huh.option("Green", "#00ff00"), Huh.option("Blue", "#0000ff") ) .height(5) # Using simple values (display and value are the same) fruit = Huh.select .key("fruit") .title("Pick a fruit") .options(*Huh.options("Apple", "Banana", "Cherry", "Date")) # Enable filtering/search filterable = Huh.select .key("country") .title("Select your country") .options(*Huh.options("USA", "Canada", "UK", "Germany", "France", "Japan")) .filtering(true) .height(8) # Inline mode for horizontal display inline_select = Huh.select .key("size") .title("Size") .options(*Huh.options("S", "M", "L", "XL")) .inline(true) form = Huh.form(Huh.group(select, fruit)) form.run puts "Color: #{form["color"]}" # => "#ff0000" puts "Fruit: #{form["fruit"]}" # => "Apple" ``` -------------------------------- ### Access Form Results and Handle Errors in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Learn how to retrieve form data and manage validation errors after the form has been run. This includes accessing results by key, getting all results as a hash, and checking the form's state. ```ruby form = Huh.form( Huh.group( Huh.input.key("name").title("Name"), Huh.input.key("email").title("Email").validate(Huh::Validation.email) ) ) # Run returns array of validation errors (empty if all valid) errors = form.run # Check for errors if errors.any? errors.each { |e| puts "Error: #{e.message}" } end # Access results form["name"] # Hash-style access form.get("name") # Method access form.to_h # All results as hash: {"name" => "...", "email" => "..."} # Get all errors form.errors # => Array[ValidationError] # Form state form.state # => FormState::COMPLETED, FormState::ABORTED, etc. # Access current group/field form.current_group form.focused_field ``` -------------------------------- ### Create and Run a Basic Form in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates how to create a simple form with text inputs for name and email using the Huh library. The form is then run, and the collected data is accessed and printed. ```ruby require "huh" form = Huh.form( Huh.group( Huh.input .key("name") .title("What's your name?") .placeholder("Enter your name..."), Huh.input .key("email") .title("Email address") .placeholder("you@example.com") ) ) form.run puts "Hello, #{form["name"]}!" puts "Email: #{form["email"]}" ``` -------------------------------- ### Run Huh Ruby Gem Demos Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Commands to run various demo applications provided with the Huh Ruby gem. These demos showcase different functionalities, including basic usage, DSL, dynamic options, spinners, and validation. ```bash ./demo/basic ./demo/dsl ./demo/dynamic ./demo/spinner ./demo/validation ``` -------------------------------- ### Create and Run a Basic Ruby Form with Huh Source: https://context7.com/marcoroth/huh-ruby/llms.txt Demonstrates how to create a form with text inputs and a confirmation field using the Huh library. It shows how to configure fields, apply themes, run the form interactively, and handle validation errors or retrieve form values. ```ruby require "huh" # Create a form with text inputs and a confirmation form = Huh.form( Huh.group( Huh.input .key("name") .title("What's your name?") .placeholder("Enter your name..."), Huh.input .key("email") .title("Email address") .placeholder("you@example.com") .validate(Huh::Validation.not_empty), Huh.confirm .key("newsletter") .title("Subscribe to newsletter?") .affirmative("Yes!") .negative("No thanks") ).title("User Registration") ).with_theme(Huh::Themes.charm) # Run the form interactively errors = form.run # Handle results if errors.any? puts "Errors:" errors.each { |e| puts " - #{e.message}" } else puts "Name: #{form.get("name")}" # or form["name"] puts "Email: #{form.get("email")}" puts "Newsletter: #{form.get("newsletter")}" puts form.to_h # => {"name" => "...", "email" => "...", "newsletter" => true} end ``` -------------------------------- ### Ruby: Dynamic Titles and Descriptions in Huh Inputs Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Shows how to dynamically set the title and description for a Huh input field using block syntax. This allows for context-aware labels and helper text that can change based on application state. ```ruby count = 0 input = Huh.input .key("item") .title_func { "Item #{count + 1}" } .description_func { "You've added #{count} items" } ``` -------------------------------- ### Configure Single Select Field with Options in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Shows how to create a single-selection dropdown menu with predefined options, each having a display value and an associated value. ```ruby select = Huh.select .key("color") .title("Pick a color") .options( Huh.option("Red", "#ff0000"), Huh.option("Green", "#00ff00"), Huh.option("Blue", "#0000ff") ) ``` -------------------------------- ### Ruby: Dynamic Options for Huh Select Fields Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates how to dynamically populate the options for a Huh select (dropdown) field. The `options_func` method allows the options to be generated or fetched at runtime, providing flexibility. ```ruby items = ["A", "B", "C"] select = Huh.select .key("item") .title("Pick an item") .options_func { Huh.options(*items) } ``` -------------------------------- ### Configure Confirmation Field in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Shows how to implement a simple Yes/No confirmation prompt. Custom labels for affirmative and negative responses can be specified. ```ruby confirm = Huh.confirm .key("agree") .title("Do you agree to the terms?") .affirmative("I agree") .negative("I disagree") ``` -------------------------------- ### Block-based DSL for Form Creation in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates the block-based DSL for creating forms in the Huh Ruby gem. This syntax allows for a more idiomatic Ruby approach to defining form elements, including groups, inputs, selects, and confirms. It requires the Huh gem and its dependencies. ```ruby form = Huh::Form.new do |form| form.theme(Huh::Themes.charm) form.group do |group| group.title("User Registration") group.input do |input| input.key("name") input.title("What's your name?") input.placeholder("Enter your name") end group.select do |select| select.key("role") select.title("Your role") select.options("Developer", "Designer", "Manager") end group.confirm do |confirm| confirm.key("newsletter") confirm.title("Subscribe?") end end end form.run ``` -------------------------------- ### Configure Spinner for Loading Indicator in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Illustrates how to use a spinner component to indicate a background process, such as fetching data from an API. It shows how to handle potential errors during the action. ```ruby spinner = Huh.spinner .title("Loading data...") .type(:dots) .action { fetch_from_api } error = spinner.run puts "Failed: #{error.message}" if error ``` -------------------------------- ### Ruby: Running Standalone Huh Fields Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Illustrates how to run individual Huh input fields without embedding them in a full form. This is useful for simple, single-purpose inputs or confirmations. ```ruby name = Huh.input .title("What's your name?") .run puts "Hello, #{name}!" result = Huh.run( Huh.confirm.title("Continue?") ) ``` -------------------------------- ### Configure Single Select Field from Simple Values in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates creating a single-select dropdown where options are derived directly from a list of simple values. ```ruby select = Huh.select .key("fruit") .title("Pick a fruit") .options(*Huh.options("Apple", "Banana", "Cherry")) ``` -------------------------------- ### Configure Single-line Text Input Field in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Shows how to configure a single-line text input field with a key, title, placeholder, character limit, and non-empty validation. ```ruby input = Huh.input .key("username") .title("Username") .placeholder("Enter username...") .char_limit(20) .validate(Huh::Validation.not_empty) ``` -------------------------------- ### Ruby: Organizing Huh Fields into Groups Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates how to group related input fields within a Huh form. Groups can have their own titles and descriptions, improving the structure and readability of complex forms. ```ruby form = Huh.form( Huh.group( Huh.input.key("name").title("Name"), Huh.input.key("email").title("Email") ).title("Personal Info").description("Enter your details"), Huh.group( Huh.input.key("company").title("Company"), Huh.input.key("role").title("Role") ).title("Work Info") ) ``` -------------------------------- ### Ruby: Applying Layouts to Huh Forms Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Shows how to customize the visual layout of fields within a Huh form. It covers the default stack layout and the column layout, which arranges fields in a specified number of columns. ```ruby form.with_layout(Huh::Layout.stack) form.with_layout(Huh::Layout.columns(2)) ``` -------------------------------- ### Configure and Use Huh Input Fields in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Illustrates various configurations for the text input field in the Huh library, including basic input, password input with hidden characters, input with autocomplete suggestions, and inline mode. It also shows how to run an input field standalone. ```ruby # Basic text input input = Huh.input .key("username") .title("Username") .description("Choose a unique username") .placeholder("Enter username...") .char_limit(20) .validate(Huh::Validation.not_empty) # Password input with hidden characters password = Huh.input .key("password") .title("Password") .placeholder("Enter password...") .echo_mode(:password) # or Huh::EchoMode::PASSWORD .validate(Huh::Validation.min_length(8)) # Input with autocomplete suggestions language = Huh.input .key("language") .title("Favorite language") .suggestions(["Ruby", "Python", "JavaScript", "Go", "Rust"]) # Inline mode (title and input on same line) inline_input = Huh.input .key("code") .title("Code:") .inline(true) # Run standalone (outside a form) name = Huh.input.title("What's your name?").run puts "Hello, #{name}!" ``` -------------------------------- ### Run Tests for Huh Ruby Gem Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Command to execute the test suite for the Huh Ruby gem using Rake. This is essential for verifying the integrity of the gem and for development purposes. ```bash bundle exec rake test ``` -------------------------------- ### Configure Note Field for Display in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates how to display static information to the user within a form. This field is useful for providing instructions or messages. ```ruby note = Huh.note .title("Welcome!") .description("This wizard will help you set up your project.") .next(true) .next_label("Get Started") ``` -------------------------------- ### Configure and Use Huh Text Area (Multi-line) in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Shows how to configure and use the multi-line text area field in the Huh library. This includes setting the number of lines, character limit, and enabling line numbers. It also demonstrates running the text area within a form. ```ruby text = Huh.text .key("bio") .title("Tell us about yourself") .description("Write a short bio") .placeholder("Write something...") .lines(5) .char_limit(500) .show_line_numbers(true) # Run in a form form = Huh.form( Huh.group(text) ).with_theme(Huh::Themes.dracula) form.run puts "Bio: #{form["bio"]}" ``` -------------------------------- ### Configure Multi-Select Field in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Illustrates how to create a field allowing multiple selections from a list of options. It includes a limit on the number of selections allowed. ```ruby multi = Huh.multi_select .key("toppings") .title("Choose toppings") .options(*Huh.options("Cheese", "Pepperoni", "Mushrooms", "Olives")) .limit(3) ``` -------------------------------- ### Construct Forms Using Block-based DSL in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Utilize an alternative, more idiomatic Ruby syntax for form construction using blocks. This approach allows for a nested and fluent way to define form elements, themes, and validations. ```ruby form = Huh::Form.new do |f| f.theme(Huh::Themes.charm) f.validate_on_submit(true) f.group do |g| g.title("User Registration") g.description("Create your account") g.input do |i| i.key("username") i.title("Username") i.placeholder("Enter username") i.char_limit(20) i.validate(Huh::Validation.length(3, 20)) end g.input do |i| i.key("password") i.title("Password") i.echo_mode(:password) i.validate(Huh::Validation.min_length(8)) end g.select do |s| s.key("role") s.title("Account type") s.options("Personal", "Business", "Enterprise") end g.confirm do |c| c.key("terms") c.title("Accept terms?") c.affirmative("Accept") c.negative("Decline") end end f.group do |g| g.title("Profile") g.text do |t| t.key("bio") t.title("Bio") t.placeholder("Tell us about yourself") t.lines(4) t.char_limit(500) end g.multi_select do |ms| ms.key("interests") ms.title("Interests") ms.options("Technology", "Music", "Sports", "Art", "Travel") ms.limit(3) end end end form.run puts form.to_h ``` -------------------------------- ### Configure Multi-line Text Area Field in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates the configuration of a multi-line text area for longer inputs. It includes settings for the number of lines and a maximum character limit. ```ruby text = Huh.text .key("bio") .title("Tell us about yourself") .placeholder("Write something...") .lines(5) .char_limit(500) ``` -------------------------------- ### Configure Password Input Field in Ruby Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Illustrates how to set up a password input field that masks user input. The 'echo_mode' is set to ':password' to enable this behavior. ```ruby password = Huh.input .key("password") .title("Password") .echo_mode(:password) ``` -------------------------------- ### Ruby: Built-in Validators for Huh Inputs Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Demonstrates the use of various built-in validation methods provided by the Huh library for inputs. These include checking for non-empty values, length constraints, format validation (email, integer, URL), custom regex matching, and custom validation blocks. ```ruby input.validate(Huh::Validation.not_empty) input.validate(Huh::Validation.min_length(3)) input.validate(Huh::Validation.max_length(100)) input.validate(Huh::Validation.length_range(3, 20)) input.validate(Huh::Validation.email) input.validate(Huh::Validation.integer) input.validate(Huh::Validation.url) input.validate(Huh::Validation.match(/^[a-z]+$/, "must be lowercase letters")) input.validate do |value| raise Huh::ValidationError, "must start with @" unless value.start_with?("@") end input.validate( Huh::Validation.all( Huh::Validation.not_empty, Huh::Validation.min_length(3), Huh::Validation.max_length(20) ) ) ``` -------------------------------- ### Ruby: Accessing Huh Form Results via Hash-Style and Methods Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Details how to retrieve the results and errors from a submitted Huh form. It covers accessing individual field values by key, checking for errors, and obtaining all results as a hash. ```ruby errors = form.run if errors.any? errors.each { |e| puts "Error: #{e.message}" } else form["name"] # Get by key form.get("name") # Same as above form.to_h # Get all results as hash end ``` -------------------------------- ### Ruby: Block Navigation on Validation Errors in Huh Forms Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Illustrates how to configure a Huh form to prevent users from proceeding until all fields are valid. This is achieved by using the `with_validate_on_submit(true)` method, ensuring a robust user experience. ```ruby form = Huh.form( Huh.group( Huh.input.key("email").validate(Huh::Validation.email) ) ).with_validate_on_submit(true) # Users can't proceed until field is valid ``` -------------------------------- ### Ruby: Binding Huh Input Values to External Variables Source: https://github.com/marcoroth/huh-ruby/blob/main/README.md Explains how to bind Huh input fields directly to external Ruby objects and their attributes. Changes made within the form are automatically reflected in the bound object, and vice versa, simplifying data synchronization. ```ruby user = Struct.new(:name, :email).new("", "") form = Huh.form( Huh.group( Huh.input.key("name").title("Name").value(user, :name), Huh.input.key("email").title("Email").value(user, :email) ) ) form.run puts user.name # Value is automatically synced puts user.email ``` -------------------------------- ### Bind Form Fields to External Objects for Value Synchronization in Ruby Source: https://context7.com/marcoroth/huh-ruby/llms.txt Synchronize form field values automatically with attributes of external objects like Structs or custom classes. This ensures that user input updates the object and vice-versa. ```ruby # Bind to Struct attributes User = Struct.new(:name, :email, :role) user = User.new("", "", "") form = Huh.form( Huh.group( Huh.input.key("name").title("Name").value(user, :name), Huh.input.key("email").title("Email").value(user, :email), Huh.select.key("role").title("Role") .options(*Huh.options("Admin", "User", "Guest")) .value(user, :role) ) ) form.run # Values automatically synced to user object puts user.name # User's input puts user.email # User's input puts user.role # Selected role # Bind to custom accessor class Config attr_accessor :setting end config = Config.new Huh.input.value(config, :setting) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.