965a5af65e2b5bd1c2109cce9f8638e610709e4d

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #50 from MichaelAquilina/more_colored_output

Colored outputs

Diff

  1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
  2index 8b9253a024c914abc8a88d7ac9e2576736756a01..ce3cbb1f6522f471e83d4e30c500404c69fdb3a2 100644
  3--- a/autoswitch_virtualenv.plugin.zsh
  4+++ b/autoswitch_virtualenv.plugin.zsh
  5@@ -1,28 +1,32 @@
  6 export AUTOSWITCH_VERSION='0.5.0'
  7 
  8+RED="\e[31m"
  9+GREEN="\e[32m"
 10+PURPLE="\e[35m"
 11+BOLD="\e[1m"
 12+NORMAL="\e[0m"
 13+
 14 if ! type workon > /dev/null; then
 15     export DISABLE_AUTOSWITCH_VENV="1"
 16-    printf "\e[1m\e[31m"
 17+    printf "${BOLD}${RED}"
 18     printf "zsh-autoswitch-virtualenv requires virtualenvwrapper to be installed!\n\n"
 19-    printf "\e[0m\e[39m"
 20+    printf "${NORMAL}"
 21     printf "If this is already installed but you are still seeing this message, \nadd the "
 22     printf "following to your ~/.zshrc:\n\n"
 23-    printf "\e[1m"
 24+    printf "${BOLD}"
 25     printf "source =virtualenvwrapper.sh\n"
 26     printf "\n"
 27-    printf "\e[0m"
 28+    printf "${NORMAL}"
 29     printf "https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv#Setup"
 30-    printf "\e[0m"
 31     printf "\n"
 32 fi
 33 
 34-
 35 function _print_python_version() {
 36    # For some reason python --version writes to stderr
 37    if type python > /dev/null; then
 38-       printf "\e[32m[%s]\e[0m\n" "$(python --version 2>&1)"
 39+       printf "${GREEN}[%s]${NORMAL}\n" "$(python --version 2>&1)"
 40    elif type python3 > /dev/null; then
 41-       printf "\e[32m[%s][\[0m\n" "$(python3 --version 2>&1)"
 42+       printf "${GREEN}[%s]${NORMAL}\n" "$(python3 --version 2>&1)"
 43    else
 44        printf "Unable to find python installed on this machine"
 45     fi
 46@@ -32,7 +36,7 @@ function _print_python_version() {
 47 function _maybeworkon() {
 48   if [[ -z "$VIRTUAL_ENV" || "$1" != "$(basename $VIRTUAL_ENV)" ]]; then
 49      if [ -z "$AUTOSWITCH_SILENT" ]; then
 50-        printf "Switching virtualenv: %s  " $1
 51+        printf "Switching virtualenv: ${BOLD}${PURPLE}%s${NORMAL} " $1
 52      fi
 53 
 54      workon "$1"
 55@@ -47,7 +51,7 @@ function _maybeworkon() {
 56 function _maybepipenv() {
 57   if [[ -z "$VIRTUAL_ENV" || "$1" != "$VIRTUAL_ENV" ]]; then
 58      if [ -z "$AUTOSWITCH_SILENT" ]; then
 59-        printf "Switching pipenv: %s  " "$(basename "$1")"
 60+        printf "Switching pipenv: ${BOLD}${PURPLE}%s${NORMAL} " "$(basename "$1")"
 61      fi
 62 
 63      . "$1"/bin/activate
 64diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
 65index 9d11970afe8acb5b2d0329079a074597101821ef..63d5d44dc9fc8a8965867af0dbc6ce870e8a8cd4 100644
 66--- a/tests/test_check_venv.zunit
 67+++ b/tests/test_check_venv.zunit
 68@@ -69,7 +69,7 @@
 69     run check_venv
 70 
 71     assert $status equals 0
 72-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
 73+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 74 }
 75 
 76 @test 'check_venv - No security warning for readable by group permission' {
 77@@ -84,7 +84,7 @@
 78     run check_venv
 79 
 80     assert $status equals 0
 81-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
 82+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 83 }
 84 
 85 @test 'check_venv - No security warning for readable only by owner permission' {
 86@@ -98,7 +98,7 @@
 87     run check_venv
 88 
 89     assert $status equals 0
 90-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
 91+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 92 }
 93 
 94 
 95@@ -124,7 +124,7 @@
 96     run check_venv
 97 
 98     assert $status equals 0
 99-    assert "$output" same_as "Switching virtualenv: foodefault  \e[32m[$PYTHON_VERSION]\e[0m"
100+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoodefault\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
101 }
102 
103 
104@@ -140,7 +140,7 @@
105     run check_venv
106 
107     assert $status equals 0
108-    assert "$output" same_as "Switching pipenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
109+    assert "$output" same_as "Switching pipenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
110 }
111 
112 
113@@ -170,5 +170,5 @@
114     run check_venv
115 
116     assert $status equals 0
117-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
118+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
119 }
120diff --git a/tests/test_maybepipenv.zunit b/tests/test_maybepipenv.zunit
121index 50cb6bd57a6cb32e2cafee10e799a70309715737..c82d5cb1f7ec4633056dfc11fbcda9e7525558e5 100644
122--- a/tests/test_maybepipenv.zunit
123+++ b/tests/test_maybepipenv.zunit
124@@ -27,7 +27,7 @@
125     run _maybepipenv "$(pipenv --venv)"
126 
127     assert $state equals 0
128-    assert "$output" matches "Switching pipenv: $(basename "$PWD")-[^\s]{8}"
129+    assert "$output" contains "Switching pipenv: \e[1m\e[35m$(basename "$PWD")"
130 }
131 
132 @test '_maybepipenv - switches virtualenv if current virtualenv is different' {
133@@ -36,7 +36,7 @@
134     run _maybepipenv "$(pipenv --venv)"
135 
136     assert $state equals 0
137-    assert "$output" matches "Switching pipenv: $(basename "$PWD")-[^\s]{8}"
138+    assert "$output" contains "Switching pipenv: \e[1m\e[35m$(basename "$PWD")"
139 }
140 
141 @test '_maybepipenv - switches virtualenv if current virtualenv is different (silent)' {
142diff --git a/tests/test_maybeworkon.zunit b/tests/test_maybeworkon.zunit
143index 519a58deddea04836ddcc2f6567ca38bedd663ee..3ac6771f290e1ef0462a26cf01e89b090d1bbf68 100644
144--- a/tests/test_maybeworkon.zunit
145+++ b/tests/test_maybeworkon.zunit
146@@ -27,7 +27,7 @@
147     run _maybeworkon foobar
148 
149     assert $state equals 0
150-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
151+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
152 }
153 
154 @test '_maybeworkon - switches virtualenv if current virtualenv is different' {
155@@ -36,7 +36,7 @@
156     run _maybeworkon foobar
157 
158     assert $state equals 0
159-    assert "$output" contains "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
160+    assert "$output" contains "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
161 }
162 
163 @test '_maybeworkon - switches virtualenv if current virtualenv is different (silent)' {
164diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit
165index dfa917ab0ae91cf4648ad429c3471ebc3dc6b975..3ce656bd453cf9a9dd69b042b4518071c364bf83 100644
166--- a/tests/test_plugin.zunit
167+++ b/tests/test_plugin.zunit
168@@ -37,7 +37,7 @@
169     run load ../autoswitch_virtualenv.plugin.zsh
170 
171     assert $status equals 0
172-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
173+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
174 }
175 
176 @test 'plugin - does nothing if switching to directory without .venv' {
177@@ -63,7 +63,7 @@
178     run cd "$TEMP_DIR"
179 
180     assert $status equals 0
181-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
182+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
183 
184     mkdir "$TEMP_DIR/foo"
185 
186@@ -71,5 +71,5 @@
187     run cd "$TEMP_DIR/foo"
188 
189     assert $status equals 0
190-    assert "$output" same_as "Switching virtualenv: foobar  \e[32m[$PYTHON_VERSION]\e[0m"
191+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
192 }