EditorGadget text char problem

Just starting out? Need help? Post your questions and find answers here.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

EditorGadget text char problem

Post by Dude »

Consider this code and its text output... how can I make the EditorGadget characters look like the cmd.exe output? I always assumed the EditorGadget was unicode? Maybe it's not? I don't know.

According to https://jpsoft.com/help/tree.htm, the "tree" command uses the "U.S. English extended ASCII character set. If your system is configured for a different country or language, or if you use a font which does not include these line drawing characters, the connecting lines in the tree display may not appear correctly (or not appear at all) on your screen. To correct the problem, use /A, or configure the TCC to use a font which can display standard extended ASCII characters."

However, using the "/A" switch for "tree" is not a solution, because it's "tree"-specific; and I need to put any given DOS output in the EditorGadget, with the correct characters at all times. So it sounds like I need a U.S. English extended ASCII font for the EditorGadget, and surely Windows would come with one installed by default? I tried "Terminal" but it didn't help (see bottom of this post).

Code: Select all

OpenWindow(0,200,200,300,120,"test",#PB_Window_SystemMenu)

EditorGadget(0,10,10,280,100)
;SetGadgetFont(0,FontID(LoadFont(#PB_Any,"Terminal",8))) ; Worse!

dir$=Chr(34)+"C:\Program Files\Internet Explorer"+Chr(34)
flags=#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read

p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$,"",flags)

While ProgramRunning(p)
  If AvailableProgramOutput(p)
    o$+ReadProgramString(p)+#CRLF$
  EndIf
Wend

SetGadgetText(0,o$)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Image

Output with "Terminal" as the font (shows 2 totally different fonts in the EditorGadget):

Image

:shock:
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: EditorGadget text char problem

Post by skywalk »

There is no issue with the EditorGadget.
Cut and paste the terminal text into Notepad or your EditorGadget and you will see the tree lines.
Even using ReadProgramData(, #PB_ASCII) or ReadProgramString(, #PB_ASCII) fails.
Try p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$ +" >c:\try\z.txt","",flags)
Open z.txt and it fails.
Workaround for my Char Set:

Code: Select all

OpenWindow(0,10,10,580,580,"test",#PB_Window_SystemMenu)
EditorGadget(0,10,10,580,580)
SetGadgetFont(0,FontID(LoadFont(#PB_Any,"Consolas",10))) ; Use a fixed pitch font.
dir$=Chr(34)+"C:\Program Files\Internet Explorer"+Chr(34)
flags=#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read
;p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$ +" >c:\try\z.txt","",flags)
p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$,"",flags)
While ProgramRunning(p)
  If AvailableProgramOutput(p)
    o$ + ReadProgramString(p, #PB_Ascii) + #CRLF$
  EndIf
Wend
o$ = ReplaceString(o$, "Ä", "─")
o$ = ReplaceString(o$, "Ã", "├")
o$ = ReplaceString(o$, "À", "└")
o$ = ReplaceString(o$, "³", "│")
SetGadgetText(0,o$)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget text char problem

Post by RASHAD »

Hi
Compile as Ascii Mode

Code: Select all

OpenWindow(0,200,200,300,120,"test",#PB_Window_SystemMenu)

StringGadget(0,10,10,280,100,"",#ES_MULTILINE)
SetGadgetFont(0,FontID(LoadFont(#PB_Any,"Terminal",8))) ; Worse!

dir$=Chr(34)+"C:\Program Files\Internet Explorer"+Chr(34)
flags=#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read

p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$,"",flags)

While ProgramRunning(p)
  If AvailableProgramOutput(p)
    o$+ReadProgramString(p)+#CRLF$
  EndIf
Wend

SetGadgetText(0,o$)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: EditorGadget text char problem

Post by Dude »

Skywalk, your workaround just shows "+---" for the output (for me), instead of lines. Also, it wouldn't cover situations where other unknown extended characters might pop up from a DOS output, so I can't rely on it. Or is "tree" the only DOS command that uses them? That might be a way out -- I could put a note in my docs that the output may not always match a real DOS prompt, so my users understand why it looks different. That's kind of a lame way out, though.

Rashad, I need to use an EditorGadget because it uses coloring (not shown in my example; I just stripped it down for the snippet to show the problem). Also, how do we compile in Ascii anyway? I thought that was disabled in the latest PureBasic versions, so I changed all my Ascii string routines in all my apps to be Unicode-compatible some time ago. I don't want to go back again. :(

Sorry that I always seem to find hard problems with my apps. :?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget text char problem

Post by RASHAD »

You have to use a Plain Text gadget to receive DOS output
PB EditorGadget is RTF and I failed to switch it to Plain
Beside with plain you can not use more than one color
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: EditorGadget text char problem

Post by Dude »

RASHAD wrote:You have to use a Plain Text gadget to receive DOS output
Okay, I will just have to keep the DOS output with the corrupted characters. I have no choice because the EditorGadget is used for other things too, that need color. Thanks for the info, as always. :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget text char problem

Post by RASHAD »

PB 5.61 x86 Win 10 x64
Workaround
I start to hate Workaround procedure :P

Code: Select all

OpenWindow(0,200,200,300,120,"test",#PB_Window_SystemMenu)

EditorGadget(0,10,10,280,100)
SetGadgetFont(0,FontID(LoadFont(#PB_Any,"Consolas",8))) ; Worse!

dir$=Chr(34)+"C:\Program Files\Internet Explorer"+Chr(34)
flags=#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read

p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$,"",flags)

While ProgramRunning(p)
  If AvailableProgramOutput(p)
    o$+ReadProgramString(p)+#CRLF$
  EndIf
Wend
o$ = ReplaceString(o$,"����","├── ")
SetGadgetText(0,o$)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
#2 :

Code: Select all

OpenWindow(0,200,200,300,120,"test",#PB_Window_SystemMenu)

EditorGadget(0,10,10,280,100)
SetGadgetFont(0,FontID(LoadFont(#PB_Any,"Consolas",8))) ; Worse!

dir$=Chr(34)+"C:\Program Files\Internet Explorer"+Chr(34)
flags=#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read

p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$,"",flags)

While ProgramRunning(p)
  If AvailableProgramOutput(p)
    o$+ReadProgramString(p)+#CRLF$
  EndIf
Wend
o$ = ReplaceString(o$,"����","├── ")
o$ = ReplaceString(o$,"├── ","└── ",#PB_String_NoCase,140)
SetGadgetText(0,o$)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Egypt my love
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: EditorGadget text char problem

Post by skywalk »

Dude wrote:Skywalk, your workaround just shows "+---" for the output (for me), instead of lines. Also, it wouldn't cover situations where other unknown extended characters might pop up from a DOS output, so I can't rely on it. Or is "tree" the only DOS command that uses them? That might be a way out -- I could put a note in my docs that the output may not always match a real DOS prompt, so my users understand why it looks different. That's kind of a lame way out, though.
That is weird. On my Windows 10 and latest PB v561x64 I get lines. Make sure you set your source code text file encoding to UTF-8 in the preferences.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: EditorGadget text char problem

Post by Dude »

Skywalk, still no luck. I'm on Win 7.

Rashad, I can't use your snippets because copying "�" becomes Chr(63) when I paste it into the IDE. What is the Asc() value of "�" anyway? I can't tell from Firefox.

Anyway, don't worry about it too much, guys. I appreciate your efforts but I'll just mention the problem in the docs, that the log window is not a real command prompt and thus is not 100% compatible with real DOS output. It's all good. :)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: EditorGadget text char problem

Post by Shardik »

Dude wrote:Consider this code and its text output... how can I make the EditorGadget characters look like the cmd.exe output? I always assumed the EditorGadget was unicode? Maybe it's not? I don't know.
According to this PB blog entry PB's EditorGadget utilizes in Windows the RICHEDIT_CLASS. The EditorGadget allows to display plain text or text in the Rich Text Format (RTF), a proprietary document file format specification developed by Microsoft. A standard RTF file can consist of only 7-bit ASCII characters, but can encode characters beyond ASCII by escape sequences. As an alternative to display the 8-bit DOS graphics characters in the EditorGadget you have to define the correct header for the EditorGadget's RTF mode. Important is the correct ANSI code page ("ansicpg1252", Western European) and the correct charater set ("fcharset254", PC 437) which is able to display the DOS graphics characters.

I have modified your program from above to display DOS graphics characters in the EditorGadget in ASCII and Unicode mode (tested on Windows 7 SP1 x64):

Image

Unfortunately the example only works in Unicode mode in PB 5.51 x86 and x64 because up to PB 5.51 (only Unicode mode implemented) SetGadgetText() had to transmit the text with SetGadgetTest() to the EditorGadget as ASCII text. In PB 5.4x and PB 5.6x Fred seemed to have changed this so that SetGadgetText() works with Unicode text but internally converts the Unicode text to ASCII. This conversion seems to interfere with the conversion into CP437 so that the DOS graphics characters get lost... :(

The same example also works in ASCII mode in PB 5.46 but (as already explained) not in Unicode mode.

So if you need DOS graphics characters in the EditorGadget in Unicode mode you have to use PB 5.51 or wait until someone finds a working solution for PB 5.61... :wink:

Code: Select all

OpenWindow(0,200,200,500,170,
  "EditorGadget with DOS Graphics characters in Unicode mode")
EditorGadget(0,10,10,480,150,#PB_Editor_WordWrap)

dir$=Chr(34)+"C:\Program Files\Internet Explorer"+Chr(34)
flags=#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read

p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$,"",flags)

While ProgramRunning(p)
  If AvailableProgramOutput(p)
    o$+ReadProgramString(p, #PB_Ascii)+"\par"
  EndIf
Wend

a$ = "{\rtf1\ansi\ansicpg1252\deff0\deflang3082{\fonttbl" +
  "{\f0\fmodern\fcharset254}}" + o$ + "}"
b$ = Space(StringByteLength(a$, #PB_Ascii) + 1)
PokeS(@b$, a$, -1, #PB_Ascii)
SetGadgetText(0, b$)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: EditorGadget text char problem

Post by Dude »

Hi Shardik, thanks for trying to help but I'm using 5.61 and don't want a lesser PureBasic.

Unfortunately it means I end up with this, as you mentioned:

Image

:(
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: EditorGadget text char problem

Post by srod »

Code: Select all

SendMessage_(GadgetID(0), #WM_SETTEXT, 0, @b$)
:wink:
I may look like a mule, but I'm not a complete ass.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: EditorGadget text char problem

Post by Dude »

Srod, we're so close! :D About 99% there! Just how to use a better font like Courier or Terminal?
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: EditorGadget text char problem

Post by Shardik »

Thank you very much Stephen, I have been so close! :twisted:

This example works in PB 5.46 in ASCII and Unicode mode and in PB 5.61:

Code: Select all

OpenWindow(0,200,200,500,170,
  "EditorGadget with DOS Graphics characters in Unicode mode")
EditorGadget(0,10,10,480,150,#PB_Editor_WordWrap)

dir$=Chr(34)+"C:\Program Files\Internet Explorer"+Chr(34)
flags=#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read

p=RunProgram(GetEnvironmentVariable("comspec"),"/c tree "+dir$,"",flags)

While ProgramRunning(p)
  If AvailableProgramOutput(p)
    o$+ReadProgramString(p, #PB_Ascii)+"\par"
  EndIf
Wend

a$ = "{\rtf1\ansi\ansicpg1252\deff0\deflang3082{\fonttbl" +
  "{\f0\fmodern\fcharset254}}" + o$ + "}"
b$ = Space(StringByteLength(a$, #PB_Ascii) + 1)
PokeS(@b$, a$, -1, #PB_Ascii)
SendMessage_(GadgetID(0), #WM_SETTEXT, 0, @b$)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: EditorGadget text char problem

Post by skywalk »

Dude - What OS are you running?
Shardik's example works but the font is poor.
I don't know how to specify Consolas font in the \rtf sequence.
If I use my replacestring() approach, I get a uniform font in the editor.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply