How can processes eliminate escape codes when its output is piped?

bool3max

That's a pretty weird title but I'm having trouble articulating this question:

When I run kitty --version in my terminal it prints its version out to stdout, however the text is styled and colored:

enter image description here

In order to achieve this the process had to output ANSI escape codes to stdout, however I don't see them when I hexdump the output:

$ kitty --version | xxd -g 1 -c 10 -u
00000000: 6B 69 74 74 79 20 30 2E 31 39  kitty 0.19
0000000a: 2E 31 20 63 72 65 61 74 65 64  .1 created
00000014: 20 62 79 20 4B 6F 76 69 64 20   by Kovid 
0000001e: 47 6F 79 61 6C 0A              Goyal.

I'd expect to see at least a few escape characters and other ANSI sequences here but I don't. This leads me to believe that kitty is able to "predict" whether its output will appear in a terminal that can process the escape codes.

How is it able to do that? Or is it a feature of the terminal emulator perhaps?

waltinator

Read man isatty, or https://linux.die.net/man/3/isatty

isatty - test whether a file descriptor refers to a terminal

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I kill piped background processes?

From Dev

How can I kill piped background processes?

From Dev

How does a program output to a terminal when stdout is piped?

From Dev

Program output changes when piped

From Dev

How to generate sql output as piped

From Dev

How can I tell Vim to show ANSI escape codes properly?

From Dev

How can we escape the folder name having space in its name when passed from variable ?

From Dev

Why does make ignore escape sequence if the output is piped

From Dev

How can I get python ''.encode('unicode_escape') to return escape codes for ascii?

From Dev

How can htop be used to suspend a process and all its child processes?

From Dev

Stop grep from parsing its own output piped to file

From Dev

How can the convert command's output be passed/piped instead of saved to a file?

From Dev

Can an object tell Twig not to escape output when it is {{ printed }}

From Dev

How to format piped output in powershell to a line

From Dev

Where do my ANSI escape codes go when I pipe to another process? Can I keep them?

From Dev

How can I simplify the codes without affect the output?

From Dev

How can I test if the output of my program contains color (codes)?

From Dev

php: how can a similar codes results different output?

From Dev

How to reverse escape output

From Dev

How to reverse escape output

From Dev

How can I truncate a string to a maximum length without breaking ANSI escape codes

From Dev

How can I tell echo/printf in Bash to swallow escape codes, based on a condition?

From Dev

How can I truncate a string to a maximum length without breaking ANSI escape codes

From Dev

How can I read redirected/piped data?

From Dev

How can a conditional statement be used in a piped command?

From Dev

Why don't some "for" commands work when the output is piped?

From Dev

ag output appears different in the terminal vs when piped to a file

From Dev

Why does bash output data instead of executing, when a script is piped?

From Dev

Why won't journalctl show logs when the program output is piped?

Related Related

  1. 1

    How can I kill piped background processes?

  2. 2

    How can I kill piped background processes?

  3. 3

    How does a program output to a terminal when stdout is piped?

  4. 4

    Program output changes when piped

  5. 5

    How to generate sql output as piped

  6. 6

    How can I tell Vim to show ANSI escape codes properly?

  7. 7

    How can we escape the folder name having space in its name when passed from variable ?

  8. 8

    Why does make ignore escape sequence if the output is piped

  9. 9

    How can I get python ''.encode('unicode_escape') to return escape codes for ascii?

  10. 10

    How can htop be used to suspend a process and all its child processes?

  11. 11

    Stop grep from parsing its own output piped to file

  12. 12

    How can the convert command's output be passed/piped instead of saved to a file?

  13. 13

    Can an object tell Twig not to escape output when it is {{ printed }}

  14. 14

    How to format piped output in powershell to a line

  15. 15

    Where do my ANSI escape codes go when I pipe to another process? Can I keep them?

  16. 16

    How can I simplify the codes without affect the output?

  17. 17

    How can I test if the output of my program contains color (codes)?

  18. 18

    php: how can a similar codes results different output?

  19. 19

    How to reverse escape output

  20. 20

    How to reverse escape output

  21. 21

    How can I truncate a string to a maximum length without breaking ANSI escape codes

  22. 22

    How can I tell echo/printf in Bash to swallow escape codes, based on a condition?

  23. 23

    How can I truncate a string to a maximum length without breaking ANSI escape codes

  24. 24

    How can I read redirected/piped data?

  25. 25

    How can a conditional statement be used in a piped command?

  26. 26

    Why don't some "for" commands work when the output is piped?

  27. 27

    ag output appears different in the terminal vs when piped to a file

  28. 28

    Why does bash output data instead of executing, when a script is piped?

  29. 29

    Why won't journalctl show logs when the program output is piped?

HotTag

Archive