Is it possible to pipe output (e.g. dmesg) to a command like less (or equivalent) and keep the text highlighting used by the original command?
example: on the left dmesg | less on the right dmesg

Is it possible to pipe output (e.g. dmesg) to a command like less (or equivalent) and keep the text highlighting used by the original command?
example: on the left dmesg | less on the right dmesg

Use the --human parameter to view colored dmesg output in a less-like environment.
dmesg --human --color=always
Or use the short version:
dmesg -H -L=always
Alternatively, use the following command to achieve similar results.
dmesg --color=always | less -R
Many other utilities that produce colored output (ls, grep, etc.) have a similar --color=always option.
A generic command to preserve coloration independent of the program providing the output is the unbuffer command (which is part of the expect package).
Usage:
unbuffer dmesg | less -R
Yes, it works nice.
for tree:
tree -C | less -r
for ls:
ls -lA --color=always | less -r
for pytest:
py.test --color=yes | less -r