Class: Epuber::UserInterface
- Inherits:
-
Object
- Object
- Epuber::UserInterface
- Defined in:
- lib/epuber/user_interface.rb
Defined Under Namespace
Classes: Location
Class Attribute Summary collapse
Class Method Summary collapse
-
.error(message, location: nil) ⇒ Object
Fatal error, prints message and exit with return code 1.
-
.error!(message, location: nil) ⇒ Object
Fatal error, prints message and exit with return code 1.
- .print_processing_debug_info(info_text) ⇒ Object
-
.print_processing_file(file, index, count) ⇒ Object
Nil.
- .print_processing_problem(problem) ⇒ Object
- .processing_files_done ⇒ Object
- .remove_processing_file_line ⇒ Object
- .warning(message, location: nil) ⇒ Object
Class Attribute Details
.current_command ⇒ Epuber::Command
16 17 18 |
# File 'lib/epuber/user_interface.rb', line 16 def current_command @current_command end |
Class Method Details
.error(message, location: nil) ⇒ Object
Fatal error, prints message and exit with return code 1
35 36 37 38 39 40 |
# File 'lib/epuber/user_interface.rb', line 35 def self.error(, location: nil) $stdout.puts unless @last_processing_file_line.nil? $stdout.puts((:error, , location: location)) _print_backtrace(location.try(:backtrace_locations) || .try(:backtrace_locations) || caller_locations, location: location) if current_command.verbose? end |
.error!(message, location: nil) ⇒ Object
Fatal error, prints message and exit with return code 1
24 25 26 27 |
# File 'lib/epuber/user_interface.rb', line 24 def self.error!(, location: nil) error(, location: location) exit(1) end |
.print_processing_debug_info(info_text) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/epuber/user_interface.rb', line 65 def self.print_processing_debug_info(info_text) if current_command && current_command.verbose? _clear_processing_line_for_new_output do = if @current_file.nil? "▸ #{info_text}" else "▸ #{@current_file.source_path}: #{info_text}" end $stdout.puts(.ansi.send(_color_from_level(:debug))) end end end |
.print_processing_file(file, index, count) ⇒ Object
Returns nil.
83 84 85 86 87 88 89 90 |
# File 'lib/epuber/user_interface.rb', line 83 def self.print_processing_file(file, index, count) remove_processing_file_line @current_file = file @last_processing_file_line = "▸ Processing #{file.source_path} (#{index + 1} of #{count})" $stdout.print(@last_processing_file_line) end |
.print_processing_problem(problem) ⇒ Object
57 58 59 60 61 |
# File 'lib/epuber/user_interface.rb', line 57 def self.print_processing_problem(problem) _clear_processing_line_for_new_output do $stdout.puts(problem.to_s.ansi.send(_color_from_level(:warning))) end end |
.processing_files_done ⇒ Object
104 105 106 107 108 |
# File 'lib/epuber/user_interface.rb', line 104 def self.processing_files_done remove_processing_file_line @current_file = nil end |
.remove_processing_file_line ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/epuber/user_interface.rb', line 92 def self.remove_processing_file_line last_line = @last_processing_file_line unless @last_processing_file_line.nil? $stdout.print("\033[2K") # remove line, but without moving cursor $stdout.print("\r") # go to beginning of line @last_processing_file_line = nil end last_line end |
.warning(message, location: nil) ⇒ Object
45 46 47 48 49 |
# File 'lib/epuber/user_interface.rb', line 45 def self.warning(, location: nil) _clear_processing_line_for_new_output do $stdout.puts((:warning, , location: location)) end end |