Page 1 of 1

Simulate Terminal in an EditorGadget

Posted: Fri Feb 23, 2024 6:24 pm
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

Re: Simulate Terminal in an EditorGadget

Posted: Fri Feb 23, 2024 9:50 pm
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


Re: Simulate Terminal in an EditorGadget

Posted: Sat Feb 24, 2024 2:26 am
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