We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › println and java escape sequences
Page Index Toggle Pages: 1
println and java escape sequences (Read 608 times)
println and java escape sequences
Jan 29th, 2009, 2:06am
 
When using println to send text to the text area, I see the following behaviors with respect to escape sequences:

Works:
\n = linefeed
\t = tab  
\" = double quote
\' = single quote

Doesn't Work:
\r = carriage return  
\f = formfeed  
\b - backspace

Any insights on this? Thanks.
Re: println and java escape sequences
Reply #1 - Jan 29th, 2009, 5:25am
 
very interesting question you have there. I checked out backspace -
> System.out.print("hello w\borld\b");
prints
> hello orld
which probably means 1.something is printed after the 'd' in hello world
or 2. \b doesn't work at the end of a line
Re: println and java escape sequences
Reply #2 - Jan 29th, 2009, 8:47am
 
What do you mean by "doesn't work"? At least the escape sequences are accepted as legal...

You should define what behavior you expect...
The console area has the behavior it was told to have, it is neither a Windows command line window nor a Unix terminal. The latter has the behavior defined by its TERM, or even its hardware (in good (?) old times before graphical interfaces).

The console is mostly designed for information and log output, not for special effect like superposing characters (it was used in Unix man pages, to underscore or strike words, using \b indeed) or re-writing on the same line (using \r) or perhaps clearing the console (\f).

These effects can be done, I suppose. But somebody have to program them. Not sure efforts in this field are worth it.
Re: println and java escape sequences
Reply #3 - Jan 30th, 2009, 2:37am
 
Hi,

As to not working, the command print("text1\b2");
produces the following output:
  text1*2
where * is a white square outline.

The output that I expected was:
  text2

The command print("LINE 2 \r LINE 3");
produces the following output:
  LINE 2  LINE 3
The output that I expected was:
  LINE 3

The command print("Word 1 \f Word 2");
produces the following output:
  Word 1 * Word 2
where * is a white square outline.
I didn't know quite what to expect with this one but I certainly didn't expect the output I got.

I'm guessing that Processing is intercepting the escape code but doesn't know what to do with it so sends it to the screen to be displayed hence the appearance of a non-printable character.

I use print and println for debugging. Unfortunately it does not appear that there is a way to make new text overwrite old text. For example, as a loop counter because one line of output is a heck of a lot easier to follow than a few thousand lines.

FYI, I'm using Processing 1.0.1 on XP with Java 1.6.0_11





Re: println and java escape sequences
Reply #4 - Jan 30th, 2009, 10:18am
 
Well, your expectation isn't foolish Wink but as I wrote, it has to be coded. The console area isn't a terminal, and probably relies on default Java behavior for these characters. Which itself might just ask the system to try and display them. On Windows with an OEM charset, it might display funny chars, on SciTE editor, it would be a black rounded box with the control char name in it, etc.
The console just acts as a log, recording everything set, but not trying fancy stuff there.

Perhaps you should extend slightly your sketch area and have a "status bar" displaying the information you need with text() calls.
Re: println and java escape sequences
Reply #5 - Jan 30th, 2009, 9:19pm
 
PhiLho  wrote on Jan 30th, 2009, 10:18am:
Perhaps you should extend slightly your sketch area and have a "status bar" displaying the information you need with text() calls.


I was really hoping to be able to put the text area to better use. Plus with the text area I can copy my output to the clipboard and paste it into another document, like Excel if the problem is math related. Alternatively I could write to a log file but I was hoping to keep things as simple as possible.

Thanks for your help.


Page Index Toggle Pages: 1