Are control characters and ANSI escape codes allowed in output?

Recently, I had people go crazy with escape codes on one of my ASCII art challenges.

• This x86 machine code answer was able to save some bytes by throwing a few colour codes at the console. At some point along the way the OP even had a version which left the output blinking.
• Both the above, as well as at least two other answers made use of escape codes to move the cursor vertically across the console, which greatly simplified the indentation logic.
• A similar situation (which didn't happen on this answer) is people using things like carriage return (0x0D) or backspace (0x08) to overwrite output in some challenges.

Of course, all of this relies on a certain console environment which interprets these control characters and escape codes the right way.

So:

• Should such solutions be allowed in general, i.e. are we only concerned with the rendered output?
• Or should the output be the exact byte stream specified in the challenge?
• What if the escape codes only work as intended in very specific environments?
• Is arbitrary colouring of the output allowed? (Provided fore- and background have different colours.)
• This seems to be a potential item on the standard loopholes. However, since it doesn't appear to be "standard", I still consider it clever. – Nathan Merrill Apr 22 '15 at 14:47
• @NathanMerrill Well that's essentially my question: is this fair game, or should it be considered cheating. – Martin Ender Apr 22 '15 at 14:48
• If so, then why isn't it on the list to be up/down voted? – Nathan Merrill Apr 22 '15 at 14:50
• @NathanMerrill Because I thought this might be worth a bit more discussion than is possible in comments, especially since this encompasses several nuances. – Martin Ender Apr 22 '15 at 14:51
• The real issue is what to call "ASCII-art" once it uses non-ASCII escape sequences. – Esolanging Fruit May 31 '17 at 4:47

4 Answers

There seems to be some confusion regarding this, so first and foremost:

ANSI escape sequences are supported by the terminal, not the shell.

Despite of what this answer did, I've shown in my answer that there's no need to involve a shell at all.

This means that all that is needed is a video text terminal that supports these sequences, which includes pretty much any terminal found on a non-Windows computer.

Relying on an escape sequence to move the cursor down is not that different from relying on a linefeed to start a new line; the terminal is not at all guaranteed to do this, but we usually assume that it does.

So:

Should such solutions be allowed in general, i.e. are we only concerned with the rendered output?

For and related challenges, I'd say that's definitely the case. We look at

o
o


not as two o's separated by a linefeed, but as one o below another. How the second o got there ("o\r\no", "o\no", "o\v\ro", "o\e[Bo", etc.) doesn't really matter.

Or should the output be the exact byte stream specified in the challenge?

If the challenge actually specifies a specific byte stream, sure.

If the challenge is not tagged as or at least closely related, definitely.

What if the escape codes only work as intended in very specific environments?

We don't seem to have problems with answers requiring specific conditions.

If we can use undefined behavior in our C answers and require some obscure CPU for our assembly, requiring a certain kind of terminal emulator that renders the output as intended should be no problem.

As always, the terminal emulator has to have existed before the challenge.

Is arbitrary colouring of the output allowed? (Provided fore- and background have different colours.)

As long as the question doesn't state which colors should be used for output, this doesn't really violate a specification.

Arguments could be made, however, against inconsistent coloring (as seen in this answer) and blinking text, since this does alter how the output is perceived.

• I claim that the empty program gives the correct answer, just in the terminal's background color :p – LegionMammal978 Jul 27 '16 at 15:01

Yes, programs must be run by echoing output to a console supporting ANSI escape codes if the answer requires it.

• -1 from me, once you'll explicitly mention that the program only works when output is echo'd on a console supporting ANSI escape codes it makes you realize how insane this requirement is. – orlp Apr 22 '15 at 20:20
• Honestly, I think using directional control characters is a nice approach for ASCII art challenges. I'm less certain about making use of colours, but a unified policy is probably nice and simple. – Martin Ender Apr 25 '15 at 12:58
• How exactly is 'you need to output it to bash' an insane requirement? It's not some obscure program; rather, I dare say it's the default for the majority of users here. – Sanchises May 6 '15 at 13:23
• @sanchises On most machines that have bash installed, Python is also installed. That doesn't mean that requiring output be piped through Python is sane. – orlp May 6 '15 at 13:30

No, output must be an exact bytestream using the specification of the challenge, unless mentioned otherwise.

• +1 from me, this seems to be the sane default. – orlp Apr 22 '15 at 20:22

Yes, if you add the amount of bytes to invoke the shell and run the program to the byte count.

Answers should then be marked with the shell as the language, for example "bash/X86".

• +1 from me, this is acceptable as well. – orlp Apr 22 '15 at 20:24