Themes fall back to default.py for missing segment

This commit is contained in:
Saswat Padhi 2013-09-17 01:39:53 +05:30
parent a746281f3c
commit fd331d0461
5 changed files with 22 additions and 5 deletions

View file

@ -18,7 +18,7 @@ A [Powerline](https://github.com/Lokaltog/vim-powerline) like prompt for Bash, Z
This script uses ANSI color codes to display colors in a terminal. These are
notoriously non-portable, so may not work for you out of the box, but try
setting your $TERM to xterm-256color, because that works for me.
setting your $TERM to `xterm-256color`, because that works for me.
* Patch the font you use for your terminal: see https://github.com/Lokaltog/powerline-fonts
@ -114,10 +114,15 @@ Make sure that your script does not introduce new globals which might conflict
with other scripts. Your script should fail silently and run quickly in any
scenario.
Make sure you introduce new default colors in `themes/default.py` for every new
segment you create. Test your segment with this theme first.
### Themes
The `themes` directory stores themes for your prompt, which are basically color
values used by segments. Create a new theme by copying `themes/default.py` and
values used by segments. The `default.py` defines a default theme which can be
used standalone, and every other theme falls back to it if they miss colors for
any segments. Create new themes by copying any other existing theme and
changing the values. To use a theme, set the `THEME` variable in `config.py` to
the name of your theme.

View file

@ -24,6 +24,7 @@ def load_source(srcfile):
if __name__ == "__main__":
source = load_source(TEMPLATE_FILE)
source += load_source(os.path.join(THEMES_DIR, 'default.py'))
source += load_source(os.path.join(THEMES_DIR, config.THEME + '.py'))
for segment in config.SEGMENTS:
source += load_source(os.path.join(SEGMENTS_DIR, segment + '.py'))

View file

@ -1,6 +1,6 @@
# Basic theme which only uses colors in 0-15 range
class Color:
class Color(DefaultColor):
USERNAME_FG = 8
USERNAME_BG = 15

View file

@ -1,4 +1,8 @@
class Color:
class DefaultColor:
"""
This class should have the default colors for every segment.
Please test every new segment with this theme first.
"""
USERNAME_FG = 250
USERNAME_BG = 240
@ -34,3 +38,10 @@ class Color:
VIRTUAL_ENV_BG = 35 # a mid-tone green
VIRTUAL_ENV_FG = 00
class Color(DefaultColor):
"""
This subclass is required when the user chooses to use 'default' theme.
Because the segments require a 'Color' class for every theme.
"""
pass

View file

@ -1,4 +1,4 @@
class Color:
class Color(DefaultColor):
USERNAME_FG = 15
USERNAME_BG = 4