ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxmrlv <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #109: ARIA-146-Support-colorful-execution-l...
Date Tue, 25 Apr 2017 16:24:05 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113236779
  
    --- Diff: aria/cli/color.py ---
    @@ -0,0 +1,73 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +from StringIO import StringIO
    +
    +import colorama
    +
    +colorama.init()
    +
    +
    +def _get_colors(color_type):
    +    for name in dir(color_type):
    +        if not name.startswith('_'):
    +            yield (name.lower(), getattr(color_type, name))
    +
    +
    +class Color(object):
    +    Fore = colorama.Fore
    +    Back = colorama.Back
    +    Style = colorama.Style
    +
    +    _colors = {
    +        'fore': dict(_get_colors(Fore)),
    +        'back': dict(_get_colors(Back)),
    +        'style': dict(_get_colors(Style))
    +    }
    +
    +    class Schema(object):
    +        def __init__(self, **kwargs):
    +            """
    +            It is possible to provide fore, back and style arguments. each could be either
    +            the color is lower case letter, or the actual color from colorama.
    +
    +            """
    +            assert all(arg in Color._colors for arg in kwargs)
    +            self._kwargs = kwargs
    +            self._str = StringIO()
    +            for type_, colors in Color._colors.items():
    +                value = kwargs.pop(type_, None)
    +                # the former case is if the value is a string, the latter is in case
of an object.
    +                self._str.write(colors.get(value) or value)
    +
    +        def __str__(self):
    +            return self._str.getvalue()
    +
    +        def __add__(self, other):
    +            return str(self) + str(other)
    +
    +        def __radd__(self, other):
    +            return str(other) + str(self)
    +
    +    @classmethod
    +    def stylize(cls, str_to_stylize, schema):
    +        return schema + str(str_to_stylize) + cls.Style.RESET_ALL
    +
    +    @classmethod
    +    def markup(cls, str_to_stylize, matches, schema):
    +        modified_str = str_to_stylize
    +        for group_index in xrange(len(matches.regs)):
    --- End diff --
    
    move regex stuff here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message