Simulate Terminal 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

Simulate Terminal in an EditorGadget

Post by danny88 »

hi
i'm trying to simulate Windows terminal behaviour inside an EditorGadget, so far i've done this :

Code: Select all

EnableExplicit

Define EventID

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(1, 0, 0, 500, 400, #PB_Editor_WordWrap)
  SetGadgetText(1, "Windows Terminal Simulation")
  SetGadgetColor(1, #PB_Gadget_BackColor, 0)
  SetGadgetColor(1, #PB_Gadget_FrontColor, $C0C0C0)
  SetGadgetFont(1, FontID(LoadFont(#PB_Any, "lucida console", 11)))
  SetActiveGadget(1)
  SendMessage_(GadgetID(1), #EM_SETSEL, $fffffff, $fffffff)
 
  Repeat
    EventID = WaitWindowEvent()
    If EventID = #WM_KEYDOWN And EventWindow() = 0
      SendMessage_(GadgetID(1), #EM_SETSEL, $fffffff, $fffffff)
    EndIf

    If EventID = #PB_Event_CloseWindow
      End
    EndIf
  ForEver
EndIf
Now i need two things :
1 - Limite characters deletion using backspace until a certain position (position of the prompt "c:\>" for instance)
2 - Detect when user presses Enter.

Thanks
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Simulate Terminal in an EditorGadget

Post by RASHAD »

A clue to start from

Code: Select all

EnableExplicit

Define Quit,key,p.POINT,row,text$

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(1, 0, 0, 500, 400, #PB_Editor_WordWrap)
  AddGadgetItem(1, -1,"Windows Terminal Simulation")
  AddGadgetItem(1,-1,"c:\>Windows Terminal Simulation")
  SetGadgetColor(1, #PB_Gadget_BackColor, 0)
  SetGadgetColor(1, #PB_Gadget_FrontColor, $C0C0C0)
  SetGadgetFont(1, FontID(LoadFont(#PB_Any, "lucida console", 11)))
  SetActiveGadget(1)
  
  Repeat
    Select  WaitWindowEvent(1)
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #WM_CHAR
        If GetActiveGadget() = 1
          key = EventwParam()
          If key = 13
            MessageRequester("Info","Return key pressed",#PB_MessageRequester_Ok)
          ElseIf key = 8
            GetCaretPos_(p.POINT)
            Row = SendMessage_(GadgetID(1),#EM_LINEFROMCHAR,-1,0)
            text$ =GetGadgetItemText(1,row)
            If Left(text$,4) = "c:\>" And Len(text$) = 4
              Debug "OK"
            EndIf
          EndIf            
        EndIf

    EndSelect
  Until Quit = 1
EndIf

Egypt my love
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Simulate Terminal in an EditorGadget

Post by danny88 »

RASHAD wrote: Fri Feb 23, 2024 9:50 pm A clue to start from

Code: Select all

EnableExplicit

Define Quit,key,p.POINT,row,text$

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(1, 0, 0, 500, 400, #PB_Editor_WordWrap)
  AddGadgetItem(1, -1,"Windows Terminal Simulation")
  AddGadgetItem(1,-1,"c:\>Windows Terminal Simulation")
  SetGadgetColor(1, #PB_Gadget_BackColor, 0)
  SetGadgetColor(1, #PB_Gadget_FrontColor, $C0C0C0)
  SetGadgetFont(1, FontID(LoadFont(#PB_Any, "lucida console", 11)))
  SetActiveGadget(1)
  
  Repeat
    Select  WaitWindowEvent(1)
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #WM_CHAR
        If GetActiveGadget() = 1
          key = EventwParam()
          If key = 13
            MessageRequester("Info","Return key pressed",#PB_MessageRequester_Ok)
          ElseIf key = 8
            GetCaretPos_(p.POINT)
            Row = SendMessage_(GadgetID(1),#EM_LINEFROMCHAR,-1,0)
            text$ =GetGadgetItemText(1,row)
            If Left(text$,4) = "c:\>" And Len(text$) = 4
              Debug "OK"
            EndIf
          EndIf            
        EndIf

    EndSelect
  Until Quit = 1
EndIf

Thanks bro
Post Reply