Git Product home page Git Product logo

Comments (11)

sharkdp avatar sharkdp commented on May 27, 2024

you can't. But you can use pastel paint to print colored text with a proper reset sequence.

from pastel.

thorstenkampe avatar thorstenkampe commented on May 27, 2024

pastel paint is fine for generating single lines of colored text. That becomes quite unreadable for longer text like help messages where you would have to split each line into the colored part with pastel paint --no-newline and the rest.

Generating the escape codes via pastel format works fine: I get all the colors I need except the "reset color". Would you consider adding it?

from pastel.

sharkdp avatar sharkdp commented on May 27, 2024

Generating the escape codes via pastel format works fine: I get all the colors I need except the "reset color". Would you consider adding it?

How do you think the command-line interface for this should look like?

from pastel.

thorstenkampe avatar thorstenkampe commented on May 27, 2024

Using "reset", "normal" or "nocolor" as special identifier (similar to "pick") would do the job in my opinion.

Use case:

declare -A color
for color in yellow reset; do
    color[$color]=$(pastel format ansi-24bit-escapecode $color)
done

echo -e "${color[yellow]}[WARN]${color[reset]}: a warning event occurred"

image

from pastel.

thorstenkampe avatar thorstenkampe commented on May 27, 2024

As a side note: ANSI defines a lot of "colors" which are rather text effects like blink, bold or underline. "Reset" in that regard is special in my opinion as you need it constantly to "turn off color" and switch back to "normal".

from pastel.

sharkdp avatar sharkdp commented on May 27, 2024

I'm not 100% convinced. It's inconsistent that pastel format ansi-24bit-escapecode reset works, but pastel format rgb reset does not. pastel color yellow works, but pastel color reset makes no sense.

What is the problem with simply setting

reset=$(printf "\x1b[0m")

or

reset=$(tput sgr0)

from pastel.

thorstenkampe avatar thorstenkampe commented on May 27, 2024

Of course there is no problem simply setting reset to the respective escape sequence. On the other hand, why should I use pastel to set the color yellow when I simply can do yellow='\e[33m'? What's the use case of format ansi-24bit-escapecode if not so you don't have to know all those weird escape codes?

Anyway, please feel free to close this issue.

from pastel.

sharkdp avatar sharkdp commented on May 27, 2024

I mean... pastel format ansi-24bit-escapecode yellow is not the most interesting use case.

The general idea of pastel is that you generate/compute colors in a pastel … | pastel … | … "pipeline" and then in the end convert it to a desired output format (here: an ANSI escape sequence).

I think I'm inclined to accept this feature request. But I would like us to think about different ways to achieve that goal.

By the way, I think pastel format ansi-24bit-escapecode should have a way to handle multiple colors. Right now, if you do something like

pastel gradient -n 10 red yellow | pastel format ansi-24bit-escapecode

it just outputs those 10 escape sequences one after each other without any way to split them. Because we do not print a newline for ansi-*-escapesequence. Which is useful if there is just a single color. But not if you want to work with multiple escape codes somehow (e.g. via xargs).

from pastel.

bend-n avatar bend-n commented on May 27, 2024

ive looked at this issue, but for me, format ansi-24bit-escapecode doesnt seem to work very well: it prints absolutely nothing?

from pastel.

sharkdp avatar sharkdp commented on May 27, 2024

ive looked at this issue, but for me, format ansi-24bit-escapecode doesnt seem to work very well: it prints absolutely nothing?

Yes it does. It prints actual ansi escape sequences (which are not visible in interactive mode). Either print add some text after them. Or pipe into a hexeditor for "debugging" purposes.

from pastel.

sharkdp avatar sharkdp commented on May 27, 2024

I'm closing this due to inactivity. Please feel free to comment in case it should be re-opened.

from pastel.

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.