color names and fixes

- fix for packageName truncated by POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER
     - processing the pwd/HOME replacement ONCE.
     - fix tests for named colors
     - use color names by default to allow dark/light themes to adjust colors based on names
pull/22/head
Charles Peterson 7 years ago
parent 87acc51aca
commit 264897a426

1
.gitignore vendored

@ -1,2 +1,3 @@
test-vm/.vagrant
*.swp
.idea

@ -243,7 +243,7 @@ battery level. This will override the following variables:
`POWERLEVEL9K_BATTERY_DISCONNECTED`, and `POWERLEVEL9K_BATTERY_LOW_COLOR`. In
order to do this, define a color array, from low to high, as shown below:
```zsh
POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND=(196 202 208 214 220 226 190 154 118 82 46)
POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND=(red1 orangered1 darkorange orange1 gold1 yellow1 yellow2 greenyellow chartreuse1 chartreuse2 green1)
```
As with the battery stages, you can use any number of colors and Powerlevel9k
@ -251,9 +251,9 @@ will automatically use all of them appropriately.
Some example settings:
|Brightness|Possible Array|
|Bright Colors|(196 202 208 214 220 226 190 154 118 82 46)|
|Normal Colors|(124 130 136 142 148 112 76 40 34 28 22)|
|Subdued Colors|( 88 94 100 106 70 34 28 22)|
|Bright Colors|(red1 orangered1 darkorange orange1 gold1 yellow1 yellow2 greenyellow chartreuse1 chartreuse2 green1)|
|Normal Colors|(red3 darkorange3 darkgoldenrod gold3 yellow3 chartreuse2 mediumspringgreen green3 green3 green4 darkgreen)|
|Subdued Colors|(darkred orange4 yellow4 yellow4 chartreuse3 green3 green4 darkgreen)|
##### command_execution_time

@ -22,14 +22,264 @@ function getColorCode() {
else
typeset -A codes
codes=(
'black' '000'
'red' '001'
'green' '002'
'yellow' '003'
'blue' '004'
'magenta' '005'
'cyan' '006'
'white' '007'
# https://jonasjacek.github.io/colors/
# use color names by default to allow dark/light themes to adjust colors based on names
'black' '000'
'maroon' '001'
'green' '002'
'olive' '003'
'navy' '004'
'purple' '005'
'teal' '006'
'silver' '007'
'grey' '008'
'red' '009'
'lime' '010'
'yellow' '011'
'blue' '012'
'fuchsia' '013'
'aqua' '014'
'white' '015'
'grey0' '016'
'navyblue' '017'
'darkblue' '018'
'blue3' '019'
'blue3' '020'
'blue1' '021'
'darkgreen' '022'
'deepskyblue4' '023'
'deepskyblue4' '024'
'deepskyblue4' '025'
'dodgerblue3' '026'
'dodgerblue2' '027'
'green4' '028'
'springgreen4' '029'
'turquoise4' '030'
'deepskyblue3' '031'
'deepskyblue3' '032'
'dodgerblue1' '033'
'green3' '034'
'springgreen3' '035'
'darkcyan' '036'
'lightseagreen' '037'
'deepskyblue2' '038'
'deepskyblue1' '039'
'green3' '040'
'springgreen3' '041'
'springgreen2' '042'
'cyan3' '043'
'darkturquoise' '044'
'turquoise2' '045'
'green1' '046'
'springgreen2' '047'
'springgreen1' '048'
'mediumspringgreen' '049'
'cyan2' '050'
'cyan1' '051'
'darkred' '052'
'deeppink4' '053'
'purple4' '054'
'purple4' '055'
'purple3' '056'
'blueviolet' '057'
'orange4' '058'
'grey37' '059'
'mediumpurple4' '060'
'slateblue3' '061'
'slateblue3' '062'
'royalblue1' '063'
'chartreuse4' '064'
'darkseagreen4' '065'
'paleturquoise4' '066'
'steelblue' '067'
'steelblue3' '068'
'cornflowerblue' '069'
'chartreuse3' '070'
'darkseagreen4' '071'
'cadetblue' '072'
'cadetblue' '073'
'skyblue3' '074'
'steelblue1' '075'
'chartreuse3' '076'
'palegreen3' '077'
'seagreen3' '078'
'aquamarine3' '079'
'mediumturquoise' '080'
'steelblue1' '081'
'chartreuse2' '082'
'seagreen2' '083'
'seagreen1' '084'
'seagreen1' '085'
'aquamarine1' '086'
'darkslategray2' '087'
'darkred' '088'
'deeppink4' '089'
'darkmagenta' '090'
'darkmagenta' '091'
'darkviolet' '092'
'purple' '093'
'orange4' '094'
'lightpink4' '095'
'plum4' '096'
'mediumpurple3' '097'
'mediumpurple3' '098'
'slateblue1' '099'
'yellow4' '100'
'wheat4' '101'
'grey53' '102'
'lightslategrey' '103'
'mediumpurple' '104'
'lightslateblue' '105'
'yellow4' '106'
'darkolivegreen3' '107'
'darkseagreen' '108'
'lightskyblue3' '109'
'lightskyblue3' '110'
'skyblue2' '111'
'chartreuse2' '112'
'darkolivegreen3' '113'
'palegreen3' '114'
'darkseagreen3' '115'
'darkslategray3' '116'
'skyblue1' '117'
'chartreuse1' '118'
'lightgreen' '119'
'lightgreen' '120'
'palegreen1' '121'
'aquamarine1' '122'
'darkslategray1' '123'
'red3' '124'
'deeppink4' '125'
'mediumvioletred' '126'
'magenta3' '127'
'darkviolet' '128'
'purple' '129'
'darkorange3' '130'
'indianred' '131'
'hotpink3' '132'
'mediumorchid3' '133'
'mediumorchid' '134'
'mediumpurple2' '135'
'darkgoldenrod' '136'
'lightsalmon3' '137'
'rosybrown' '138'
'grey63' '139'
'mediumpurple2' '140'
'mediumpurple1' '141'
'gold3' '142'
'darkkhaki' '143'
'navajowhite3' '144'
'grey69' '145'
'lightsteelblue3' '146'
'lightsteelblue' '147'
'yellow3' '148'
'darkolivegreen3' '149'
'darkseagreen3' '150'
'darkseagreen2' '151'
'lightcyan3' '152'
'lightskyblue1' '153'
'greenyellow' '154'
'darkolivegreen2' '155'
'palegreen1' '156'
'darkseagreen2' '157'
'darkseagreen1' '158'
'paleturquoise1' '159'
'red3' '160'
'deeppink3' '161'
'deeppink3' '162'
'magenta3' '163'
'magenta3' '164'
'magenta2' '165'
'darkorange3' '166'
'indianred' '167'
'hotpink3' '168'
'hotpink2' '169'
'orchid' '170'
'mediumorchid1' '171'
'orange3' '172'
'lightsalmon3' '173'
'lightpink3' '174'
'pink3' '175'
'plum3' '176'
'violet' '177'
'gold3' '178'
'lightgoldenrod3' '179'
'tan' '180'
'mistyrose3' '181'
'thistle3' '182'
'plum2' '183'
'yellow3' '184'
'khaki3' '185'
'lightgoldenrod2' '186'
'lightyellow3' '187'
'grey84' '188'
'lightsteelblue1' '189'
'yellow2' '190'
'darkolivegreen1' '191'
'darkolivegreen1' '192'
'darkseagreen1' '193'
'honeydew2' '194'
'lightcyan1' '195'
'red1' '196'
'deeppink2' '197'
'deeppink1' '198'
'deeppink1' '199'
'magenta2' '200'
'magenta1' '201'
'orangered1' '202'
'indianred1' '203'
'indianred1' '204'
'hotpink' '205'
'hotpink' '206'
'mediumorchid1' '207'
'darkorange' '208'
'salmon1' '209'
'lightcoral' '210'
'palevioletred1' '211'
'orchid2' '212'
'orchid1' '213'
'orange1' '214'
'sandybrown' '215'
'lightsalmon1' '216'
'lightpink1' '217'
'pink1' '218'
'plum1' '219'
'gold1' '220'
'lightgoldenrod2' '221'
'lightgoldenrod2' '222'
'navajowhite1' '223'
'mistyrose1' '224'
'thistle1' '225'
'yellow1' '226'
'lightgoldenrod1' '227'
'khaki1' '228'
'wheat1' '229'
'cornsilk1' '230'
'grey100' '231'
'grey3' '232'
'grey7' '233'
'grey11' '234'
'grey15' '235'
'grey19' '236'
'grey23' '237'
'grey27' '238'
'grey30' '239'
'grey35' '240'
'grey39' '241'
'grey42' '242'
'grey46' '243'
'grey50' '244'
'grey54' '245'
'grey58' '246'
'grey62' '247'
'grey66' '248'
'grey70' '249'
'grey74' '250'
'grey78' '251'
'grey82' '252'
'grey85' '253'
'grey89' '254'
'grey93' '255'
)
# Strip eventual "bg-" prefixes
@ -53,4 +303,3 @@ function isSameColor() {
return $(( color1 != color2 ))
}

@ -569,7 +569,7 @@ prompt_context() {
typeset -AH context_states
context_states=(
"ROOT" "yellow"
"DEFAULT" "011"
"DEFAULT" "yellow"
)
local content=""
@ -612,7 +612,7 @@ prompt_user() {
"STATE" "DEFAULT"
"CONTENT" "$(whoami)"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
"FOREGROUND_COLOR" "011"
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "USER_ICON"
)
fi
@ -639,7 +639,7 @@ prompt_host() {
"STATE" "LOCAL"
"CONTENT" "${POWERLEVEL9K_HOST_TEMPLATE}"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
"FOREGROUND_COLOR" "011"
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "HOST_ICON"
)
fi
@ -686,7 +686,7 @@ prompt_command_execution_time() {
fi
if (( _P9K_COMMAND_DURATION >= POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )); then
"$1_prompt_segment" "$0" "$2" "red" "226" "${humanReadableDuration}" 'EXECUTION_TIME_ICON'
"$1_prompt_segment" "$0" "$2" "red" "yellow1" "${humanReadableDuration}" 'EXECUTION_TIME_ICON'
fi
}
@ -701,10 +701,10 @@ prompt_dir() {
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
truncate_middle)
current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g")
current_path=$(echo "$current_path" | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g")
;;
truncate_from_right)
current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
current_path=$(truncatePathFromRight "$current_path" )
;;
truncate_with_package_name)
local name repo_path package_path current_dir zero
@ -754,8 +754,12 @@ prompt_dir() {
# Instead of printing out the full path, print out the name of the package
# from the package.json and append the current subdirectory
current_path="`echo $packageName | tr -d '"'`$subdirectory_path"
if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then
# add space before the packageName to allow for removing the "first" character, without messing up the package name.
current_path=" ${current_path}"
fi
else
current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
current_path=$(truncatePathFromRight "$current_path" )
fi
;;
truncate_with_folder_marker)
@ -858,13 +862,13 @@ prompt_go_version() {
go_path=$(go env GOPATH 2>/dev/null)
if [[ -n "$go_version" && "${PWD##$go_path}" != "$PWD" ]]; then
"$1_prompt_segment" "$0" "$2" "green" "255" "$go_version" "GO_ICON"
"$1_prompt_segment" "$0" "$2" "green" "grey93" "$go_version" "GO_ICON"
fi
}
# Command number (in local history)
prompt_history() {
"$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h'
"$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" '%h'
}
# Detection for virtualization (systemd based systems only)
@ -1026,7 +1030,7 @@ prompt_nodeenv() {
# print a little OS icon
prompt_os_icon() {
"$1_prompt_segment" "$0" "$2" "black" "255" "$OS_ICON"
"$1_prompt_segment" "$0" "$2" "black" "white" "$OS_ICON"
}
# print PHP version number
@ -1035,7 +1039,7 @@ prompt_php_version() {
php_version=$(php -v 2>&1 | grep -oe "^PHP\s*[0-9.]*")
if [[ -n "$php_version" ]]; then
"$1_prompt_segment" "$0" "$2" "013" "255" "$php_version"
"$1_prompt_segment" "$0" "$2" "fuchsia" "grey93" "$php_version"
fi
}
@ -1101,7 +1105,7 @@ prompt_rust_version() {
rust_version=$(rustc --version 2>&1 | grep -oe "^rustc\s*[^ ]*" | grep -o '[0-9.a-z\\\-]*$')
if [[ -n "$rust_version" ]]; then
"$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version" 'RUST_ICON'
"$1_prompt_segment" "$0" "$2" "darkorange" "$DEFAULT_COLOR" "Rust $rust_version" 'RUST_ICON'
fi
}
# RSpec test ratio
@ -1120,7 +1124,7 @@ prompt_rvm() {
local version_and_gemset=${rvm_env_string/ruby-}
if [[ -n "$version_and_gemset" ]]; then
"$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON'
"$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON'
fi
}
@ -1176,7 +1180,7 @@ prompt_status() {
if (( ec_sum > 0 )); then
if [[ "$POWERLEVEL9K_STATUS_CROSS" == false && "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then
"$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$ec_text" 'CARRIAGE_RETURN_ICON'
"$1_prompt_segment" "$0_ERROR" "$2" "red" "yellow1" "$ec_text" 'CARRIAGE_RETURN_ICON'
else
"$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON'
fi
@ -1225,7 +1229,7 @@ prompt_symfony2_version() {
if [[ -f app/bootstrap.php.cache ]]; then
local symfony2_version
symfony2_version=$(grep " VERSION " app/bootstrap.php.cache | sed -e 's/[^.0-9]*//g')
"$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$symfony2_version" 'SYMFONY_ICON'
"$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$symfony2_version" 'SYMFONY_ICON'
fi
}
@ -1259,7 +1263,7 @@ prompt_todo() {
if $(hash todo.sh 2>&-); then
count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }')
if [[ "$count" = <-> ]]; then
"$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" "$count" 'TODO_ICON'
"$1_prompt_segment" "$0" "$2" "grey50" "$DEFAULT_COLOR" "$count" 'TODO_ICON'
fi
fi
}
@ -1406,7 +1410,7 @@ prompt_swift_version() {
# dir_writable: Display information about the user's permission to write in the current directory
prompt_dir_writable() {
if [[ ! -w "$PWD" ]]; then
"$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "226" "" 'LOCK_ICON'
"$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "yellow1" "" 'LOCK_ICON'
fi
}

@ -28,7 +28,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
_P9K_COMMAND_DURATION=2.03
assertEquals "%K{red} %F{226%}Dur%f %F{226}2.03 %k%F{red}%f " "$(build_left_prompt)"
assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@ -40,7 +40,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0
_P9K_COMMAND_DURATION=0.03
assertEquals "%K{red} %F{226%}Dur%f %F{226}0.03 %k%F{red}%f " "$(build_left_prompt)"
assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}0.03 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@ -53,7 +53,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4
_P9K_COMMAND_DURATION=0.0001
assertEquals "%K{red} %F{226%}Dur%f %F{226}0.0001 %k%F{red}%f " "$(build_left_prompt)"
assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@ -66,7 +66,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() {
POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
_P9K_COMMAND_DURATION=23.5001
assertEquals "%K{red} %F{226%}Dur%f %F{226}23 %k%F{red}%f " "$(build_left_prompt)"
assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@ -77,7 +77,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand()
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
_P9K_COMMAND_DURATION=180
assertEquals "%K{red} %F{226%}Dur%f %F{226}03:00 %k%F{red}%f " "$(build_left_prompt)"
assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION
@ -87,7 +87,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() {
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time)
_P9K_COMMAND_DURATION=7200
assertEquals "%K{red} %F{226%}Dur%f %F{226}02:00:00 %k%F{red}%f " "$(build_left_prompt)"
assertEquals "%K{red} %F{yellow1%}Dur%f %F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unset _P9K_COMMAND_DURATION

@ -40,7 +40,7 @@ function testGo() {
PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k"
assertEquals "%K{green} %F{255%}%f %F{255}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
assertEquals "%K{green} %F{grey93%}%f %F{grey93}go1.5.3 %k%F{green}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_GO_ICON
unset PWD

@ -19,7 +19,7 @@ function testRust() {
alias rustc=mockRust
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version)
assertEquals "%K{208} %F{black}Rust 0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)"
assertEquals "%K{darkorange} %F{black}Rust 0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)"
unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
unalias rustc

Loading…
Cancel
Save