Cut and Paste in Terminal

User avatar
cogier
Site Admin
Posts: 159
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Cut and Paste in Terminal

Post by cogier » Tuesday 05th December 2017 3:31pm

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 28 times

didier18
Posts: 31
Joined: Monday 19th December 2016 10:08pm

Re: Cut and Paste in Terminal

Post by didier18 » Wednesday 06th December 2017 12:06am

Hello Cogier

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

Have a nice day.

User avatar
cogier
Site Admin
Posts: 159
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Cut and Paste in Terminal

Post by cogier » Wednesday 06th December 2017 5:24pm

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!

didier18
Posts: 31
Joined: Monday 19th December 2016 10:08pm

Re: Cut and Paste in Terminal

Post by didier18 » Wednesday 06th December 2017 8:54pm

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.

User avatar
cogier
Site Admin
Posts: 159
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Cut and Paste in Terminal

Post by cogier » Thursday 07th December 2017 3:29pm

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. :(

didier18
Posts: 31
Joined: Monday 19th December 2016 10:08pm

Re: Cut and Paste in Terminal

Post by didier18 » Thursday 07th December 2017 4:19pm

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.

User avatar
jornmo
Site Admin
Posts: 148
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Cut and Paste in Terminal

Post by jornmo » Friday 08th December 2017 5:39pm

She :roll: :D

User avatar
cogier
Site Admin
Posts: 159
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Cut and Paste in Terminal

Post by cogier » Sunday 10th December 2017 5:05pm

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

didier18
Posts: 31
Joined: Monday 19th December 2016 10:08pm

Re: Cut and Paste in Terminal

Post by didier18 » Tuesday 12th December 2017 10:49am

Hello cogier

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

Have a nice day.

User avatar
cogier
Site Admin
Posts: 159
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Cut and Paste in Terminal

Post by cogier » Wednesday 13th December 2017 6:37pm

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 583 times
EasyTerminal.tar
(799 KiB) Downloaded 27 times

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest