Class: Shoes::Console
- Inherits:
-
Object
- Object
- Shoes::Console
- Defined in:
- shoes-core/lib/shoes/console.rb
Instance Attribute Summary collapse
-
#message_stacks ⇒ Object
readonly
Returns the value of attribute message_stacks.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #add_message(type, message) ⇒ Object
- #add_message_stack(type, message, index = nil) ⇒ Object
- #clear ⇒ Object
- #copy ⇒ Object
- #create_app ⇒ Object
- #debug(message) ⇒ Object
- #drain_queued_messages ⇒ Object
- #error(message) ⇒ Object
- #formatted_messages ⇒ Object
- #info(message) ⇒ Object
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #save ⇒ Object
- #show ⇒ Object
- #showing? ⇒ Boolean
- #warn(message) ⇒ Object
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
7 8 9 10 11 12 |
# File 'shoes-core/lib/shoes/console.rb', line 7 def initialize @queued_messages = Queue.new @messages = [] @message_stacks = [] end |
Instance Attribute Details
#message_stacks ⇒ Object (readonly)
Returns the value of attribute message_stacks.
5 6 7 |
# File 'shoes-core/lib/shoes/console.rb', line 5 def @message_stacks end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
5 6 7 |
# File 'shoes-core/lib/shoes/console.rb', line 5 def @messages end |
Instance Method Details
#add_message(type, message) ⇒ Object
91 92 93 94 |
# File 'shoes-core/lib/shoes/console.rb', line 91 def (type, ) @messages << [type, ] (type, , @messages.count - 1) end |
#add_message_stack(type, message, index = nil) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'shoes-core/lib/shoes/console.rb', line 96 def (type, , index = nil) return unless defined?(@app) && @app.open? @app.instance_exec do append do @console. << stack do background "#f1f5e1" if index.even? background rgb(220, 220, 220) if index.odd? para type, stroke: blue flow do stack margin: 4 do s = .to_s para s, margin: 4, margin_top: 0 end end end end end end |
#clear ⇒ Object
136 137 138 139 140 141 |
# File 'shoes-core/lib/shoes/console.rb', line 136 def clear .clear .each(&:remove) .clear end |
#copy ⇒ Object
122 123 124 |
# File 'shoes-core/lib/shoes/console.rb', line 122 def copy @app.clipboard = if .any? end |
#create_app ⇒ Object
26 27 28 29 30 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 |
# File 'shoes-core/lib/shoes/console.rb', line 26 def create_app # Capture ourself for access inside our app block console = self @app = Shoes.app do @console = console stack do flow do background black stack do tagline "Shoes Console", stroke: white end "Copy", margin: 6, width: 80, height: 40, right: 170 do @console.copy end "Save", margin: 6, width: 80, height: 40, right: 90 do @console.save end "Clear", margin: 6, width: 80, height: 40, right: 10 do @console.clear end end end every 0.1 do # Periodically update UI with new log lines @console. end end # Synchronously drain queue first showing console end |
#debug(message) ⇒ Object
75 76 77 |
# File 'shoes-core/lib/shoes/console.rb', line 75 def debug() @queued_messages << [:debug, ] end |
#drain_queued_messages ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'shoes-core/lib/shoes/console.rb', line 64 def 10.times do # Non-blocking = true, so will raise ThreadError once we're done type, = @queued_messages.pop(true) (type, ) end rescue ThreadError # rubocop:disable Lint/HandleExceptions # Queue's drained, carry on! # Disabled cop because this is Queue#pop's non-blocking API end |
#error(message) ⇒ Object
87 88 89 |
# File 'shoes-core/lib/shoes/console.rb', line 87 def error() @queued_messages << [:error, ] end |
#formatted_messages ⇒ Object
116 117 118 119 120 |
# File 'shoes-core/lib/shoes/console.rb', line 116 def @messages.inject("") do |memo, (type, )| "#{memo}#{type.to_s.capitalize}\n #{}\n\n" end end |
#info(message) ⇒ Object
79 80 81 |
# File 'shoes-core/lib/shoes/console.rb', line 79 def info() @queued_messages << [:info, ] end |
#save ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'shoes-core/lib/shoes/console.rb', line 126 def save filename = @app.ask_save_file return unless filename File.open(filename, "w") do |f| f.write() end end |
#show ⇒ Object
14 15 16 17 18 19 20 |
# File 'shoes-core/lib/shoes/console.rb', line 14 def show if showing? @app.focus else create_app end end |
#showing? ⇒ Boolean
22 23 24 |
# File 'shoes-core/lib/shoes/console.rb', line 22 def showing? @app&.open? end |
#warn(message) ⇒ Object
83 84 85 |
# File 'shoes-core/lib/shoes/console.rb', line 83 def warn() @queued_messages << [:warn, ] end |