Module: INat::App::Status
- Defined in:
- lib/inat/app/status.rb
Overview
TODO: переделать на отдельный поток и очередь статусов. Ввести отдельно ключ, как идентификатор запроса, например.
Class Method Summary collapse
Instance Method Summary collapse
- #ellipsis(src, len) ⇒ Object private
- #status(str) ⇒ Object private
Class Method Details
.init ⇒ Object
20 21 22 23 24 |
# File 'lib/inat/app/status.rb', line 20 def init @lines = {} @mutex = Mutex::new @shift = 0 end |
.out ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/inat/app/status.rb', line 30 def out $stderr.print "\e[0K\n" @lines.each do |key, value| $stderr.print "#{ value }\e[0K\n" end $stderr.print "\e[0K\n" @shift = @lines.size + 2 end |
.status(key, value) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/inat/app/status.rb', line 47 def status key, value task = ellipsis G.current_task&.name, 16 key = task if key == nil line = format("%16s | %s", key.to_s, value) @mutex.synchronize do @lines ||= {} @lines[key] = line up out end end |
.up ⇒ Object
26 27 28 |
# File 'lib/inat/app/status.rb', line 26 def up $stderr.print "\e[#{ @shift }A\r" if @shift > 0 end |
.wrap ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/inat/app/status.rb', line 39 def wrap @mutex.synchronize do up yield out end end |
Instance Method Details
#ellipsis(src, len) ⇒ Object (private)
11 12 13 14 15 16 17 18 |
# File 'lib/inat/app/status.rb', line 11 private def ellipsis src, len return '' unless String === src if src.length <= len src else src[.. len - 4] + '...' end end |
#status(str) ⇒ Object (private)
61 62 63 |
# File 'lib/inat/app/status.rb', line 61 private def status str self.class.status str end |