add info and colored
authorOrakaro <nhatminh_179@hotmail.com>
Mon, 25 Aug 2014 01:09:26 +0000 (10:09 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Mon, 25 Aug 2014 01:09:26 +0000 (10:09 +0900)
rainbowstream/colorset/monokai.json
rainbowstream/draw.py
rainbowstream/interactive.py

index 3473aea016439cf1b2dc4c6f888d988db2fc0da8..553be6a708d859adedd2ed20f4b70e1ac28785ac 100644 (file)
     },
 
     "MESSAGE" : {
-        "partner"   : 112,
-        "me"        : 112,
-        "to"        : 50,
-        "clock"     : 57,
-        "id"        : 166
+        "partner"       : 112,
+        "me"            : 112,
+        "me_bg"         : 74,
+        "partner_bg"    : 112,
+        "to"            : 50,
+        "clock"         : 57,
+        "id"            : 166
     },
 
     "PROFILE" : {
index e123ba9806c8603816ec6f7cfe0ec09315468f88..747a68b4d8d9eb1c4136878a47f89a2a67f59f61 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):
index 45b7853bc6829f782e3a057ef480bf3c68083fec..76755e8c21adf85dfc2fddb4835f1889021081b1 100644 (file)
@@ -68,15 +68,20 @@ def read_history():
     """
     Read history file
     """
-    if os.path.isfile(c['HISTORY_FILENAME']):
+    try:
         readline.read_history_file(c['HISTORY_FILENAME'])
+    except:
+        pass
 
 
 def save_history():
     """
     Save history to file
     """
-    readline.write_history_file(c['HISTORY_FILENAME'])
+    try:
+        readline.write_history_file(c['HISTORY_FILENAME'])
+    except:
+        pass
 
 
 def init_interactive_shell(d):