Skip to content

Commit 4084b5c

Browse files
committed
Merge pull request #87 from ggordan/web-colors
Added support for web color names. Closes #16
2 parents 1e03aed + fc9151d commit 4084b5c

File tree

5 files changed

+762
-2
lines changed

5 files changed

+762
-2
lines changed

gutter_color.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def fix_scheme_in_view(view, regenerate=False, ignore_flags=False):
121121
return
122122
print("Could not find or access the settings file where current color_scheme ("+current_scheme+") is set.")
123123

124-
125124
def fix_scheme_in_settings(settings_file,current_scheme, new_scheme, regenerate=False):
126125
"""Change the color scheme in the given Settings to a background-corrected one"""
127126
from os.path import join, normpath, isfile

line.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os.path import join, dirname, realpath, isfile
22
from sublime import HIDDEN, PERSISTENT, load_settings, cache_path
33
import subprocess, os, glob, re, platform
4+
import GutterColor.webcolors as webcolors
45

56
class Line:
67

@@ -20,8 +21,12 @@ class Line:
2021
RGBA_REGEXP = 'rgba\(' + FOUR_DIGITS + '\)'
2122
HSL_REGEXP = 'hsl\(' + THREE_DIGITS + '\)'
2223
HSLA_REGEXP = 'hsla\(' + FOUR_DIGITS + '\)'
24+
WEB_COLORS_REGEX = ''
25+
WEB_COLORS = []
2326

2427
def __init__(self, view, region, file_id):
28+
self.generate_webcolors()
29+
2530
self.view = view
2631
self.region = region
2732
self.file_id = file_id
@@ -34,6 +39,8 @@ def has_color(self):
3439

3540
def color(self):
3641
"""Returns the color in the line, if any."""
42+
if self.web_color():
43+
return self.web_color()
3744
if self.hex_color():
3845
return self.hex_color()
3946
if self.rgb_color():
@@ -47,6 +54,17 @@ def color(self):
4754
if not self.settings.get("custom_colors") == None:
4855
return self.custom_color()
4956

57+
def generate_webcolors(self):
58+
"""Generates a list of web color names."""
59+
self.WEB_COLORS = dict((name, color) for (name, color) in webcolors.css3_names_to_hex.items())
60+
self.WEB_COLORS_REGEX = "("+ "|".join(self.WEB_COLORS.keys()) +")"
61+
62+
def web_color(self):
63+
"""Returns the color in the line, if any CSS color name is found."""
64+
matches = re.search(self.WEB_COLORS_REGEX, self.text)
65+
if matches:
66+
return matches.group(0)
67+
5068
def hex_color(self):
5169
"""Returns the color in the line, if any hex is found."""
5270
matches = re.search(Line.HEX_REGEXP, self.text)
@@ -94,7 +112,6 @@ def custom_color(self):
94112
if matches:
95113
return prefix+matches.group(group_id)+suffix
96114

97-
98115
def icon_path(self):
99116
"""Returns the absolute path to the icons"""
100117
return join(cache_path(), 'GutterColor', '%s.png' % self.color())

messages/v0.3.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This version introduces highlighting of web color names!

test.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
/* From https://developer.mozilla.org/en-US/docs/Web/CSS/color_value */
22

3+
.COLORS {
4+
background-color: black;
5+
background-color: gray;
6+
background-color: white;
7+
background-color: maroon;
8+
background-color: red;
9+
background-color: purple;
10+
background-color: fuchsia;
11+
background-color: green;
12+
background-color: lime;
13+
background-color: olive;
14+
background-color: yellow;
15+
background-color: navy;
16+
background-color: blue;
17+
background-color: teal;
18+
background-color: aqua;
19+
}
20+
321
.HEX3 {
422
background-color: #000; /* black */
523
background-color: #888; /* gray */

0 commit comments

Comments
 (0)