Skip to content

Commit 9dde354

Browse files
Merge pull request #96 from MasterOdin/color_fix
Use default terminal colors instead of white by default
2 parents 9e3e9f6 + 162bbcb commit 9dde354

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ If you are experiencing issues with *tldr*, consider deleting the cache files be
5757
### Colors
5858

5959
Values of the `TLDR_COLOR_x` variables may consist of three parts:
60-
* Font color, *required*: `blue, green, yellow, cyan, magenta, white, grey, red`
60+
* Font color: `blue, green, yellow, cyan, magenta, white, grey, red`
6161
* Background color: `on_blue, on_cyan, on_magenta, on_white, on_grey, on_yellow, on_red, on_green`
6262
* Additional effects, which depends on platform: `reverse, blink, dark, concealed, underline, bold`
6363

64-
Values of background color and additional effect may be omitted:
64+
You may specify as many additional effects as you want, while only one of font and background color.
65+
66+
Any of the values of above may be omitted. For example, you can do similar things as the following:
67+
* `TLDR_COLOR_NAME=""` use default system font color with default background color without any effects
6568
* `TLDR_COLOR_DESCRIPTION="white"` for white text on default system background color without any effects
6669
* `TLDR_COLOR_NAME="cyan dark"` for dark cyan text on default system background color
70+
* `TLDR_COLOR_NAME="on_red"` for default system font color on red background color
6771
* `TLDR_COLOR_PARAMETER="red on_yellow underline"` for underlined red text on yellow background
72+
* `TLDR_COLOR_NAME="bold underline"` for default system font and background colors with underline and bolded effects
6873

6974
## Remote source
7075

tests/data/gem_rendered

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# gem 
1+
# gem 
22
 
3-
 Interact with the package manager for the Ruby programming language. 
3+
Interact with the package manager for the Ruby programming language. 
44
 
55
- Install latest version of a gem 
66
 
7-
 gem install gemname 
7+
 gem install gemname 
88
 
99
- Install specific version of a gem 
1010
 
11-
 gem install gemname -v 1.0.0 
11+
 gem install gemname -v 1.0.0 
1212
 
1313
- Update a gem 
1414
 
15-
 gem update gemname 
15+
 gem update gemname 
1616
 
1717
- List all gems 
1818
 
1919
 gem list 
2020
 
2121
- Uninstall a gem 
2222
 
23-
 gem uninstall gemname 
23+
 gem uninstall gemname 
2424
 
2525
 
2626
 

tldr.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,27 @@ def get_page(command, remote=None, platform=None):
201201

202202
DEFAULT_COLORS = {
203203
'blank': 'white',
204-
'name': 'white bold',
205-
'description': 'white',
204+
'name': 'bold',
205+
'description': '',
206206
'example': 'green',
207207
'command': 'red',
208-
'parameter': 'white',
208+
'parameter': '',
209209
}
210210

211211
# See more details in the README:
212212
# https://github.com/tldr-pages/tldr-python-client#colors
213213
ACCEPTED_COLORS = [
214214
'blue', 'green', 'yellow', 'cyan', 'magenta', 'white',
215-
'grey', 'red', 'on_blue', 'on_cyan', 'on_magenta', 'on_white',
216-
'on_grey', 'on_yellow', 'on_red', 'on_green', 'reverse',
217-
'blink', 'dark', 'concealed', 'underline', 'bold'
215+
'grey', 'red'
216+
]
217+
218+
ACCEPTED_COLOR_BACKGROUNDS = [
219+
'on_blue', 'on_cyan', 'on_magenta', 'on_white',
220+
'on_grey', 'on_yellow', 'on_red', 'on_green'
221+
]
222+
223+
ACCEPTED_COLOR_ATTRS = [
224+
'reverse', 'blink', 'dark', 'concealed', 'underline', 'bold'
218225
]
219226

220227
LEADING_SPACES_NUM = 2
@@ -225,17 +232,18 @@ def get_page(command, remote=None, platform=None):
225232

226233
def colors_of(key):
227234
env_key = 'TLDR_COLOR_%s' % key.upper()
228-
user_value = os.environ.get(env_key, '').strip()
229-
if user_value and user_value not in ACCEPTED_COLORS:
230-
# you can put a warning statement here, but it will print a lot
231-
user_value = None
232-
values = user_value or DEFAULT_COLORS[key]
233-
values = values.split()
234-
return (
235-
values[0] if len(values) > 0 else None,
236-
values[1] if len(values) > 1 and values[1].startswith('on_') else None,
237-
values[2:] if len(values) > 1 and values[1].startswith('on_') else values[1:],
238-
)
235+
values = os.environ.get(env_key, DEFAULT_COLORS[key]).strip().split()
236+
color = None
237+
on_color = None
238+
attrs = []
239+
for value in values:
240+
if value in ACCEPTED_COLORS:
241+
color = value
242+
elif value in ACCEPTED_COLOR_BACKGROUNDS:
243+
on_color = value
244+
elif value in ACCEPTED_COLOR_ATTRS:
245+
attrs.append(value)
246+
return (color, on_color, attrs)
239247

240248

241249
def output(page):

0 commit comments

Comments
 (0)