[update]
- added pipe and stream support to terminal class git-svn-id: svn://localhost/gambas/trunk@8105 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
e68cad85c4
commit
207dbcdfb5
10 changed files with 441 additions and 19 deletions
Binary file not shown.
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.5 KiB |
|
@ -1,13 +1,14 @@
|
|||
# Gambas Project File 3.0
|
||||
# Compiled with Gambas 3.9.90
|
||||
Title=Gambas Terminal control
|
||||
Startup=FTestTerminalView
|
||||
Startup=PipeTest
|
||||
Icon=terminalview.png
|
||||
Version=3.9.90
|
||||
VersionFile=1
|
||||
Component=gb.image
|
||||
Component=gb.gui
|
||||
Component=gb.form
|
||||
Component=gb.net
|
||||
Authors="Benoît Minisini\nFabien Bodard"
|
||||
TabSize=2
|
||||
Language=fr
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
}
|
||||
}
|
||||
{ Timer1 #Timer
|
||||
#MoveScaled(117,17)
|
||||
#MoveScaled(4,63)
|
||||
Delay = 50
|
||||
}
|
||||
}
|
||||
|
|
209
comp/src/gb.form.terminal/.src/TerminalView/PipeTest.class
Normal file
209
comp/src/gb.form.terminal/.src/TerminalView/PipeTest.class
Normal file
|
@ -0,0 +1,209 @@
|
|||
' Gambas class file
|
||||
|
||||
Private $hPipeIn As File
|
||||
Private $hPipeOut As File
|
||||
Private InPipe As File
|
||||
Private OutPipe As File
|
||||
Private $hMySock As Socket
|
||||
|
||||
Public TheTask As PipedTask
|
||||
|
||||
|
||||
|
||||
Public Sub Form_Open()
|
||||
|
||||
OutPipe = Pipe "/tmp/MyPipeIn" For Write ' providers output pipe
|
||||
$hPipeIn = Pipe "/tmp/MyPipeIn" For Read Watch
|
||||
|
||||
$hPipeOut = Pipe "/tmp/MyPipeOut" For Write ' open this first so other side never blocks
|
||||
InPipe = Pipe "/tmp/MyPipeOut" For Read ' providers in pipe
|
||||
|
||||
|
||||
If Not Term.Piped(OutPipe, InPipe) Then
|
||||
|
||||
Close $hPipeOut
|
||||
Close InPipe
|
||||
Close OutPipe
|
||||
Close $hPipeIn
|
||||
$hPipeIn = Null
|
||||
$hPipeOut = Null
|
||||
InPipe = Null
|
||||
OutPipe = Null
|
||||
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub file_read()
|
||||
|
||||
If Not Lof($hPipeIn) Then Return
|
||||
|
||||
DataFromTerminal.Text &= Read #$hPipeIn, Lof($hPipeIn)
|
||||
|
||||
End
|
||||
|
||||
Public Sub sndTxt_Click()
|
||||
|
||||
If TheTask Then
|
||||
TaskStop_Click()
|
||||
Endif
|
||||
|
||||
If Not $hPipeIn Then
|
||||
Form_Open()
|
||||
Endif
|
||||
|
||||
Write #$hPipeOut, dataToSend.Text
|
||||
|
||||
End
|
||||
|
||||
Public Sub KillSession_Click()
|
||||
|
||||
Term.Kill()
|
||||
|
||||
If $hPipeIn Then Close #$hPipeIn
|
||||
If $hPipeOut Then Close #$hPipeOut
|
||||
If InPipe Then Close InPipe
|
||||
If OutPipe Then Close OutPipe
|
||||
|
||||
$hPipeIn = Null
|
||||
$hPipeOut = Null
|
||||
InPipe = Null
|
||||
OutPipe = Null
|
||||
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Sub TaskTest_Click()
|
||||
|
||||
If TheTask Then Return
|
||||
|
||||
PipedTask.$sInputFileName = "/tmp/MyPipeIn"
|
||||
PipedTask.$sOutputFileName = "/tmp/MyPipeOut"
|
||||
|
||||
TheTask = New PipedTask As "TheBestTask" ' Start the task which should wait on the input stream until opened by the terminal
|
||||
|
||||
Wait 1
|
||||
|
||||
If TheTask Then
|
||||
|
||||
InPipe = Pipe PipedTask.$sInputFileName For Write
|
||||
OutPipe = Pipe PipedTask.$sOutputFileName For Read
|
||||
|
||||
Term.Piped(InPipe, OutPipe) ' tell the terminal about the remote task
|
||||
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Sub TaskStop_Click()
|
||||
|
||||
If Not Thetask Then Return
|
||||
|
||||
Term.Kill()
|
||||
|
||||
TheTask.Stop()
|
||||
|
||||
Close InPipe
|
||||
Close OutPipe
|
||||
|
||||
Thetask = Null
|
||||
InPipe = Null
|
||||
OutPipe = Null
|
||||
|
||||
End
|
||||
|
||||
Public Sub TheBestTask_Read(buffer As String)
|
||||
|
||||
DataFromTerminal.text &= "Task stdout -> " & buffer ' display from task stdout
|
||||
|
||||
End
|
||||
|
||||
Public Sub TheBestTask_kill()
|
||||
DataFromTerminal.text &= "Task Killed"
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Sub StartRs232_Click()
|
||||
|
||||
$hPipeIn = SerialPort1.Open()
|
||||
$hPipeOut = $hPipeIn()
|
||||
|
||||
If Not Term.Piped($hPipeIn, $hPipeOut) Then
|
||||
|
||||
Close $hPipeOut
|
||||
Close $hPipeIn
|
||||
$hPipeIn = Null
|
||||
$hPipeOut = Null
|
||||
|
||||
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub Stoprs232_Click()
|
||||
|
||||
KillSession_Click ' should be same as this
|
||||
|
||||
End
|
||||
|
||||
Public Sub Button2_Click()
|
||||
Dim Port As Integer
|
||||
Dim host As String
|
||||
|
||||
|
||||
$hMySock = New Socket As "Socket1"
|
||||
Port = Val(PortNumber.text)
|
||||
host = HostName.text
|
||||
|
||||
$hMySock.Connect(Host, port)
|
||||
|
||||
DataFromTerminal.text &= "Opening Socket host = " & Host & ", Port = " & Str$(Port) & "\n"
|
||||
|
||||
End
|
||||
|
||||
Public Sub Socket1_Found()
|
||||
|
||||
DataFromTerminal.text &= "Found Socket\n"
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Sub Socket1_Ready()
|
||||
|
||||
|
||||
DataFromTerminal.text &= "Ready to send receive on socket\n"
|
||||
|
||||
Term.Piped($hMySock, $hMySock)
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Sub TCPSTOP_Click()
|
||||
|
||||
If Not $hMySock Then Return
|
||||
Term.Kill
|
||||
Close #$hMySock
|
||||
$hMySock = Null
|
||||
DataFromTerminal.text &= "Closed for send receive on socket\n"
|
||||
|
||||
End
|
||||
|
||||
Public Sub Socket1_Error()
|
||||
|
||||
DataFromTerminal.text &= "Error on socket(" & Str$($hMySock.Status) & ")\n"
|
||||
$hMySock = Null
|
||||
|
||||
End
|
||||
|
||||
Public Sub Socket1_Closed()
|
||||
|
||||
DataFromTerminal.text &= "Event Closed for send receive on socket\n"
|
||||
|
||||
|
||||
End
|
75
comp/src/gb.form.terminal/.src/TerminalView/PipeTest.form
Normal file
75
comp/src/gb.form.terminal/.src/TerminalView/PipeTest.form
Normal file
|
@ -0,0 +1,75 @@
|
|||
# Gambas Form File 3.0
|
||||
|
||||
{ Form Form
|
||||
MoveScaled(0,0,147,69)
|
||||
{ Term TerminalView
|
||||
MoveScaled(2,4,58,56)
|
||||
}
|
||||
{ sndTxt Button
|
||||
MoveScaled(132,4,13,4)
|
||||
Text = ("Send data")
|
||||
}
|
||||
{ dataToSend TextBox
|
||||
MoveScaled(66,3,61,6)
|
||||
Text = ("Test Data to the terminal")
|
||||
}
|
||||
{ DataFromTerminal TextArea
|
||||
MoveScaled(66,15,65,41)
|
||||
}
|
||||
{ Label1 Label
|
||||
MoveScaled(67,11,44,4)
|
||||
Text = ("Data From Terminal")
|
||||
}
|
||||
{ KillSession Button
|
||||
MoveScaled(132,20,14,6)
|
||||
Text = ("kill Session")
|
||||
}
|
||||
{ TaskTest Button
|
||||
MoveScaled(132,27,14,6)
|
||||
Text = ("Task Testing")
|
||||
}
|
||||
{ TaskStop Button
|
||||
MoveScaled(132,33,14,5)
|
||||
Text = ("Task Stop")
|
||||
}
|
||||
{ Timer1 #Timer
|
||||
#MoveScaled(29,61)
|
||||
}
|
||||
{ SerialPort1 #SerialPort
|
||||
#MoveScaled(43,61)
|
||||
FlowControl = SerialPort.None
|
||||
PortName = "/dev/ttyS0"
|
||||
}
|
||||
{ StartSession Button
|
||||
MoveScaled(132,14,14,6)
|
||||
Text = ("Start Session")
|
||||
}
|
||||
{ StartRs232 Button
|
||||
MoveScaled(132,40,14,6)
|
||||
Text = ("Start Rs232")
|
||||
}
|
||||
{ Stoprs232 Button
|
||||
MoveScaled(132,46,14,5)
|
||||
Text = ("Stop Rs232")
|
||||
}
|
||||
{ Button2 Button
|
||||
MoveScaled(132,57,14,5)
|
||||
Text = ("TCP test")
|
||||
}
|
||||
{ Socket1 #Socket
|
||||
#MoveScaled(54,61)
|
||||
Host = "localhost"
|
||||
}
|
||||
{ TCPSTOP Button
|
||||
MoveScaled(132,62,14,5)
|
||||
Text = ("TCP Stop")
|
||||
}
|
||||
{ HostName TextBox
|
||||
MoveScaled(67,57,63,5)
|
||||
Text = ("127.0.0.1")
|
||||
}
|
||||
{ PortNumber TextBox
|
||||
MoveScaled(67,62,63,5)
|
||||
Text = ("23")
|
||||
}
|
||||
}
|
74
comp/src/gb.form.terminal/.src/TerminalView/PipedTask.class
Normal file
74
comp/src/gb.form.terminal/.src/TerminalView/PipedTask.class
Normal file
|
@ -0,0 +1,74 @@
|
|||
' Gambas class file
|
||||
|
||||
Export
|
||||
Inherits Task
|
||||
|
||||
Private $hPipeIn As File
|
||||
Private $hPipeOut As File
|
||||
|
||||
Static Public $sInputFileName As String
|
||||
Static Public $sOutputFileName As String
|
||||
|
||||
|
||||
Public Sub Main()
|
||||
Dim i As Integer = 1
|
||||
|
||||
Print "Task is up and running"
|
||||
|
||||
$hPipeOut = Pipe $sOutputFileName For Write
|
||||
|
||||
Print "Task has opened output file : " & $sOutputFileName
|
||||
Wait 2
|
||||
Print "Waited 2 Seconds"
|
||||
|
||||
$hPipeIn = Pipe $sInputFileName For Read Watch ' we should hang on this till the other side starts
|
||||
|
||||
Print "Task IO in " & $sInputFilename
|
||||
|
||||
Do
|
||||
|
||||
Wait 5
|
||||
|
||||
Print " Task Is alive " & i
|
||||
Inc i
|
||||
If $hPipeIn.EndOfFile Then
|
||||
Print " Task Pipe Closed on other end"
|
||||
Wait 1
|
||||
Break
|
||||
Endif
|
||||
|
||||
Loop
|
||||
|
||||
|
||||
End
|
||||
|
||||
Public Sub file_read()
|
||||
|
||||
Dim $sBuffer As String
|
||||
Dim $sChar As String
|
||||
|
||||
|
||||
Print "Got read message"
|
||||
|
||||
If Lof($hPipeIn) Then
|
||||
|
||||
$sBuffer = "Term Key Rx .. Echoed back ---->"
|
||||
|
||||
$sChar = Read #$hPipeIn, Lof($hPipeIn)
|
||||
|
||||
Write #$hPipeOut, $sChar
|
||||
|
||||
Print $sBuffer & $sChar
|
||||
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub _kill()
|
||||
|
||||
Print "Exit task"
|
||||
|
||||
Close #$hPipeIn
|
||||
Close #$hPipeOut
|
||||
|
||||
End
|
|
@ -16,7 +16,7 @@ Public Sub OutputTo((hView) As TerminalView, (hScreen) As TerminalScreen, (hProc
|
|||
|
||||
End
|
||||
|
||||
Public Sub InputTo((hView) As TerminalView, (hScreen) As TerminalScreen, (hProcess) As Process, (iKeyCode) As Integer, (sText) As String, Optional (bNormal) As Boolean = True, (bShift) As Boolean, (bControl) As Boolean) As Boolean
|
||||
Public Sub InputTo((hView) As TerminalView, (hScreen) As TerminalScreen, (hProcess) As Stream, (iKeyCode) As Integer, (sText) As String, Optional (bNormal) As Boolean = True, (bShift) As Boolean, (bControl) As Boolean) As Boolean
|
||||
|
||||
End
|
||||
|
||||
|
|
|
@ -632,7 +632,7 @@ NOT_IMPLEMENTED:
|
|||
|
||||
End
|
||||
|
||||
Public Sub InputTo(hView As TerminalView, hScreen As TerminalScreen, hProcess As Process, iCode As Integer, sText As String, Optional bNormal As Boolean = True, bShift As Boolean, bControl As Boolean) As Boolean
|
||||
Public Sub InputTo(hView As TerminalView, hScreen As TerminalScreen, hProcess As Stream, iCode As Integer, sText As String, Optional bNormal As Boolean = True, bShift As Boolean, bControl As Boolean) As Boolean
|
||||
|
||||
If bNormal Then
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@ Private $hMouseTimer As Timer
|
|||
Private $bTermUseMouse As Boolean
|
||||
|
||||
Private $hProcess As Process
|
||||
Private $hPipeIn As Stream ' Added this BG to support pipe io to and from the ScreenTop
|
||||
Private $hPipeOut As Stream ' added this BG to support pipe io to and from the screen
|
||||
|
||||
Private $fStart As Float
|
||||
|
||||
Private $hFilter As TerminalFilter
|
||||
|
@ -562,13 +565,25 @@ End
|
|||
Public Sub View_KeyPress()
|
||||
|
||||
'If Key.Text Then $hScreen.Print(Replace(Key.Text, "\r", "\n"))
|
||||
If Not $hProcess Then Return
|
||||
|
||||
If Not $hProcess And Not $hPipeout Then Return ' added BG to allow redirection of io
|
||||
|
||||
If $hOutputTimer.Enabled Then $hOutputTimer.Trigger
|
||||
|
||||
If $hPipeOut Then ' added BG to allow redirection of io
|
||||
|
||||
If $hFilter.InputTo(Me, $hScreen, $hPipeOut, Key.Code, Key.Text, Key.Normal, Key.Shift, Key.Control) Then
|
||||
EnsureVisible
|
||||
Stop Event
|
||||
Endif
|
||||
|
||||
Else
|
||||
|
||||
If $hFilter.InputTo(Me, $hScreen, $hProcess, Key.Code, Key.Text, Key.Normal, Key.Shift, Key.Control) Then
|
||||
EnsureVisible
|
||||
Stop Event
|
||||
If $hFilter.InputTo(Me, $hScreen, $hProcess, Key.Code, Key.Text, Key.Normal, Key.Shift, Key.Control) Then
|
||||
EnsureVisible
|
||||
Stop Event
|
||||
Endif
|
||||
|
||||
Endif
|
||||
|
||||
End
|
||||
|
@ -676,7 +691,7 @@ Public Sub Exec(Command As String[], Optional Environment As String[]) As Proces
|
|||
|
||||
Dim aEnv As String[]
|
||||
|
||||
If $hProcess Then Return
|
||||
If Not (IsNull($hProcess) Or IsNull($hPipeOut)) Then Return
|
||||
|
||||
aEnv = ["TERM=xterm"]
|
||||
If Environment Then aEnv.Insert(Environment)
|
||||
|
@ -695,7 +710,7 @@ Public Sub Shell(Command As String, Optional Environment As String[]) As Process
|
|||
|
||||
Dim aEnv As String[]
|
||||
|
||||
If $hProcess Then Return
|
||||
If Not (IsNull($hProcess) Or IsNull($hPipeOut)) Then Return
|
||||
|
||||
aEnv = ["TERM=xterm"]
|
||||
If Environment Then aEnv.Insert(Environment)
|
||||
|
@ -710,6 +725,27 @@ Public Sub Shell(Command As String, Optional Environment As String[]) As Process
|
|||
|
||||
End
|
||||
|
||||
|
||||
' allow a connection to a filter or other task
|
||||
|
||||
Public Sub Piped(PipeOut As Variant, PipeIn As Variant) As Boolean ' added BG this function to use as a piped terminal
|
||||
|
||||
|
||||
If $hProcess Then Return
|
||||
|
||||
$hPipeOut = PipeOut
|
||||
$hPipeIn = PipeIn
|
||||
|
||||
$hPipeIn.Watch(gb.Read, True)
|
||||
Object.Attach($hPipeIn, Me, "Process")
|
||||
|
||||
$fStart = Timer
|
||||
|
||||
Return True
|
||||
|
||||
End
|
||||
|
||||
|
||||
Public Sub Process_Kill()
|
||||
|
||||
If $sBuffer Then OutputTimer_Timer
|
||||
|
@ -718,12 +754,18 @@ Public Sub Process_Kill()
|
|||
|
||||
End
|
||||
|
||||
|
||||
Public Sub Process_Read()
|
||||
|
||||
Dim sData As String
|
||||
|
||||
sData = Read #$hProcess, Lof($hProcess)
|
||||
|
||||
|
||||
If $hPipeIn Then
|
||||
Read #$hPipeIn, sData, Lof($hPipeIn)
|
||||
Stop Event
|
||||
Else
|
||||
sData = Read #$hProcess, Lof($hProcess)
|
||||
Endif
|
||||
|
||||
$sBuffer &= sData
|
||||
|
||||
If Len($sBuffer) > 65536 Or If (Timer - $fStart) > 0.25 Then
|
||||
|
@ -744,7 +786,12 @@ End
|
|||
Public Sub OutputTimer_Timer()
|
||||
|
||||
$fStart = Timer
|
||||
$hFilter.OutputTo(Me, $hScreen, $hProcess, $sBuffer)
|
||||
|
||||
If $hPipeOut Then
|
||||
$hFilter.OutputTo(Me, $hScreen, $hPipeOut, $sBuffer) ' added this BG to support piped io
|
||||
Else
|
||||
If $hProcess Then $hFilter.OutputTo(Me, $hScreen, $hProcess, $sBuffer)
|
||||
Endif
|
||||
$sBuffer = ""
|
||||
$hOutputTimer.Stop
|
||||
EnsureVisible
|
||||
|
@ -792,8 +839,19 @@ End
|
|||
|
||||
Public Sub Kill()
|
||||
|
||||
Try $hProcess.Kill
|
||||
|
||||
|
||||
If $hProcess Then
|
||||
Try $hProcess.Kill
|
||||
Else ' added BG to end the piped session
|
||||
If $hPipeIn Then
|
||||
Process_Read() ' Get the last data in stream and display it
|
||||
$hPipeIn.Watch(gb.Read, False)
|
||||
|
||||
$hPipeIn = Null ' dont close the pipes its the owners problem
|
||||
$hPipeOut = Null
|
||||
Endif
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Private Function Blink_Read() As Boolean
|
||||
|
@ -830,13 +888,17 @@ Public Sub Paste()
|
|||
|
||||
Dim sText As String
|
||||
|
||||
If Not $hProcess Then Return
|
||||
If Not $hProcess Or Not $hPipeOut Then Return ' Added BG to support Pipes
|
||||
|
||||
sText = Clipboard.Paste("text/plain")
|
||||
If Not sText Then Return
|
||||
|
||||
If $hFilter.BracketedPasteActive Then sText = "\e[200~" & sText & "\e[200~"
|
||||
$hFilter.InputTo(Me, $hScreen, $hProcess, 0, sText)
|
||||
If $hPipeOut Then
|
||||
$hFilter.InputTo(Me, $hScreen, $hPipeOut, 0, sText)
|
||||
Else
|
||||
$hFilter.InputTo(Me, $hScreen, $hProcess, 0, sText)
|
||||
Endif
|
||||
EnsureVisible
|
||||
|
||||
End
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FTestTerminalView
|
||||
PipeTest
|
||||
Gambas Terminal control
|
||||
0
|
||||
0
|
||||
|
@ -7,4 +7,5 @@ Gambas Terminal control
|
|||
gb.image
|
||||
gb.gui
|
||||
gb.form
|
||||
gb.net
|
||||
|
||||
|
|
Loading…
Reference in a new issue