diff --git a/README.md b/README.md index e6295711..73ded26d 100644 --- a/README.md +++ b/README.md @@ -299,11 +299,14 @@ The options for the `cwd` segment are: - `full_cwd`: If true, the last directory will not be shortened when `max_dir_size` is used. -The `hostname` segment provides one option: +The `hostname` segment provides two options: - `colorize`: If true, the hostname will be colorized based on a hash of itself. +- `dark`: If true (and colorize=true), a bright color will be used as the + background color + The `vcs` segment provides one option: - `show_symbol`: If `true`, the version control system segment will start with diff --git a/powerline_shell/color_compliment.py b/powerline_shell/color_compliment.py index f0517115..16bbc3e3 100644 --- a/powerline_shell/color_compliment.py +++ b/powerline_shell/color_compliment.py @@ -10,21 +10,11 @@ def getOppositeColor(r,g,b): - r, g, b = [x/255.0 for x in [r, g, b]] # convert to float before getting hls value - hls = rgb_to_hls(r,g,b) - opp = list(hls[:]) - opp[0] = (opp[0]+0.2)%1 # shift hue (a.k.a. color) - if opp[1] > 255/2: # for level you want to make sure they - opp[1] -= 255/2 # are quite different so easily readable - else: - opp[1] += 255/2 - if opp[2] > -0.5: # if saturation is low on first color increase second's - opp[2] -= 0.5 - opp = hls_to_rgb(*opp) - m = max(opp) - if m > 255: #colorsys module doesn't give caps to their conversions - opp = [ x*254/m for x in opp] - return tuple([ int(x) for x in opp]) + """returns RGB components of complementary color""" + # colorsys functions expect values to be between 0 and 1 + hls = rgb_to_hls(r, g, b) # r,g,b are now between 0 and 1 + opp = hls_to_rgb(*[ (x+0.5)%1 for x in hls ]) + return tuple([ int(x*255) for x in opp ]) # convert back to value range 0-255 def stringToHashToColorAndOpposite(string): if py3: diff --git a/powerline_shell/segments/hostname.py b/powerline_shell/segments/hostname.py index 894e139e..79546af9 100644 --- a/powerline_shell/segments/hostname.py +++ b/powerline_shell/segments/hostname.py @@ -10,6 +10,11 @@ def add_to_powerline(self): if powerline.segment_conf("hostname", "colorize"): hostname = gethostname() FG, BG = stringToHashToColorAndOpposite(hostname) + # if we operate on a dark background then + # we want the brighter color to always be the + # background color + if powerline.segment_conf("hostname", "dark") and sum(FG) > sum(BG): + FG,BG = BG,FG FG, BG = (rgb2short(*color) for color in [FG, BG]) host_prompt = " %s " % hostname.split(".")[0] powerline.append(host_prompt, FG, BG)