1

When coding in general I make liberal use of escape sequences for colour and cursor movement.

Some languages need initialisation steps to make this happen, like in python os.system('') needs to be called before printing escape sequences.

In Java, printing sequences appears limited. In the IDE, only colour sequences (ending with m) work correctly. Other sequences do not work. Colour does not work in cmd-hosted console.

Example code:

public class Main {

    public static void main(String[] args) {
        System.out.print("Start b");
        System.out.print("\033[s\nreplace b with h\033[u\bh\033[38;2;0;255;0mgreen text\033[0m");
    }

}

Expected behaviour: ("green text" is bright green)

Start hgreen text
replace b with h

console:

Start b←[s
replace b with h←[h←[38;2;0;255;0mgreen text←[0m

IDE: ("green text is bright green")

Start b
replace b with hgreen text

Is there something like the python os.system call to enable a more 'cooked' console output, or is there some sort of buffered write operation I have to do in order for these sequences to behave correctly?

  • windows I guess? https://stackoverflow.com/questions/5762491/how-to-print-color-in-console-using-system-out-println – weston Aug 05 '21 at 03:40
  • @weston I might not have made this clear, but the color sequences are not the issue, it comes through in ide emulated terminal. It's the other sequences, like cursor movement. I initially came across this problem when I tried to use \u001b[A to go up. – Michael Richards Aug 15 '21 at 23:35

0 Answers0