add info and colored
[rainbowstream.git] / rainbowstream / draw.py
index e123ba9..747a68b 100644 (file)
@@ -340,7 +340,6 @@ def print_thread(partner, me_nick, me_name):
     # Sort messages by time
     messages = dg['thread'][partner]
     messages.sort(key = lambda x:parser.parse(x['created_at']))
-
     # Print the 1st line
     dg['message_thread_margin'] = margin = 2
     left_size = len(partner[0])+len(partner[1]) + margin
@@ -357,7 +356,6 @@ def print_thread(partner, me_nick, me_name):
     printNicely('')
     printNicely(line)
     printNicely('')
-
     # Print messages
     for m in messages:
         if m['sender_screen_name'] == me_nick:
@@ -377,7 +375,8 @@ def print_right_message(m):
     slicing = [m['text'][i:i+step] for i in range(0, len(m['text']), step)]
     spaces = w - frame_width - dg['message_thread_margin']
     dotline = ' ' * spaces + '-' * frame_width
-
+    dotline = color_func(c['MESSAGE']['me_bg'])(dotline)
+    # Draw the frame
     printNicely(dotline)
     for line in slicing:
         fill = step - len(line)
@@ -386,8 +385,31 @@ def print_right_message(m):
             screen_line = screen_line + ' >'
         else:
             screen_line = screen_line + '|'
+        screen_line = color_func(c['MESSAGE']['me_bg'])(screen_line)
         printNicely(screen_line)
     printNicely(dotline)
+    # Print clock
+    date = parser.parse(m['created_at'])
+    date = arrow.get(date).to('local').datetime
+    clock_format = '%Y/%m/%d %H:%M:%S'
+    try:
+        clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
+    except:
+        pass
+    clock = date.strftime(clock_format)
+    # Get rainbow id
+    if m['id'] not in c['message_dict']:
+        c['message_dict'].append(m['id'])
+        rid = len(c['message_dict']) - 1
+    else:
+        rid = c['message_dict'].index(m['id'])
+    rid = str(rid)
+    # Create line and print
+    meta = color_func(c['MESSAGE']['clock'])(clock) + \
+        color_func(c['MESSAGE']['id'])(' ('+rid+')')
+    line = ' ' * (w - len(clock + rid) - 3 - dg['message_thread_margin']) + \
+        meta
+    printNicely(line)
 
 
 def print_left_message(m):
@@ -401,7 +423,8 @@ def print_left_message(m):
     slicing = [m['text'][i:i+step] for i in range(0, len(m['text']), step)]
     spaces = dg['message_thread_margin']
     dotline = ' ' * spaces + '-' * frame_width
-
+    dotline = color_func(c['MESSAGE']['partner_bg'])(dotline)
+    # Draw the frame
     printNicely(dotline)
     for line in slicing:
         fill = step - len(line)
@@ -410,8 +433,31 @@ def print_left_message(m):
             screen_line = ' ' * (spaces-1) + '< ' + screen_line
         else:
             screen_line = ' ' * spaces + '|' + screen_line
+        screen_line = color_func(c['MESSAGE']['partner_bg'])(screen_line)
         printNicely(screen_line)
     printNicely(dotline)
+    # Print clock
+    date = parser.parse(m['created_at'])
+    date = arrow.get(date).to('local').datetime
+    clock_format = '%Y/%m/%d %H:%M:%S'
+    try:
+        clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
+    except:
+        pass
+    clock = date.strftime(clock_format)
+    # Get rainbow id
+    if m['id'] not in c['message_dict']:
+        c['message_dict'].append(m['id'])
+        rid = len(c['message_dict']) - 1
+    else:
+        rid = c['message_dict'].index(m['id'])
+    rid = str(rid)
+    # Create line and print
+    meta = color_func(c['MESSAGE']['clock'])(clock) + \
+        color_func(c['MESSAGE']['id'])(' ('+rid+')')
+    line = ' ' * dg['message_thread_margin'] + \
+        meta
+    printNicely(line)
 
 
 def print_message(m):