[ https://issues.apache.org/jira/browse/ARIA-146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15983031#comment-15983031 ]
ASF GitHub Bot commented on ARIA-146: ------------------------------------- Github user mxmrlv commented on a diff in the pull request: https://github.com/apache/incubator-ariatosca/pull/109#discussion_r113221527 --- 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 --- End diff -- format > Support colorful execution logging > ---------------------------------- > > Key: ARIA-146 > URL: https://issues.apache.org/jira/browse/ARIA-146 > Project: AriaTosca > Issue Type: Story > Reporter: Ran Ziv > Assignee: Maxim Orlov > Priority: Minor > > Add support for printing execution logs in color -- This message was sent by Atlassian JIRA (v6.3.15#6346)