Skip to content

Commit

Permalink
Merge pull request #33 from TheSecEng/st4/no_auto_generate
Browse files Browse the repository at this point in the history
fix: remove color generator, include butchered sublime_lib
  • Loading branch information
TerminalFi authored Apr 16, 2021
2 parents 6f6ea1f + c11cb47 commit b4c3ee8
Show file tree
Hide file tree
Showing 20 changed files with 4,031 additions and 175 deletions.
8 changes: 2 additions & 6 deletions Commands.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[
{
"caption": "Colored Comments: Generate Color Scheme",
"command": "colored_comments_theme_generator"
},
{
"caption": "Colored Comments: Remove Generated Color Scheme",
"command": "colored_comments_theme_revert"
"caption": "Colored Comments: Override Current Color Scheme",
"command": "colored_comments_edit_scheme"
},
{
"caption": "Colored Comments: Clear Colorization",
Expand Down
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,26 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

MIT License

Copyright (c) 2010-2014 Guillermo López-Anglada (Vintageous)
Copyright (c) 2012-2019 FichteFoll <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
115 changes: 111 additions & 4 deletions colored_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,123 @@
import sublime_plugin

from .plugin import logger as log
from .plugin.color_manager import color_manager, load_color_manager
from .lib.sublime_lib import ResourcePath
from .plugin.settings import load_settings, settings, unload_settings

NAME = "Colored Comments"
VERSION = "3.0.3"

comment_selector = "comment - punctuation.definition.comment"

# Thanks PackageDev
SCHEME_TEMPLATE = """\
{
// http://www.sublimetext.com/docs/3/color_schemes.html
"variables": {
"important_comment": "var(region.redish)",
"deprecated_comment": "var(region.purplish)",
"question_comment": "var(region.cyanish)",
"todo_comment": "var(region.greenish)",
"fixme_comment": "var(region.bluish)",
"undefined_comment": "var(region.accent)",
},
"globals": {
// "foreground": "var(green)",
},
"rules": [
{
"name": "IMPORTANT COMMENTS",
"scope": "comments.important",
"foreground": "var(important_comment)",
"background": "rgba(1,22,38, 0.1)",
},
{
"name": "DEPRECATED COMMENTS",
"scope": "comments.deprecated",
"foreground": "var(deprecated_comment)",
"background": "rgba(1,22,38, 0.1)",
},
{
"name": "QUESTION COMMENTS",
"scope": "comments.question",
"foreground": "var(question_comment)",
"background": "rgba(1,22,38, 0.1)",
},
{
"name": "TODO COMMENTS",
"scope": "comments.todo",
"foreground": "var(todo_comment)",
"background": "rgba(1,22,38, 0.1)",
},
{
"name": "FIXME COMMENTS",
"scope": "comments.fixme",
"foreground": "var(fixme_comment)",
"background": "rgba(1,22,38, 0.1)",
},
{
"name": "UNDEFINED COMMENTS",
"scope": "comments.undefined",
"foreground": "var(undefined_comment)",
"background": "rgba(1,22,38, 0.1)",
},
],
}""".replace(" ", "\t")

KIND_SCHEME = (sublime.KIND_ID_VARIABLE, "s", "Scheme")
DEFAULT_CS = 'Packages/Color Scheme - Default/Mariana.sublime-color-scheme'


class ColoredCommentsEditSchemeCommand(sublime_plugin.WindowCommand):

"""Like syntax-specific settings but for the currently used color scheme."""

def run(self):
view = self.window.active_view()
if not view:
return

scheme_path = self.get_scheme_path(view, 'color_scheme')
if scheme_path != 'auto':
self.open_scheme(scheme_path)
else:
paths = [
(setting, self.get_scheme_path(view, setting))
for setting in ('dark_color_scheme', 'light_color_scheme')
]
choices = [
sublime.QuickPanelItem(
setting, details=str(path), kind=KIND_SCHEME)
for setting, path in paths
]

def on_done(i):
if i >= 0:
self.open_scheme(paths[i][1])

self.window.show_quick_panel(choices, on_done)

@staticmethod
def get_scheme_path(view, setting_name):
# Be lazy here and don't consider invalid values
scheme_setting = view.settings().get(setting_name, DEFAULT_CS)
if scheme_setting == 'auto':
return 'auto'
elif "/" not in scheme_setting:
return ResourcePath.glob_resources(scheme_setting)[0]
else:
return ResourcePath(scheme_setting)

def open_scheme(self, scheme_path):
self.window.run_command(
'edit_settings',
{
'base_file': '/'.join(("${packages}",) + scheme_path.parts[1:]),
'user_file': "${packages}/User/" + scheme_path.stem + '.sublime-color-scheme',
'default': SCHEME_TEMPLATE,
},
)


class ColoredCommentsEventListener(sublime_plugin.EventListener):
def on_init(self, views):
Expand Down Expand Up @@ -63,7 +172,7 @@ def ApplyDecorations(self) -> None:
self.view.add_regions(
key=key.lower(),
regions=to_decorate.get(key),
scope=settings.get_scope_for_region(tag),
scope=settings.get_scope_for_region(key, tag),
icon=settings.get_icon(),
flags=settings.get_flags(tag),
)
Expand All @@ -87,9 +196,7 @@ def run(self, edit):


def plugin_loaded() -> None:
global color_scheme_manager
load_settings()
load_color_manager()
log.set_debug_logging(settings.debug)


Expand Down
45 changes: 8 additions & 37 deletions colored_comments.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Character to continue matching on
"continued_matching_pattern": "-",
// Shows comment icon next to comments
"comment_icon_enabled": true,
"comment_icon_enabled": false,
// Which comment icon to use
// Valid options: comment, dots
"comment_icon": "dots",
Expand All @@ -23,6 +23,8 @@
// and used in the OrderedDict
// These should be unique
"Important": {
// The name of the scope being use in your color scheme file
"scope": "comments.important",
// The actual identifier used to highlight the comments
"identifier": "!",
// Enables sublime.DRAW_SOLID_UNDERLINE
Expand All @@ -43,59 +45,28 @@
"is_regex": false,
// Enables ignorecase for the ideentifier
"ignorecase": true,
// Colors used for Scope generation
"color": {
// Scope name this becomes colored.comments.color.important
"name": "important",
// Color you want the text to be
"foreground": "#FF2D00",
// Color you want the background to be
// this HAS to be slightly different than
// your themes background....Because Sublime
"background": "rgba(1,22,38, 0.1)"
},
},
"Deprecated": {
"scope": "comments.deprecated",
"identifier": "*",
"color": {
"name": "deprecated",
"foreground": "#98C379",
"background": "rgba(1,22,38, 0.1)"
},
},
"Question": {
"scope": "comments.question",
"identifier": "?",
"color": {
"name": "question",
"foreground": "#3498DB",
"background": "rgba(1,22,38, 0.1)"
},
},
"TODO": {
"color": {
"background": "rgba(1,22,38, 0.1)",
"foreground": "#FF8C00",
"name": "todo"
},
"scope": "comments.todo",
"identifier": "TODO[:]?|todo[:]?",
"is_regex": true,
"ignorecase": true,
},
"FIXME": {
"color": {
"background": "rgba(1,22,38, 0.1)",
"foreground": "#9933FF",
"name": "fixme"
},
"scope": "comments.fixme",
"identifier": "FIXME[:]?|fixme[:]?",
"is_regex": true
},
"UNDEFINED": {
"color": {
"background": "rgba(1,22,38, 0.1)",
"foreground": "#474747",
"name": "undefined"
},
"scope": "comments.undefined",
"identifier": "//[:]?",
"is_regex": true
}
Expand Down
21 changes: 21 additions & 0 deletions lib/sublime_lib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Thomas Smith

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions lib/sublime_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .resource_path import ResourcePath # noqa: F401
Empty file.
4 changes: 4 additions & 0 deletions lib/sublime_lib/_compat/pathlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
from pathlib import * # noqa: F401, F403
except ImportError:
from ..vendor.pathlib.pathlib import * # type: ignore # noqa: F401, F403
4 changes: 4 additions & 0 deletions lib/sublime_lib/_compat/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
try:
from typing import * # noqa: F401, F403
except ImportError:
from .typing_stubs import * # type: ignore # noqa: F401, F403
Empty file.
51 changes: 51 additions & 0 deletions lib/sublime_lib/_util/glob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import re
from functools import lru_cache

from .._compat.typing import Callable

__all__ = ['get_glob_matcher']


GLOB_RE = re.compile(r"""(?x)(
\*
| \?
| \[ .*? \]
)""")


@lru_cache()
def get_glob_matcher(pattern: str) -> Callable[[str], bool]:
if pattern.startswith('/'):
pattern = pattern[1:]
else:
pattern = '**/' + pattern

expr_string = r'\A'
for component in pattern.split('/'):
if component == '':
pass
elif component == '*':
# Component must not be empty.
expr_string += r'(?:[^/])+' + '/'
elif component == '**':
expr_string += r'(?:.*(?:\Z|/))?'
elif '**' in component:
raise ValueError("Invalid pattern: '**' can only be an entire path component")
else:
for part in GLOB_RE.split(component):
if part == '':
pass
elif part == '*':
expr_string += r'(?:[^/])*'
elif part == '?':
expr_string += r'(?:[^/])'
elif part[0] == '[':
expr_string += part
else:
expr_string += re.escape(part)
expr_string += '/'

expr_string = expr_string.rstrip('/') + r'\Z'
expr = re.compile(expr_string)

return lambda path: (expr.search(path) is not None)
Loading

0 comments on commit b4c3ee8

Please sign in to comment.