eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'TerminalSession':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: TerminalSession


Inheritance:

   Object
   |
   +--TerminalSession

Package:
stx:libbasic2
Category:
Views-TerminalViews
Version:
rev: 1.48 date: 2019/08/08 13:17:47
user: alkurz
file: TerminalSession.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


This is basically a TerminalView without a view.

This keeps the state and API to interact with another program
via a terminal session. Under Unix, a pseudo-tty connection
is used; other operating systems might use other mechanisms.

This is (currently) used by the GDBApplication, to interact
with gdb, cscope and the program.
It can be used wherever more control is needed than a simple pipe
offers (such as terminal emulation, window size, CTRL-c support etc.)

A major feature is a mechanism to catch certain prompt strings of the output
and get a notification.
This is very useful, if a program's output is to be shown both in a terminalview,
and also to be analyzed for robot actions.
Applications for this are telnet like interaction, interactions with a debugger
or monitor (gdb, android-adb) etc.,

A lot of code has been extracted from TerminalView, 
which will be refactored, once this is stable. 
For now, there is some code duplication (as of Summer 2014).

outStream   - the controlled program's output (a pty-half)
inStream    - the controlled program's input (a pty-half)
errStream   - the controlled program's output (a pty-half)


Class protocol:

initialization
o  initialize
self initialize
Debug := true.


Instance protocol:

accessing
o  errStream
the stdErrToStx stream.
Stuff written by the process' to its stderr will appear here

o  inStream
the stxTostdIn stream.
Stuff written to this stream will appear at the process' stdin

o  outStream
the process' stdOutToStx stream.
Stuff written by the process to its stdout will appear here

o  pluggableCheckBeforeReadAction: aBlockOrNil

o  pluggableProcessInputAction: aBlockOrNil

o  pty

o  ptyName

o  shellCommand

o  shellDirectory

o  shellPid

o  terminatedAction: aBlock
hook to be called when terminated

initialization & release
o  closeDownShell
shut down my shell process

o  closeDownShell: waitTimeInSeconds
shut down my shell process

o  closeDownShellAndStopReaderProcess
shut down my shell process, stop the background reader thread
and close the streams

o  closeStreams

o  createTerminalConnectionAndSetupWith: setupBlock
create a terminal connection (pseudo terminal or pipe)

o  reinitialize

o  startCommand: aCommand in: aDirectory environment: envIn setupTerminalWith: setupBlock terminatedAction: terminatedActionArg
start a command on a pseudo terminal.
If the command arg is nil, a shell is started.
If aDirectory is nil, the command is executed in the current directory.
Also fork a reader process, to read the shell's output
and tell me, whenever something arrives

input / output
o  paste: someText
paste - redefined to send the chars to the shell instead
of pasting into the view

o  send: aString

o  sendCharacter: aCharacter

o  sendLine: aString

o  sendLineEnd

misc
o  collectedOutput
return any collected output, so far

o  defineWindowSizeLines: numberOfLines columns: numberOfColumns
any idea, how to do this under windows ?

o  forgetPrompt: aString
Transcript show:'forget prompt: '; showCR:aString.

o  onPrompt: aString do: aBlock
remember what to do, when a prompt arrives;
notice: will only start checking for prompt, when startCollectingOutput
has been called.

o  onPrompt: string1 do: block1 onPrompt: string2 do: block2
remember what to do, when a prompt arrives;
notice: will only start checking for prompt, when startCollectingOutput
has been called.

o  outputFromAction: aBlock prompt: prompt timeout: seconds
evaluate aBlock and wait for the prompt.
return gdb output as string collection

o  outputFromAction: aBlock prompt: prompt timeout: seconds to: aStreamOrNil
evaluate aBlock and wait for the prompt.
return gdb output as string collection

o  outputFromCommand: aCommand prompt: prompt timeout: seconds
return a command's output as string collection

o  outputFromCommand: aCommand prompt: prompt timeout: seconds to: aStreamOrNil
return a command's output as string collection

o  sendInterruptSignal
send an INT-signal to the shell (UNIX only)

o  sendKillSignal
send a KILL-signal to the shell (UNIX only)

o  startCollectingOutput
start collecting output in a collecting stream

o  startCollectingOutputTo: aStream
start collecting output into a collecting (or other) stream

o  stopCollectingOutput
start collecting output in a collecting stream

queries
o  isOpen

reader process
o  collectOutputAndCheckForPrompt: buffer count: n
Transcript showCR:'prompts: '; showCR:promptActions.

o  readAnyAvailableData
read data from the stream,
and sends me #processInput:n: events if something arrived.
Returns the amount of data read.

o  readerProcessLoop
look for the session's output

o  startReaderProcess
Start a reader process, which looks for the commands output,
and sends me #processInput:n: events whenever something arrives.

o  stopReaderProcess
stop the background reader thread


Examples:


|session| session := TerminalSession new. session startReaderProcess. session pluggableProcessInputAction:[:buffer :n | Transcript show:(buffer copyTo:n). Transcript endEntry. ]. session startCommand:'ls -l' in:'~' environment:nil setupTerminalWith:[] terminatedAction:[ Transcript showCR:'finished' ]. session startCommand:'(cd ~/work/cg/schemeNew ; make)' in:'~' environment:nil setupTerminalWith:[] terminatedAction:[ Transcript showCR:'finished' ]. session startCommand:'(ls ~/work/cg/schemeNew)' in:'~' environment:nil setupTerminalWith:[] terminatedAction:[ Transcript showCR:'finished' ].

ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Tue, 16 Apr 2024 08:43:35 GMT