notify
[rainbowstream.git] / rainbowstream / rainbow.py
index 51ab7ddd956563a5f942d1138ac27004765579ad..d69f6026f3c11a183d2d6f2d32ff79ae4a3625d5 100644 (file)
@@ -775,12 +775,14 @@ def theme():
             # Detect custom config
             if theme == 'custom':
                 line += light_magenta('custom')
-                exists = db.theme_query()
-                themes = [t.theme_name for t in exists]
-                if themes[0] == 'custom':
-                    line += light_magenta(' (applied)')
+                custom_path = os.environ.get(
+                    'HOME',
+                    os.environ.get('USERPROFILE',
+                        '')) + os.sep + '.rainbow_config.json'
+                if not os.path.exists(custom_path):
+                    line += light_magenta(' (create your own config file at ~/.rainbow_config.json)')
                 else:
-                    line += light_magenta(' (not specified)')
+                    line += light_magenta(' (loaded)')
             else:
                 line += light_magenta(theme)
             if c['theme'] == theme :
@@ -792,19 +794,30 @@ def theme():
         # Change theme
         try:
             # Load new config
-            new_config = 'rainbowstream/colorset/' + g['stuff'] + '.json'
+            c['theme'] = g['stuff']
+            if g['stuff'] != 'custom':
+                new_config = 'rainbowstream/colorset/' + g['stuff'] + '.json'
+            else:
+                new_config = os.environ.get(
+                    'HOME',os.environ.get(
+                        'USERPROFILE',
+                        '')) + os.sep + '.rainbow_config.json'
             new_config = load_config(new_config)
             if new_config:
                 for nc in new_config:
                     c[nc] = new_config[nc]
-            # Update db
+            # Update db and reset colors
             db.theme_update(g['stuff'])
+            notify_cycle()
             g['decorated_name'] = color_func(
                 c['DECORATED_NAME'])(
                 '[@' + g['original_name'] + ']: ')
             printNicely(green('Theme changed.'))
         except:
-            printNicely(red('Sorry, config file is broken!'))
+            if g['stuff'] == 'custom':
+                printNicely(light_magenta('~/.rainbow_config.json is not exists!'))
+            else:
+                printNicely(red('No such theme exists.'))
 
 
 def help():