printing to the console without newline?

Posted on
  • Dumb question: is there a way to print a string to the console without newline? Both console.log() and print() add a newline.

  • With console.log() had expected that... but with print() there usually goes also a println()... like write() and writeln()... but I'm obviously mistaken.

  • print is exactly the same as console.log in Espruino - it's really there just to make it easier for learners...

    If you know where the console is (eg. Serial1) you can just do Serial1.write - but you should be aware that you can totally mess things up - console.log actually removes the current line(s) being input in the console before writing your text (the current input line is then put back when your JS function has finished executing)

  • So there's no way to print long lines incrementally, one has to build the string in memory and then print it at once? Sigh.

  • I can't say I'm fond of a .print() method appending line ending. That's what .println() methods should be for.

  • Well, Serial.print doesn't print a line ending, Serial.println does. It's just print() that's there - a bit confusing, but handy for people new to JS who just want to do 'Hello World'.

    To be honest it looks like a JS thing - it's not just Espruino: http://stackoverflow.com/questions/61574­97/node-js-printing-to-console-without-a­-trailing-newline

    If you want to print a bit of a line at once, do console.log() which will print a newline (but will clear off the current input line and make sure it gets put back). Then use USB.print() or similar.

    I guess to make it more compatible I could make process.stdout and stdin point to the current Serial device.

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

printing to the console without newline?

Posted by Avatar for tve @tve

Actions