Mimic command line behaviour in an EditorGadget()

Just starting out? Need help? Post your questions and find answers here.
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Mimic command line behaviour in an EditorGadget()

Post by danny88 »

Hello

My first probleme was to find how to close a Console window without terminating the whole program. As I found out that it was impossible, is there a way to mimic a console behaviour inside an EditorGagdet, which means that the user can only enter input at the last cursor position and an output is generated when user hits "Enter" .

any other solution is welcome
Thanks
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Mimic command line behaviour in an EditorGadget()

Post by Randy Walker »

Try this in v6.11 or above, Windows Only!!. (don't know about others) I don't think you can type anywhere except end of the text.

Code: Select all

#KB_Return = #PB_Shortcut_Return + 49152

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    EditorGadget(0, 8, 8, 306, 133)
    For a = 0 To 5
      AddGadgetItem(0, a, "Line "+Str(a))
    Next
  AddKeyboardShortcut(0, #PB_Shortcut_Return, #KB_Return)
    SetActiveGadget(0) ; necessary to get cursor active in edit box.
    Repeat
    SendMessage_(GadgetID(0),#EM_SETSEL,-1,-1) ; Force cursor to End of text.
    Select EventMenu()
      Case #KB_Return ; Catch Return Key
        s$ = GetGadgetText(0)   ;get input if return key
        Break ; exit the loop with all text in s$
    EndSelect

    Until WaitWindowEvent() = #PB_Event_CloseWindow  
EndIf
Debug s$
[HINT] do web search for "EM_SETSEL" to learn about cursor placement and text selections.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: Mimic command line behaviour in an EditorGadget()

Post by Axolotl »

Did you ask a similar question back in February?

Simulate Terminal in an EditorGadget
Does the RASHAD example not work?

Perhaps this is something for you?
Module: TerminalGadget
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Mimic command line behaviour in an EditorGadget()

Post by Randy Walker »

Axolotl wrote: Fri Sep 13, 2024 1:20 pm Did you ask a similar question back in February?
I didn't ask the question. I ran into this coding question post and noticed it had no reply so I replied.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Mimic command line behaviour in an EditorGadget()

Post by Quin »

Randy Walker wrote: Fri Sep 13, 2024 5:41 pm
Axolotl wrote: Fri Sep 13, 2024 1:20 pm Did you ask a similar question back in February?
I didn't ask the question. I ran into this coding question post and noticed it had no reply so I replied.
Looks like the OP made two topics about this issue, this one that never got any replies until recently, and the one linked a couple posts back.
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: Mimic command line behaviour in an EditorGadget()

Post by Axolotl »

Yeah, Quin is right.
Quin wrote: Fri Sep 13, 2024 11:04 pm Randy Walker wrote: ↑13 Sep 2024, 18:41

Axolotl wrote: ↑13 Sep 2024, 14:20
Did you ask a similar question back in February?

I didn't ask the question. I ran into this coding question post and noticed it had no reply so I replied.

Looks like the OP made two topics about this issue, this one that never got any replies until recently, and the one linked a couple posts back.
I (never) look at the date. So, Randy, if you felt offended. Here's my apology. Because that was not my intention. :oops:
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Randy Walker
Addict
Addict
Posts: 1109
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: Mimic command line behaviour in an EditorGadget()

Post by Randy Walker »

Axolotl wrote: Sun Sep 15, 2024 1:30 pm Yeah, Quin is right.

I (never) look at the date. So, Randy, if you felt offended. Here's my apology. Because that was not my intention. :oops:
:lol: Nope, not offended. All comments welcome :)
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply