mirror of
https://github.com/b-ryan/powerline-shell.git
synced 2026-09-10 07:26:28 -04:00
Merge 4a4184bb66 into 4b19aa47f1
This commit is contained in:
commit
a760c1633d
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -10,21 +10,11 @@ from .utils import py3
|
|||
|
||||
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ class Segment(BasicSegment):
|
|||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue