How to print newline in graphical console

Just starting out? Need help? Post your questions and find answers here.
endo
Enthusiast
Enthusiast
Posts: 141
Joined: Fri Apr 30, 2004 10:44 pm
Location: Turkiye (istanbul)
Contact:

How to print newline in graphical console

Post by endo »

How can I print a line (or a content read from a file etc.) that includes newline (10, 13 or 0x0D0A) in graphical console?

Code: Select all

EnableGraphicalConsole(1)
PrintN("hello" + #CRLF$ + "world")
This prints out

Code: Select all

hello☐☐world
on the console. If I remove EnableGraphicalConsole then it works as expected.
I tried each combination of CR, LF, CRLF.

Note that below code also works as expected, so I don't know what PrintN does different:

Code: Select all

PrintN("hello")
PrintN("world")
-= endo (registered user of purebasic since 98) =-
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: How to print newline in graphical console

Post by BarryG »

Quick workaround:

Code: Select all

Procedure PrintNN(text$)
  crlf=CountString(text$,#CRLF$)+1
  For n=1 To crlf
    PrintN(StringField(text$,n,#CRLF$))
  Next
EndProcedure

OpenConsole()
EnableGraphicalConsole(1)
PrintNN("hello"+#CRLF$+"world")
Input()
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: How to print newline in graphical console

Post by Marc56us »

You can also change mode as you want after open console.
In mode 0 CRLF work

Code: Select all

OpenConsole()

EnableGraphicalConsole(1)
PrintN("Console mode 1" + #CRLF$ + " Graphic (no CRLF)")

EnableGraphicalConsole(0)
PrintN("(Console mode 0" + #CRLF$ + "Text with CRLF)")

EnableGraphicalConsole(1)
ConsoleLocate(7, 8) 
PrintN("Console mode 1")
Print("Press Return")

Input()
endo
Enthusiast
Enthusiast
Posts: 141
Joined: Fri Apr 30, 2004 10:44 pm
Location: Turkiye (istanbul)
Contact:

Re: How to print newline in graphical console

Post by endo »

Thanks for the replies, both methods are useful.
Is it a bug of PureBasic or a known issue of Windows?
-= endo (registered user of purebasic since 98) =-
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: How to print newline in graphical console

Post by Olliv »

ROFL !!

Thank you endo !

The best laugh since long time :

I can read << Hello >> << Vote >> << Vote >> << World >>.

:D

(We would want to do it, that we cannot do it : random... I kept screenshoots)
Post Reply