Coder Social home page Coder Social logo

Customize colors about ydiff HOT 3 CLOSED

ymattw avatar ymattw commented on August 22, 2024 1
Customize colors

from ydiff.

Comments (3)

plgruener avatar plgruener commented on August 22, 2024 1

I may be able to help out here:

@ymattw Can you point out in the code where the colors are set?

The color definition is not exactly hard to find if you try just a little bit:

ydiff/ydiff.py

Lines 43 to 60 in ce8f7a1

COLORS = {
'reset' : '\x1b[0m',
'underline' : '\x1b[4m',
'reverse' : '\x1b[7m',
'red' : '\x1b[31m',
'green' : '\x1b[32m',
'yellow' : '\x1b[33m',
'blue' : '\x1b[34m',
'magenta' : '\x1b[35m',
'cyan' : '\x1b[36m',
'lightred' : '\x1b[1;31m',
'lightgreen' : '\x1b[1;32m',
'lightyellow' : '\x1b[1;33m',
'lightblue' : '\x1b[1;34m',
'lightmagenta' : '\x1b[1;35m',
'lightcyan' : '\x1b[1;36m',
}

These are ANSI escape codes, and are sort of the least common denominator for encoding colors across terminal applications.

ydiff uses the 3/4bit ones, which essentially mean there are 16 basic named colors (in order: black, red, green, yellow, blue, magenta, cyan, white; and their respective bright- variants), which exact RGB-value is set by your terminal. So if you just wanted a lighter/darker shade of red, adjust your terminal accordingly. If you wanted magenta/cyan instead of red/green, you would just change the ANSI escape code in that color-definition above.

There are two other modes: 8bit (256 colors) and 24bit (full RGB, 32M colors). Many terminal today do have "truecolor" support, but some don't and never will (basic xterm has not, for example).
And doing truecolor-support the right way is hard. For your "simple" suggestion, you'd have to have to do:

  1. a custom config file for ydiff
  2. a custom DSL for defining colors, either as 4bit, 8bit or 24bit ones (RGB,RGB-A,HSV,…?)
  3. parsing of this color-DSL and generating the appropriate ANSI escape codes. Sure there are probably libraries for that, but that's another dependency.
  4. check if the terminal you're outputting to does support 256/24bit colors or not, and add fallbacks. This is the hardest step, because there currently is just no reliable way to do that. You can find a great writeup here: https://gist.github.com/XVilka/8346728

All in all probably too much hassle for a tool that just displays two colors.

from ydiff.

ymattw avatar ymattw commented on August 22, 2024

Unfortunately I do not have plan to support that. I intentionally want to keep the tool simple enough. But I can imagine there are different flavors of color schema, so I am open to accept contribution :).

from ydiff.

ElectricRCAircraftGuy avatar ElectricRCAircraftGuy commented on August 22, 2024

@ymattw Can you point out in the code where the colors are set?

This could easily be done by having a config file that ydiff reads from, but for any configuration settings not set, or if the config file is missing entirely, it will just use some defaults. That's what I would do.

from ydiff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.