[PYTHON] Change the color of Fabric errors and warnings

Fabric colors errors and warnings with ʻenv.colorize_errors = True`, but if the terminal color is red, it will be fogged, so I want to color the background. (By the way, I'm on a black background so I'm not in trouble)

So, overwrite fabric.colors. (It may not be the way you expected in a future update, so it may not be a good idea)

colors.py


# -*- coding: utf-8 -*-
import fabric.colors

def _wrap_with(color, background):

    def inner(text, bold=False):
        c = color
        if background:
            c = "%s;%s" % (background, c)
        if bold:
            c = "1;%s" % c

        return "\033[%sm%s\033[0;m" % (c, text)

    return inner

red = _wrap_with('31', '40')
green = _wrap_with('32', '40')
yellow = _wrap_with('33', '40')
blue = _wrap_with('34', '40')
magenta = _wrap_with('35', '40')
cyan = _wrap_with('36', '40')
white = _wrap_with('37', '40')

fabric.colors.red = red
fabric.colors.green = green
fabric.colors.yellow = yellow
fabric.colors.blue = blue
fabric.colors.magenta = magenta
fabric.colors.cyan = cyan
fabric.colors.white = white

In the escape sequence, \ 033 [1; 40; 31 is bold, black background, red letters, and fabric.utils.abort calls fabric.colors.red, so fabric.colors.red Should be a function that constructs \ 033 [1; 40; 31% s \ 033 [0; m".

Read this

fabfile.py


# -*- coding: utf-8 -*-

from fabric.api import *

from colors import *

env.colorize_errors = True

@task
def abort_task():
    abort("Task failed!>_<")

Now you can read the characters even on a red background.

Screen Shot 2017-01-19 at 01.50.25.png

You can create your own color output function using this method.

Recommended Posts

Change the color of Fabric errors and warnings
Change the saturation and brightness of color specifications like # ff000 in python 2.5
Just fix the sudo apt-get update errors and warnings
[Touch Designer] Change the appearance color of Button COMP
Change the theme of Jupyter
Change the style of matplotlib
[Python] Change the text color and background color of a specific keyword in print output
The story of Python and the story of NaN
Change the background of Ubuntu (GNOME)
Change the Python version of Homebrew
Change the suffix of django-filter / DateFromToRangeFilter
How to change the color of just the button pressed in Tkinter
I summarized how to change the boot parameters of GRUB and GRUB2
This and that of the inclusion notation.
Graph of the history of the number of layers of deep learning and the change in accuracy
Script to change the description of fasta
Let's change the color scheme of iTerm2 automatically depending on the time zone
The story of trying deep3d and losing
Open an Excel file in Python and color the map of Japan
Change the order of PostgreSQL on Heroku
Change the destination batfish server of pybatfish
Extract the color of the object in the image with Mask R-CNN and K-Means clustering
About the behavior of copy, deepcopy and numpy.copy
Summary of the differences between PHP and Python
Full understanding of the concepts of Bellman-Ford and Dijkstra
Organize the meaning of methods, classes and objects
Specifying the range of ruby and python arrays
Change the decimal point of logging from, to.
Compare the speed of Python append and map
General description of the CPUFreq core and CPUFreq notifiers
Change the resolution of Ubuntu running on VirtualBox
Organize the super-basic usage of Autotools and pkg-config
I read and implemented the Variants of UKR
ROS Lecture 119 Correct the color of the camera image
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
The nice and regrettable parts of Cloud Datalab
[Machine learning] "Abnormality detection and change detection" Let's draw the figure of Chapter 1 in Python.
Consideration of the difference between ROC curve and PR curve
Get the title of yahoo news and analyze sentiment
The story of Python without increment and decrement operators.
The background color of the QWidget subclass cannot be set
Python --Explanation and usage summary of the top 24 packages
[FSL] Measurement of segment and volume of the basal ganglia
Think about the next generation of Rack and WSGI
Referencing and changing the upper bound of Python recursion
I checked out the versions of Blender and Python
I checked the default OS and shell of docker-machine
[Django] Change the Default IP address of the runserver command
Visualization of the connection between malware and the callback server
[Python] Summary of how to specify the color of the figure
[Django 2.2] Sort and get the value of the relation destination
Personal notes about the integration of vscode and anaconda
Extract the maximum value with pandas and change that value
Check the type and version of your Linux distribution
Animate the basics of dynamic programming and the knapsack problem
[Python] Let's change the URL of the Django administrator site
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api