Page 1 of 2

Cut and Paste in Terminal

Posted: Tuesday 5th December 2017 3:31pm
by cogier
Can anyone point me in the right direction. I am trying to Cut and Paste in a Gambas Terminal. I have attached a small program to help highlight the issue. I would like to be able to Copy selected text from Terminal and Paste text into Terminal. I can Copy but only ALL the text, no need to highlight. :cry:
Terminal_Copy_Paste.tar
(28.5 KiB) Downloaded 444 times

Re: Cut and Paste in Terminal

Posted: Wednesday 6th December 2017 12:06am
by didier18
Hello Cogier

Maybe using the "Clipboard" function...
Type "cli"... then a popup should open in the help...

Have a nice day.

Re: Cut and Paste in Terminal

Posted: Wednesday 6th December 2017 5:24pm
by cogier
Thanks Didier but I still can't get it to work. I have even loaded the Gambas daily build on a computer hoping that the 'help' for TerminalView had been updated, but no!

Re: Cut and Paste in Terminal

Posted: Wednesday 6th December 2017 8:54pm
by didier18
Hello Cogier

Yes, I misunderstood your question.
In fact you would like to retrieve what is highlighted in the end part (and only this?).
Maybe a start to the track...
When you type 1 command, it starts with "#" and each answer is separated by "\n".
When you type 2 commands, they are separated by a "#" and the internal answers are also separated by a "\n".
All of this is visible in the text property.
Maybe a split might be suitable for temporary use?
Here is an example when I type probepart and probedisk commands.
Of course it is easier for me to type these commands in "shell" and get the result in a variable...

It all depends on what you want to do...

Code: Select all

"# probepart\n/dev/sda1|ext3|109373440\n/dev/sda5|swap|7852032\n# probedisk\n/dev/sda|drive|ATA ST96812AS \n/dev/sr0|optical|TSSTcorpDVD+-RW \nTS-U633F\n# "
Have a nice day.

Re: Cut and Paste in Terminal

Posted: Thursday 7th December 2017 3:29pm
by cogier
I have tried looking for the '\n' (gb.newline) but it is not put in the text so does not show up in a string. :(

Re: Cut and Paste in Terminal

Posted: Thursday 7th December 2017 4:19pm
by didier18
Hello cogier

In the "Public Sub TerminalMenu_Click ()",
you have to declare "sline" and she's the one who will retrieve the contents of "TerminalView1. Text"
Public Sub TerminalMenu_Click()
Dim sline As String

  sline = TerminalView1.Text
  
  Print sline
  Wait
     
' Select Case Last.Name
'   Case "MenuPaste"
'     'TerminalView1.Input = Clipboard.Paste
'   Case "MenuCopy"
'     Clipboard.Copy(TerminalView1.Text) ''Copys ALL the text in Terminal without the need to highlight?
' End Select
End
Set a stop point on the "wait" to analyze the content "sline".
Or look in the console...

Have a nice day.

Re: Cut and Paste in Terminal

Posted: Friday 8th December 2017 5:39pm
by jornmo
She :roll: :D

Re: Cut and Paste in Terminal

Posted: Sunday 10th December 2017 5:05pm
by cogier
With the help of my friend Matt we found that the 'TerminalView.copy' works fine but we could not get the 'TerminalView.paste' to work. So with the help of 'Desktop.sendkeys' we came up with the following code for the 'Terminal_Copy_Paste' program in my first post.

Thanks for all the input.
pBash As Process
sCopy As String

Public Sub Form_Show()

pBash = TerminalView1.Exec(["bash"])
TerminalView1.SetFocus

End

Public Sub ButtonClear_Click()

TextArea1.Clear
TerminalView1.SetFocus

End

Public Sub Form_Close()

pBash.close

End

Public Sub TerminalMenu_Click()
Dim sTemp As String

TerminalView1.setfocus
Select Case Last.Name
  Case "MenuPaste"
    sTemp = Clipboard.Paste("text/plain")
    SendTheKeys(sTemp)
  Case "MenuCopy"
    TerminalView1.Copy
End Select
End

Public Sub SendTheKeys(sText As String)
Dim siCount As Short

For siCount = 1 To Len(sText)
  If Mid(sText, siCount, 1) = "[" Then 
    Desktop.SendKeys("[bracketleft]")
  Else
    Desktop.SendKeys(Mid(sText, siCount, 1))
  Endif
Next

End

Re: Cut and Paste in Terminal

Posted: Tuesday 12th December 2017 10:49am
by didier18
Hello cogier

Simple and effective solution.
Thank you and congratulations to you both.

Have a nice day.

Re: Cut and Paste in Terminal

Posted: Wednesday 13th December 2017 6:37pm
by cogier
The attached program was what it was all about. I would appreciate any feed back as I know you good people use different Distros.
EasyTerminal_378.png
EasyTerminal_378.png (3.74 MiB) Viewed 11292 times
EasyTerminal.tar
(799 KiB) Downloaded 475 times