Class: Tng::UI::JsonSession
- Inherits:
-
Object
- Object
- Tng::UI::JsonSession
- Defined in:
- lib/tng/ui/json_session.rb
Overview
UI Session that outputs JSON events to STDOUT for machine consumption
Instance Method Summary collapse
- #display_error(message) ⇒ Object
- #display_info(message) ⇒ Object
- #display_list(title, items) ⇒ Object
- #display_warning(message) ⇒ Object
-
#initialize ⇒ JsonSession
constructor
A new instance of JsonSession.
- #running? ⇒ Boolean
-
#show_audit_results(audit_result, _audit_type) ⇒ Object
------------------------------------------------------------------ Results Display ------------------------------------------------------------------.
-
#show_auth_error(message = "Authentication failed") ⇒ Object
------------------------------------------------------------------ Errors & Warnings ------------------------------------------------------------------.
- #show_auth_warning(missing_items = "") ⇒ Object
- #show_banner(_version) ⇒ Object
- #show_clipboard_success(_cmd) ⇒ Object
- #show_clones(file_path, results) ⇒ Object
- #show_config_error(missing) ⇒ Object
- #show_config_missing(missing_items) ⇒ Object
- #show_dead_code_results(file_path, results_json) ⇒ Object
- #show_generation_result(result) ⇒ Object
- #show_goodbye ⇒ Object
- #show_help(_version) ⇒ Object
- #show_list_view(_title, _items) ⇒ Object
-
#show_menu ⇒ Object
------------------------------------------------------------------ Stubs for Interactive Methods (Not supported in JSON mode) ------------------------------------------------------------------.
- #show_no_items(type) ⇒ Object
- #show_post_generation_menu(_file_path, _run_command) ⇒ Object
- #show_post_install(_version) ⇒ Object
- #show_progress(title) ⇒ Object
- #show_prompt(content) ⇒ Object
-
#show_spinner(message) ⇒ Object
------------------------------------------------------------------ Progress & Spinners ------------------------------------------------------------------.
- #show_stats(_stats) ⇒ Object
- #show_system_status(status) ⇒ Object
- #show_test_results(title, passed, failed, errors, total, results = []) ⇒ Object
- #show_test_type_menu(_mode = "test") ⇒ Object
- #show_trace_results(trace_file_path) ⇒ Object
- #show_xray_results(xray_result, method_info = {}) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ JsonSession
Returns a new instance of JsonSession.
9 10 11 12 13 |
# File 'lib/tng/ui/json_session.rb', line 9 def initialize # Ensure stdout is sync so events are emitted immediately $stdout.sync = true @running = false end |
Instance Method Details
#display_error(message) ⇒ Object
25 26 27 |
# File 'lib/tng/ui/json_session.rb', line 25 def display_error() emit_event("error", { message: strip_colors() }) end |
#display_info(message) ⇒ Object
33 34 35 |
# File 'lib/tng/ui/json_session.rb', line 33 def display_info() emit_event("info", { message: strip_colors() }) end |
#display_list(title, items) ⇒ Object
37 38 39 |
# File 'lib/tng/ui/json_session.rb', line 37 def display_list(title, items) emit_event("list", { title: strip_colors(title), items: items }) end |
#display_warning(message) ⇒ Object
29 30 31 |
# File 'lib/tng/ui/json_session.rb', line 29 def display_warning() emit_event("warning", { message: strip_colors() }) end |
#running? ⇒ Boolean
41 42 43 |
# File 'lib/tng/ui/json_session.rb', line 41 def running? @running end |
#show_audit_results(audit_result, _audit_type) ⇒ Object
Results Display
91 92 93 |
# File 'lib/tng/ui/json_session.rb', line 91 def show_audit_results(audit_result, _audit_type) emit_event("result", audit_result) end |
#show_auth_error(message = "Authentication failed") ⇒ Object
Errors & Warnings
136 137 138 |
# File 'lib/tng/ui/json_session.rb', line 136 def show_auth_error( = "Authentication failed") emit_event("auth_error", { message: }) end |
#show_auth_warning(missing_items = "") ⇒ Object
173 174 175 176 177 178 |
# File 'lib/tng/ui/json_session.rb', line 173 def show_auth_warning(missing_items = "") emit_event("auth_warning", { missing: missing_items }) # In headless mode, we probably can't prompt, so we might default to cancel # or we could make this configurable. For now, cancel to be safe. "cancel" end |
#show_banner(_version) ⇒ Object
180 |
# File 'lib/tng/ui/json_session.rb', line 180 def (_version); end |
#show_clipboard_success(_cmd) ⇒ Object
185 |
# File 'lib/tng/ui/json_session.rb', line 185 def show_clipboard_success(_cmd); end |
#show_clones(file_path, results) ⇒ Object
95 96 97 |
# File 'lib/tng/ui/json_session.rb', line 95 def show_clones(file_path, results) emit_event("clones", { file_path: file_path, matches: results[:matches] }) end |
#show_config_error(missing) ⇒ Object
140 141 142 |
# File 'lib/tng/ui/json_session.rb', line 140 def show_config_error(missing) emit_event("config_error", { missing: missing }) end |
#show_config_missing(missing_items) ⇒ Object
144 145 146 |
# File 'lib/tng/ui/json_session.rb', line 144 def show_config_missing(missing_items) emit_event("config_missing", { missing: missing_items }) end |
#show_dead_code_results(file_path, results_json) ⇒ Object
104 105 106 107 |
# File 'lib/tng/ui/json_session.rb', line 104 def show_dead_code_results(file_path, results_json) parsed = JSON.parse(results_json) emit_event("dead_code", parsed) end |
#show_generation_result(result) ⇒ Object
124 125 126 |
# File 'lib/tng/ui/json_session.rb', line 124 def show_generation_result(result) emit_event("result", result) end |
#show_goodbye ⇒ Object
181 |
# File 'lib/tng/ui/json_session.rb', line 181 def show_goodbye; end |
#show_help(_version) ⇒ Object
183 |
# File 'lib/tng/ui/json_session.rb', line 183 def show_help(_version); end |
#show_list_view(_title, _items) ⇒ Object
165 166 167 |
# File 'lib/tng/ui/json_session.rb', line 165 def show_list_view(_title, _items) "back" end |
#show_menu ⇒ Object
Stubs for Interactive Methods (Not supported in JSON mode)
156 157 158 159 |
# File 'lib/tng/ui/json_session.rb', line 156 def # JSON mode is non-interactive usually, but if called, we just exit "exit" end |
#show_no_items(type) ⇒ Object
187 188 189 |
# File 'lib/tng/ui/json_session.rb', line 187 def show_no_items(type) emit_event("no_items", { type: type }) end |
#show_post_generation_menu(_file_path, _run_command) ⇒ Object
169 170 171 |
# File 'lib/tng/ui/json_session.rb', line 169 def (_file_path, _run_command) "back" end |
#show_post_install(_version) ⇒ Object
182 |
# File 'lib/tng/ui/json_session.rb', line 182 def show_post_install(_version); end |
#show_progress(title) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tng/ui/json_session.rb', line 66 def show_progress(title) emit_event("progress_start", { title: title }) reporter = JsonProgressReporter.new result = yield(reporter) if result&.dig(:error) # Error handled by reporter or caller else emit_event("progress_complete", { message: result&.dig(:message) || "Done", result: result }) end result rescue StandardError => e emit_event("error", { message: e. }) raise end |
#show_prompt(content) ⇒ Object
128 129 130 |
# File 'lib/tng/ui/json_session.rb', line 128 def show_prompt(content) emit_event("prompt", { content: content.to_s }) end |
#show_spinner(message) ⇒ Object
Progress & Spinners
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tng/ui/json_session.rb', line 49 def show_spinner() emit_event("progress", { message: , status: "running" }) result = yield status = result&.dig(:success) ? "success" : "error" emit_event("progress", { message: result&.dig(:message) || "Done", status: status }) result rescue StandardError => e emit_event("error", { message: e. }) raise end |
#show_stats(_stats) ⇒ Object
184 |
# File 'lib/tng/ui/json_session.rb', line 184 def show_stats(_stats); end |
#show_system_status(status) ⇒ Object
148 149 150 |
# File 'lib/tng/ui/json_session.rb', line 148 def show_system_status(status) emit_event("system_status", status) end |
#show_test_results(title, passed, failed, errors, total, results = []) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/tng/ui/json_session.rb', line 113 def show_test_results(title, passed, failed, errors, total, results = []) emit_event("test_results", { title: title, passed: passed, failed: failed, errors: errors, total: total, results: results }) end |
#show_test_type_menu(_mode = "test") ⇒ Object
161 162 163 |
# File 'lib/tng/ui/json_session.rb', line 161 def (_mode = "test") "back" end |
#show_trace_results(trace_file_path) ⇒ Object
99 100 101 102 |
# File 'lib/tng/ui/json_session.rb', line 99 def show_trace_results(trace_file_path) trace_json = JSON.parse(File.read(trace_file_path)) emit_event("result", trace_json) end |
#show_xray_results(xray_result, method_info = {}) ⇒ Object
109 110 111 |
# File 'lib/tng/ui/json_session.rb', line 109 def show_xray_results(xray_result, method_info = {}) emit_event("result", xray_result.merge(method_info: method_info)) end |
#start ⇒ Object
15 16 17 18 |
# File 'lib/tng/ui/json_session.rb', line 15 def start @running = true emit_event("started", { message: "TNG JSON Session Started" }) end |
#stop ⇒ Object
20 21 22 23 |
# File 'lib/tng/ui/json_session.rb', line 20 def stop @running = false emit_event("stopped", { message: "TNG JSON Session Stopped" }) end |