• Hi,
    Is there an existing way to colour text being displayed in the Web IDE Terminal window.
    Specifically for colouring the text from the execution of console.log('string') in espruino.

    It seems a common method would be to prefix the string with an ANSI escape sequence such as
    Red: \u001b[31m. or green
    Green: \u001b[32m
    This works in node in vscode.

    Ive tried this in Espruino WebIDE

    console.log (" \u001b[31m HelloWorld ");
    

    and it looks like the the escape sequence is being trapped , because not all of it is printed.

    Ive had a poke around the WebIDE code on github but I cant find the code that handles the terminal window. I can see that there is colour styling of the code editor window.

    My use case is im having a quick look at the feasability of a simple jest style unit testing tool and would like to colour the output to the console. Which looks good so far. (colour is a bit of a nice to have I would agree)

    Any cluse on an approach to implement the coloured output text appreciated. And a high level of how the terminal window is driven ??. Is there is some escape sequence to HTML going on somehwere ??

    Thanks in advance, Simon

  • cant find the code that handles the terminal window

    it is in EspruinoTools submodule
    https://github.com/espruino/EspruinoTools/blob/master/core/terminal.js

    Don't see anything about color and also any html printed by js code is escaped. Special case are inline images produced by g.dump() - handled here https://github.com/espruino/EspruinoTools/blob/master/core/terminal.js#L438

    escape codes handled here https://github.com/espruino/EspruinoTools/blob/master/core/terminal.js#L521

  • Thanks @fanoush , that's a great start.

  • Exactly as @fanoush says - I'd handle it in terminal.js. Handling color in ANSI escape sequences would be great!

  • Ok, Ill have a go. Thanks

  • Hi,
    Ive got a version of this change that im testing. Ive set out an issue https://github.com/espruino/EspruinoTools/issues/154
    to track this as a change. See the issue for more detail and link to my fork.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino Web IDE - terminal window - coloured text in concole.log string

Posted by Avatar for SimonGAndrews @SimonGAndrews

Actions