fatih / color

Color package for Go (golang)
https://pkg.go.dev/github.com/fatih/color
MIT License
7.36k stars 619 forks source link

Adding escape function. #29

Closed henvic closed 8 years ago

henvic commented 8 years ago

This is useful for when you don't trust user input (say, it's something from the Internet).

Btw, escaping Windows colors is missing.

fatih commented 8 years ago

Hi @henvic

Not sure why we should deal with it? This is just a color package. If you want to validate user input you should another package. Checkout https://godoc.org/ for packages that do these kind of things. Feel free to reopen if this is color related. Thanks!

henvic commented 8 years ago

Hey @fatih,

here are my arguments for a escape functionality on a[ny] coloring library:

  1. a decoloring library seems over-kill / micro-framework disaster.
  2. a escape method acts like a filter, not a validation tool, so it is appropriate for such library.

I'm being really picky here, but let me give you this example:

Imagine you get some content (string) from a file on the Internet and output (print) it on the terminal. If you don't escape properly, you can get unexpected results on your screen (say, colored output when it should just show a set of characters together -- and probably colorizing other things later until your program terminates or another colorizing rule is applied on top of it).

That is, escaping is not only important for HTML | JSON | XML, but also for terminal as well. We usually don't do it because we just kind of don't care as no one is actively attacking others' CLI tools with evil rainbows.

Please let me know if you understand my point (I can do a short demo showing you how to reproduce the issue if you don't get it), and if you think it's relevant, missing something, etc.