Class: Mchat::Timeline
- Inherits:
-
Object
- Object
- Mchat::Timeline
- Defined in:
- lib/mchat/timeline.rb
Instance Method Summary collapse
- #api_bossmode ⇒ Object
-
#api_clear ⇒ Object
约定和cli交互用api_xx方法.
- #api_close_window ⇒ Object
- #boss_will_see_fake_logs ⇒ Object
- #dispatch(m) ⇒ Object
- #hook_close ⇒ Object
-
#initialize ⇒ Timeline
constructor
A new instance of Timeline.
- #run ⇒ Object
Constructor Details
Instance Method Details
#api_bossmode ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mchat/timeline.rb', line 30 def api_bossmode # toggle api @boss_mode = !@boss_mode thx = nil if @boss_mode system('clear') boss_will_see_fake_logs else sleep 2 system('clear') puts "======= Recover last 100 ===========" @reader.(100).each do |m| if m.is_a? String || Rainbow::Presenter puts m end end puts "======= Recover last 100 ===========" end end |
#api_clear ⇒ Object
约定和cli交互用api_xx方法
26 27 28 |
# File 'lib/mchat/timeline.rb', line 26 def api_clear system('clear') end |
#api_close_window ⇒ Object
51 52 53 |
# File 'lib/mchat/timeline.rb', line 51 def api_close_window @reader. = false end |
#boss_will_see_fake_logs ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mchat/timeline.rb', line 73 def boss_will_see_fake_logs fake_logs = File.open(Pathname.new(File.join(__dir__, './fake_log.txt'))).readlines thx = Thread.new { while @boss_mode fake_logs.each do |line| puts line sleep 0.1 end end } end |
#dispatch(m) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mchat/timeline.rb', line 61 def dispatch(m) cmd_name = m.name data = m.data || nil api_name = "api_#{cmd_name}".to_sym if data __send__(api_name, data) else __send__(api_name) end end |
#hook_close ⇒ Object
55 56 57 58 59 |
# File 'lib/mchat/timeline.rb', line 55 def hook_close @reader.hook_quit system('screen -X quit') exit 0 end |
#run ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mchat/timeline.rb', line 85 def run @reader. { || .each do |m| if m.is_a? String || Rainbow::Presenter if !@boss_mode puts m end elsif m.is_a? Mchat::TimelineCommand dispatch(m) end end } hook_close end |