20
\$\begingroup\$

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.)
\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$ Apr 22, 2015 at 14:47
  • \$\begingroup\$ @NathanMerrill Well that's essentially my question: is this fair game, or should it be considered cheating. \$\endgroup\$ Apr 22, 2015 at 14:48
  • \$\begingroup\$ If so, then why isn't it on the list to be up/down voted? \$\endgroup\$ Apr 22, 2015 at 14:50
  • 3
    \$\begingroup\$ @NathanMerrill Because I thought this might be worth a bit more discussion than is possible in comments, especially since this encompasses several nuances. \$\endgroup\$ Apr 22, 2015 at 14:51
  • \$\begingroup\$ The real issue is what to call "ASCII-art" once it uses non-ASCII escape sequences. \$\endgroup\$ May 31, 2017 at 4:47

4 Answers 4

17
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I claim that the empty program gives the correct answer, just in the terminal's background color :p \$\endgroup\$ Jul 27, 2016 at 15:01
5
\$\begingroup\$

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

\$\endgroup\$
4
  • 3
    \$\begingroup\$ -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. \$\endgroup\$
    – orlp
    Apr 22, 2015 at 20:20
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ Apr 25, 2015 at 12:58
  • 3
    \$\begingroup\$ 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. \$\endgroup\$
    – Sanchises
    May 6, 2015 at 13:23
  • \$\begingroup\$ @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. \$\endgroup\$
    – orlp
    May 6, 2015 at 13:30
0
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ +1 from me, this seems to be the sane default. \$\endgroup\$
    – orlp
    Apr 22, 2015 at 20:22
-2
\$\begingroup\$

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".

\$\endgroup\$
1
  • \$\begingroup\$ +1 from me, this is acceptable as well. \$\endgroup\$
    – orlp
    Apr 22, 2015 at 20:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .