logToConsole without a linebreak

I was wondering if it would be possible to remove the automatic linebreak \n and let people add one if they need it? So a program that emits characters(a-la write()) could use the logger.

Cheers!

1 Like

I would like to second this request (unless a way has been added in the meantime, but I can’t find anything in Inside Playdate with C). From the MicroPython interpreter I am trying to integrate in my program, I am getting output for the serial console in variably-sized, non-line-delimited chunks, and the \n added by playdate->system->logToConsole() totally butcher it. As long as it’s text, I could line-buffer it myself, but it could also be backspaces, terminal control escape sequences, or even arbitrary binary content. Without a write()-like function, I don’t see any way to handle this except adding another protocol layer (as I will probably have to do for the input direction, see `msg` command sim/device differences (control codes dropped, max length) - #4 by CWalther) and running the output through a decoder on the receiving system before it can go to an actual terminal.

You can turn off line breaks by using playdate.setNewlinePrinted(). Edit, I just noticed you're using C, that makes it slightly less convenient.

1 Like

Ah, good to know, thanks. But yes, a C API for the same thing would be helpful, as in this project I am not using Lua at all.

I opened an issue in our tracker to add this to the C API as well. Thanks for bringing it up.

5 Likes

Just wanted to add a +1 to this, I'm currently looking at adding Swift.print support to PlaydateKit (Swift bindings for the C API), and it requires implementing putchar. I can forward this to playdate->system->logToConsole, but without disabling newlines it will just print every character on a separate line.

4 Likes

I have done some tests (on OS/SDK 2.4.2) and found another related deficiency: logToConsole appears unable to output bytes of value zero ('\0') to the serial line. For all other values 1 – 255,
playdate->system->logToConsole("%c", i);
worked, but a zero just terminated the message:
playdate->system->logToConsole("abc%cdef", 0);
resulted in output "abc\n" instead of the expected "abc\0def\n".

I would appreciate if this could be addressed at the same time, either in logToConsole or by providing a separate more binary-friendly write()- or putchar()-like function.

1 Like

I too am getting bitten by this. The implied newline is making it hard to print what I want!