Module: Lijab::Out

Defined in:
lib/lijab/out.rb

Class Method Summary collapse

Class Method Details

.clear_infolineObject



157
158
159
160
161
162
# File 'lib/lijab/out.rb', line 157

def clear_infoline
   @monitor.synchronize do
      print "#{ANSI.savepos}\n#{ANSI.clearline}#{ANSI.restorepos}"
      STDOUT.flush
   end
end

.error(s, redisplay_input = true) ⇒ Object



143
144
145
146
# File 'lib/lijab/out.rb', line 143

def error(s, redisplay_input=true)
   puts "#{ANSI.cleartoeol}error: #{s}".red.bold
   InputHandler::redisplay_input if redisplay_input
end

.format_message_in(from, text, colors, time) ⇒ Object



40
41
42
# File 'lib/lijab/out.rb', line 40

def format_message_in(from, text, colors, time)
   "#{ANSI.clearline}#{time}#{from} -> ".colored(*colors) + text
end

.format_message_out(to, text, colors, time) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lijab/out.rb', line 44

def format_message_out(to, text, colors, time)

   prefix = "#{time}#{to} <- "
   indent = " " * prefix.length

   lines = text.to_a
   s = []

   s << "#{ANSI.clearline}#{prefix.colored(*colors)}#{lines.shift.chomp}"
   lines.each do |l|
      s << "#{ANSI.clearline}#{indent}#{l.chomp}"
   end

   s.join("\n")
end

.format_time(time = nil, format = :datetime_format) ⇒ Object



33
34
35
36
37
38
# File 'lib/lijab/out.rb', line 33

def format_time(time=nil, format=:datetime_format)
   return "" unless time
   time = Time.now if time == :now

   "#{time.strftime(Config.opts[format])} "
end

.history(*log_entries) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/lijab/out.rb', line 125

def history(*log_entries)
   log_entries.each do |e|
      contact = Main.contacts[Jabber::JID.new(e[:target])]
      target_s = contact ? contact.simple_name : e[:target]
      colors = contact ? [contact.color] : []
      time = format_time(e[:time].localtime, :history_datetime_format)

      if e[:direction] == :from
         colors << :bold
         m = method(:format_message_in)
      else
         m = method(:format_message_out)
      end

      puts m.call(target_s, e[:msg], colors, time)
   end
end

.infoline(s) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/lijab/out.rb', line 148

def infoline(s)
   @monitor.synchronize do
      print "#{ANSI.savepos}#{ANSIMove.down(1)}#{ANSI.clearline}"
      print s
      print "#{ANSI.restorepos}"
      STDOUT.flush
   end
end

.make_infolineObject



164
165
166
167
168
169
# File 'lib/lijab/out.rb', line 164

def make_infoline
   @monitor.synchronize do
      print "\n\r#{ANSI.cleartoeol}#{ANSIMove.up(1)}"
      STDOUT.flush
   end
end

.message_in(from, text, colors = []) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lijab/out.rb', line 60

def message_in(from, text, colors=[])
   @monitor.synchronize do
      clear_infoline()
      InputHandler::delete_typed

      notice_if_day_changed()

      print "\a" if Config.opts[:terminal_bell_on_message]
      puts format_message_in(from, text, colors, format_time(:now))

      InputHandler::redisplay_input
   end
end

.message_out(to, text, colors = []) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/lijab/out.rb', line 74

def message_out(to, text, colors=[])
   @monitor.synchronize do
      InputHandler::delete_last_typed

      notice_if_day_changed(false)

      puts format_message_out(to, text, colors, format_time(:now))
   end
end

.notice_if_day_changed(redisplay_input = true) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/lijab/out.rb', line 24

def notice_if_day_changed(redisplay_input=true)
   t = Time.now
   if @time.day != t.day
      ft = @time.strftime('%Y-%M-%d')
      @time = t
      puts "#{ANSI.clearline}** day changed -- #{ft} -> #{Date.today}".green
   end
end

.presence(from, presence, colors = []) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/lijab/out.rb', line 84

def presence(from, presence, colors=[])
   @monitor.synchronize do
      clear_infoline()
      InputHandler::delete_typed

      notice_if_day_changed()

      print "#{ANSI.clearline}"
      print "** #{format_time(:now)}#{from} (#{presence.priority || 0}) is now ".colored(*colors)
      puts presence.pretty(true)

      InputHandler::redisplay_input
   end
end

.put(s = "\n", redisplay_input = false) ⇒ Object



18
19
20
21
22
# File 'lib/lijab/out.rb', line 18

def put(s="\n", redisplay_input=false)
   #clear_infoline()
   puts "#{ANSI.clearline}#{s}"
   InputHandler::redisplay_input if redisplay_input
end

.subscription(from, type, msg = nil, colors = []) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/lijab/out.rb', line 99

def subscription(from, type, msg=nil, colors=[])
   @monitor.synchronize do
      clear_infoline()
      InputHandler::delete_typed

      notice_if_day_changed()

      time = format_time(:now)
      case type
      when :subscribe
         indent = ' ' * time.length
         s = "** #{time}subscription request from #{from} received:\n"
         s += %{"#{msg}"\n} if msg
         s += "** See '/help requests' to see how to handle requests."
      when :subscribed
         s = "** #{time}#{from} has subscribed to you"
      when :unsubscribed
         s = "** #{time}#{from} has unsubscribed from you"
      end

      puts "#{ANSI.clearline}#{s}"

      InputHandler::redisplay_input
   end
end