Class: Sxn::UI::Table
- Inherits:
-
Object
- Object
- Sxn::UI::Table
- Defined in:
- lib/sxn/ui/table.rb
Overview
Table formatting for lists and data display
Instance Method Summary collapse
- #config_summary(config) ⇒ Object
-
#header(title) ⇒ Object
Add a header to the table output.
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #projects(projects) ⇒ Object
- #rules(rules, project_filter = nil) ⇒ Object
- #sessions(sessions) ⇒ Object
- #worktrees(worktrees) ⇒ Object
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
10 11 12 |
# File 'lib/sxn/ui/table.rb', line 10 def initialize @pastel = Pastel.new end |
Instance Method Details
#config_summary(config) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sxn/ui/table.rb', line 80 def config_summary(config) headers = %w[Setting Value Source] rows = [ ["Sessions Folder", config[:sessions_folder] || "Not set", "config"], ["Current Session", config[:current_session] || "None", "config"], ["Auto Cleanup", config[:auto_cleanup] ? "Enabled" : "Disabled", "config"], ["Max Sessions", config[:max_sessions] || "Unlimited", "config"] ] render_table(headers, rows) end |
#header(title) ⇒ Object
Add a header to the table output
93 94 95 96 |
# File 'lib/sxn/ui/table.rb', line 93 def header(title) puts "\n#{@pastel.bold.underline(title)}" puts end |
#projects(projects) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sxn/ui/table.rb', line 31 def projects(projects) return empty_table("No projects configured") if projects.empty? headers = ["Name", "Type", "Path", "Default Branch"] rows = projects.map do |project| [ project[:name], project[:type] || "unknown", truncate_path(project[:path]), project[:default_branch] || "master" ] end render_table(headers, rows) end |
#rules(rules, project_filter = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sxn/ui/table.rb', line 63 def rules(rules, project_filter = nil) filtered_rules = project_filter ? rules.select { |r| r[:project] == project_filter } : rules return empty_table("No rules configured") if filtered_rules.empty? headers = %w[Project Type Config Status] rows = filtered_rules.map do |rule| [ rule[:project], rule[:type], truncate_config(rule[:config]), rule[:enabled] ? @pastel.green("✓") : @pastel.red("✗") ] end render_table(headers, rows) end |
#sessions(sessions) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sxn/ui/table.rb', line 14 def sessions(sessions) return empty_table("No sessions found") if sessions.empty? headers = %w[Name Status Projects Created Updated] rows = sessions.map do |session| [ session[:name], status_indicator(session[:status]), session[:projects]&.join(", ") || "", format_date(session[:created_at]), format_date(session[:updated_at]) ] end render_table(headers, rows) end |
#worktrees(worktrees) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sxn/ui/table.rb', line 47 def worktrees(worktrees) return empty_table("No worktrees in current session") if worktrees.empty? headers = %w[Project Branch Path Status] rows = worktrees.map do |worktree| [ worktree[:project], worktree[:branch], truncate_path(worktree[:path]), worktree_status(worktree) ] end render_table(headers, rows) end |