Class: Strata::CLI::FieldEditor
- Inherits:
-
Object
- Object
- Strata::CLI::FieldEditor
- Includes:
- Terminal
- Defined in:
- lib/strata/cli/ui/field_editor.rb
Overview
Interactive field editor with row-by-row navigation. Displays a table of AI-generated fields and allows inline editing.
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#model_context ⇒ Object
readonly
Returns the value of attribute model_context.
-
#pastel ⇒ Object
readonly
Returns the value of attribute pastel.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Instance Method Summary collapse
-
#initialize(fields, prompt: TTY::Prompt.new, table_context: nil, model_context: nil) ⇒ FieldEditor
constructor
A new instance of FieldEditor.
-
#run ⇒ Array<Hash>?
Run the interactive editor.
Methods included from Terminal
#create_spinner, #print_table, #with_spinner
Constructor Details
#initialize(fields, prompt: TTY::Prompt.new, table_context: nil, model_context: nil) ⇒ FieldEditor
Returns a new instance of FieldEditor.
20 21 22 23 24 25 26 27 |
# File 'lib/strata/cli/ui/field_editor.rb', line 20 def initialize(fields, prompt: TTY::Prompt.new, table_context: nil, model_context: nil) @fields = fields.map { |f| f.merge(skipped: false) } @prompt = prompt @pastel = Pastel.new @selected_index = 0 @model_context = model_context || {description: ""} @table_context = table_context end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
15 16 17 |
# File 'lib/strata/cli/ui/field_editor.rb', line 15 def fields @fields end |
#model_context ⇒ Object (readonly)
Returns the value of attribute model_context.
15 16 17 |
# File 'lib/strata/cli/ui/field_editor.rb', line 15 def model_context @model_context end |
#pastel ⇒ Object (readonly)
Returns the value of attribute pastel.
15 16 17 |
# File 'lib/strata/cli/ui/field_editor.rb', line 15 def pastel @pastel end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
15 16 17 |
# File 'lib/strata/cli/ui/field_editor.rb', line 15 def prompt @prompt end |
Instance Method Details
#run ⇒ Array<Hash>?
Run the interactive editor
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/strata/cli/ui/field_editor.rb', line 31 def run loop do clear_screen display_table display_help show_cursor key = prompt.reader.read_keypress case key when "\e[A", "k" # Up arrow or k @selected_index = [@selected_index - 1, 0].max when "\e[B", "j" # Down arrow or j @selected_index = [@selected_index + 1, @fields.length - 1].min when "\r", "\n" # Enter handle_edit when "s", "S" toggle_skip when "p", "P" handle_prompt_mode when "c", "C" if prompt.yes?("Confirm and generate model file?") show_cursor return {fields: active_fields, model_context: @model_context} end when "q", "Q", "\e" # q or Escape if prompt.yes?("Quit without saving?") show_cursor return nil end end end end |