11from os .path import join , dirname , realpath , isfile
22from sublime import HIDDEN , PERSISTENT , load_settings , cache_path
33import subprocess , os , glob , re , platform
4+ import GutterColor .webcolors as webcolors
45
56class 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 ())
0 commit comments