Change iTerm2 font color depending on the word - terminal

Example, if "GET" is being printed on the terminal, i want that GET get colores in color green. if the sign # is printed, i want that only this character get colored.

Preferences>Profiles>Advanced>Triggers/Edit!

Related

Actual colors in MacOS Terminal don't match their values in Preferences

I am trying to build a Terminal theme in MacOS. The colors that are actually being displayed are slightly different from the hex colors I am setting. For example:
I am setting the background color to #292D3E here. But when I sample the color from the actual background, it is #24293B.
Why is this happening? It seems to do it with most of the colors. I suspect it has to do with Terminal only being able to use a limited palette? But I'm wondering why it would still allow me to enter it, and why it would still show the pasted value and not change it to the allowed value after I saved it if that were the case.

Using color withing log4j2 messages

I have the following log statement which I would expect to result in a colored line in the logs, but it does not. The logs are setup to write to standard out, and there are other things that are writing colored output that work fine, so I know it is not a problem with the terminal.
LoggerFactory.getLogger("foo").info("no color \\033[1;35m COLOR \\033[0m no color")
and this is what shows up in the logs.
15:59:25 15:59:25 20:59:25,268: INFO [MyClazz] no color \033[1;35m COLOR \033[0m no color
Is it possible to put color within a log message? and if so how?
I would advise against storing ANSI color escape sequences/codes inside your logs. At least you should test if the output device is TTY, and write the "colored" output only if it is.
That being said, your problem is in escaping the backslash, \. Your output should contain the actual \033 character (in octal), i.e. \x1b (in hex),
or 27 (in decimal). Try it like this:
LoggerFactory.getLogger("foo").info("no color \033[1;35m COLOR \033[0m no color")

Color codes and string interpolation

I am trying to colorize text. Say I want blue text. This is the way I get it:
"\e[34mThis is blue text.\e[0m"
I am using define_method to create multiple methods (one for each color). I keep the color code for each color in an array. I iterate over both the color array and the color code, and do this:
"\e#{code}m[#{self}\e[0m"
When I run it, I get "m[test" instead of the colorized text.
Any thoughts? If, instead of #{code}, I put the actual code, it works, but that'd be like 20 ifs, one for each color, and it won't be DRY.
You are likely a victim of copy-paste :)
# ⇓ incorrect
puts "\e#{code}m[#{self}\e[0m"
# ⇓ correct
puts "\e[#{code}m#{self}\e[0m"
The opening square bracket should follow \e, not m.

colored text with highlighted data via colored gem

I am trying to achieve multi colored text with the colored gem in ruby.
Basically I want to set a base color for the text, but highlight specific details in another color while still keeping all the other text in the base color.
For example if I do something like:
puts "Found #{book_title.yellow} and it has #{chapters.to_s.yellow} chapters".green
I would of expected that the entire phrase would be green except for the book title and number of chapters which should be yellow.
Instead the results are that "Found" is green, book title is yellow, "and it has" is white (no color), chapters is yellow, and "chapters" is white (no color).
It simply appears that appending .green to the surrounding string doesn't re-add the color codes after a color change when using #{} to insert data.
I want to build this functionality into a info function like so:
def info(message)
time_stamp = "[#{Time.new.strftime("%H:%M:%S")}]"
puts "#{time_stamp} Info: #{message}".green
end
So that when I call it like so:
info "Found #{book_title.yellow} and it has #{chapters.to_s.yellow} chapters"
It will print the entire statement in green with highlighted text in yellow as described above.
Is this possible without breaking the string into substrings and concatting them, or specifying a hard coded list of arguments to the info function (the number of highlighted texts is dynamic). Is there a VA_LIST type like in C's printf I could use?
I wouldn't mind calling the function as:
info "Found %s and it has %d chapters", book_title.yellow, chapters.to_s.yellow
or something similar. But I would still need to figure out a way to set the color codes for each segment of text and concat them together.
Hopefully this makes sense.

terminal top command different text colors

on OSX, when I run top sometimes I see some different colors, namely black text....
What does it mean?
What bash setting do I need to change to make these a different color? black is too hard to read with my setup.
It turns out that it was a simple text color in the terminal preferences, I think the title of the setting was 'bold text'

Resources