Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to input graphics on a console without JFrame?

I use codiva to do my coding on a chromebook. I was just wondering if I could create graphics in a console output. For example, my text right now is plain and normal(it prints in the console as plain text). Is there a way to bold, emphasize, or even change the color of the text if I can only use the console for output(no canvas, Jframe, popup, etc.)?

I have tried "\u001B[1m (bold text)" and all I get is (see Output). Same goes for the italic one.

Output:

like image 326
FairOPShotgun Avatar asked Feb 21 '26 15:02

FairOPShotgun


1 Answers

The interpretation of control sequences is subject of the specific console and it seems, codiva.io’s console doesn’t interpret any control sequences.

However, since it’s displayed in a browser and browsers usually have broad Unicode support, you can achieve a limited formatting using special codepoints. E.g.

class HelloCodiva {
    public static void main(String[] args) {
        System.out.println("Formatted: "
            + bold("bold") + " " + italic("italic") + " " + bold(italic("both")));
    }

    static CharSequence bold(CharSequence cs) {
        return trans(cs, 0x1D400, 0x1D41A);
    }

    static CharSequence italic(CharSequence cs) {
        return trans(cs, 0x1D434, 0x1D44e);
    }

    static CharSequence trans(CharSequence cs, int upper, int lower) {
        return cs.codePoints()
            .map(cp -> cp >= 'A' && cp <= 'Z'? cp + upper - 'A':
                       cp >= 'a' && cp <= 'z'? cp + lower - 'a':
                       cp >= 0x1D400 && cp <= 0x1D433? cp + 104:
                       cp >= 0x1D434 && cp <= 0x1D467? cp + 52:
                       cp)
            .collect(StringBuilder::new,
                     StringBuilder::appendCodePoint, StringBuilder::append);
    }
}

prints

Formatted: 𝐛𝐨π₯𝐝 π‘–π‘‘π‘Žπ‘™π‘–π‘ 𝒃𝒐𝒕𝒉

In codiva.io’s console.

The limitation is that it only works for letters. But for highlighting important words, it might be sufficient.

like image 111
Holger Avatar answered Feb 23 '26 14:02

Holger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!