Class: Kotoshu::Cli::DisplayFormatter
- Inherits:
-
Object
- Object
- Kotoshu::Cli::DisplayFormatter
- Defined in:
- lib/kotoshu/cli/display_formatter.rb
Overview
Formats output for interactive review mode.
Provides methods to display errors, context, suggestions, and navigation prompts in a user-friendly CLI format.
Constant Summary collapse
- COLORS =
ANSI color codes for terminal output
{ error: "\e[31m", # Red warning: "\e[33m", # Yellow success: "\e[32m", # Green info: "\e[36m", # Cyan dim: "\e[2m", # Dim bold: "\e[1m", # Bold reset: "\e[0m" # Reset }.freeze
- CONFIDENCE_LABELS =
Confidence level indicators
{ high: '✓ High', medium: '~ Medium', low: '? Low' }.freeze
Instance Attribute Summary collapse
-
#color_enabled ⇒ Object
readonly
Returns the value of attribute color_enabled.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#error(message) ⇒ String
Display error message.
-
#export_summary(navigation, export_path) ⇒ String
Display export summary.
-
#format_suggestions(suggestions, max_display: 5) ⇒ String
Format suggestions list with confidence scores.
-
#help_screen ⇒ String
Display help screen.
-
#highlight_error(error) ⇒ String
Highlight the error word within its context.
-
#initialize(verbose: false, color_enabled: nil) ⇒ DisplayFormatter
constructor
Create a new display formatter.
-
#issue_screen(error, index:, total:, show_context: true) ⇒ String
Display individual error screen.
-
#list_all_errors(navigation) ⇒ String
Display all errors with status indicators.
-
#prompt(text) ⇒ String
Format input prompt.
-
#statistics(navigation) ⇒ String
Display statistics summary.
-
#success(message) ⇒ String
Display success message.
-
#summary_screen(document, navigation) ⇒ String
Display summary screen for document review.
-
#warning(message) ⇒ String
Display warning message.
Constructor Details
#initialize(verbose: false, color_enabled: nil) ⇒ DisplayFormatter
Create a new display formatter.
41 42 43 44 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 41 def initialize(verbose: false, color_enabled: nil) @verbose = verbose @color_enabled = color_enabled.nil? ? $stdout.tty? : color_enabled end |
Instance Attribute Details
#color_enabled ⇒ Object (readonly)
Returns the value of attribute color_enabled.
35 36 37 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 35 def color_enabled @color_enabled end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
35 36 37 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 35 def verbose @verbose end |
Instance Method Details
#error(message) ⇒ String
Display error message.
348 349 350 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 348 def error() colorize("Error: #{}", :error) end |
#export_summary(navigation, export_path) ⇒ String
Display export summary.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 301 def export_summary(, export_path) corrections = .export_corrections lines = [] lines << "" lines << colorize("═══ Export Summary ═══", :bold) lines << "" lines << "Exported #{corrections.size} corrections to:" lines << colorize(export_path, :info) lines << "" if corrections.any? && @verbose lines << colorize("Corrections:", :bold) corrections.first(10).each do |corr| lines << " Line #{corr[:line]}: #{corr[:original]} → #{corr[:replacement]}" end if corrections.size > 10 lines << colorize(" ... and #{corrections.size - 10} more", :dim) end lines << "" end lines.join("\n") end |
#format_suggestions(suggestions, max_display: 5) ⇒ String
Format suggestions list with confidence scores.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 179 def format_suggestions(suggestions, max_display: 5) return colorize("No suggestions", :dim) unless suggestions&.any? lines = [] suggestions.first(max_display).each_with_index do |suggestion, idx| number = colorize((idx + 1).to_s + '.', :info) word = colorize(suggestion.word, suggestion.high_confidence? ? :success : :warning) confidence = "(#{(suggestion.confidence * 100).round(0)}%)" line = " #{number} #{word} #{confidence}" line += " [#{suggestion.source}]" if suggestion.source && @verbose lines << line end if suggestions.size > max_display remaining = suggestions.size - max_display lines << colorize(" ... and #{remaining} more", :dim) end lines.join("\n") end |
#help_screen ⇒ String
Display help screen.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 259 def help_screen lines = [] lines << "" lines << colorize("═══ Interactive Review Help ═══", :bold) lines << "" lines << colorize("Navigation Commands:", :bold) lines << " [Enter] or [n] Move to next error" lines << " [b] Move to previous error" lines << " [j] <number> Jump to error by number" lines << " [f] Jump to first error" lines << " [l] Jump to last error" lines << "" lines << colorize("Error Actions:", :bold) lines << " [1-9] Accept suggestion by number" lines << " [s] Skip current error" lines << " [e] Edit custom replacement" lines << "" lines << colorize("Display Commands:", :bold) lines << " [l] List all errors with status" lines << " [t] Toggle show/hide context" lines << " [v] Toggle verbose mode" lines << " [?] Show this summary" lines << "" lines << colorize("Program Commands:", :bold) lines << " [q] Quit and save changes" lines << " [Q] Quit without saving" lines << " [!] Export corrections to file" lines << "" lines << colorize("Filter Commands:", :bold) lines << " [c] <level> Filter by confidence (high, medium, low)" lines << " [y] <type> Filter by error type" lines << " [a] Show all errors (clear filters)" lines << "" lines.join("\n") end |
#highlight_error(error) ⇒ String
Highlight the error word within its context.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 158 def highlight_error(error) return error.original unless error.context ctx = error.context highlighted = ctx.current.gsub(/\b#{Regexp.escape(error.original)}\b/i) do |match| colorize(match, :error) end # Truncate if too long if highlighted.length > 100 "..." + highlighted[-100..-1] else highlighted end end |
#issue_screen(error, index:, total:, show_context: true) ⇒ String
Display individual error screen.
Shows the error with context, suggestions, and action prompt.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 112 def issue_screen(error, index:, total:, show_context: true) lines = [] lines << "" lines << colorize("═" * 70, :bold) lines << colorize("Error #{index} of #{total}", :bold) + " — #{error_type_label(error.error_type)}" lines << colorize("═" * 70, :bold) lines << "" # Error location lines << colorize("Location:", :bold) + " #{error.location}" lines << "" # Error with highlighting lines << colorize("Found:", :error) + " #{highlight_in_context(error)}" lines << "" # Context window if show_context && error.context lines << colorize("Context:", :bold) lines << format_context(error.context) lines << "" end # Confidence indicator conf_label = confidence_label(error.confidence) lines << colorize("Confidence:", :bold) + " #{conf_label} (#{(error.confidence * 100).round(1)}%)" lines << "" # Suggestions if error.suggestions&.any? lines << colorize("Suggestions:", :bold) lines << format_suggestions(error.suggestions) lines << "" end # Action prompt lines << colorize("Actions:", :bold) + " [Enter] Next [1-#{error.suggestions&.size || 0}] Accept [s] Skip [b] Back [q] Quit" lines << "" lines.join("\n") end |
#list_all_errors(navigation) ⇒ String
Display all errors with status indicators.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 205 def list_all_errors() lines = [] lines << "" lines << colorize("All Errors (#{.errors.size})", :bold) lines << "─" * 70 .list_all.each do |line| # Add color coding based on status colored_line = if line.include?('[DONE]') colorize(line, :success) elsif line.include?('[SKIP]') colorize(line, :dim) else line end lines << colored_line end lines << "" lines.join("\n") end |
#prompt(text) ⇒ String
Format input prompt.
332 333 334 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 332 def prompt(text) colorize("#{text} ", :info) end |
#statistics(navigation) ⇒ String
Display statistics summary.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 231 def statistics() stats = .statistics lines = [] lines << "" lines << colorize("Review Statistics", :bold) lines << "─" * 40 lines << "Total: #{stats[:total]}" lines << "Pending: #{stats[:pending]}" lines << colorize("Modified: #{stats[:modified]}", :success) lines << colorize("Skipped: #{stats[:skipped]}", :dim) lines << "" if stats[:by_type]&.any? lines << colorize("By Type:", :bold) stats[:by_type].each do |type, count| label = SemanticError::ERROR_TYPES[type] || type.to_s.capitalize lines << " #{label}: #{count}" end lines << "" end lines.join("\n") end |
#success(message) ⇒ String
Display success message.
356 357 358 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 356 def success() colorize(, :success) end |
#summary_screen(document, navigation) ⇒ String
Display summary screen for document review.
Shows error breakdown by type and confidence, plus navigation hints.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 53 def summary_screen(document, ) stats = .statistics lines = [] lines << "" lines << colorize("═══ Document Review Summary", :bold) lines << "" lines << "Document: #{document.name}" lines << "Format: #{Document::FORMATS[document.format]}" lines << "Language: #{document.language_code}" lines << "" lines << colorize("Error Summary", :bold) lines << "─" * 40 # Total counts lines << "Total errors found: #{stats[:total]}" lines << " • Pending: #{stats[:pending]}" lines << " • Modified: #{stats[:modified]}" lines << " • Skipped: #{stats[:skipped]}" lines << "" # Breakdown by type if stats[:by_type]&.any? lines << colorize("By Type", :bold) stats[:by_type].each do |type, count| label = SemanticError::ERROR_TYPES[type] || type.to_s.capitalize lines << " • #{label}: #{count}" end lines << "" end # Breakdown by confidence if stats[:by_confidence]&.any? lines << colorize("By Confidence", :bold) lines << " • High (>0.8): #{stats[:by_confidence][:high]}" lines << " • Medium (0.5-0.8): #{stats[:by_confidence][:medium]}" lines << " • Low (≤0.5): #{stats[:by_confidence][:low]}" lines << "" end # Navigation hints lines << colorize("Navigation", :bold) lines << " [Enter] Next error [s] Skip [a] Accept suggestion" lines << " [b] Back [q] Quit [l] List all errors" lines << " [j] Jump to error [h] Help [?] Show this summary" lines << "" lines.join("\n") end |
#warning(message) ⇒ String
Display warning message.
340 341 342 |
# File 'lib/kotoshu/cli/display_formatter.rb', line 340 def warning() colorize("Warning: #{}", :warning) end |