#Source of ptyCommunication.png
title PTY Communication

Document Terminal->PTY Service: wants new PTY
note over PTY Service,PTY Host Service: gRPC communication
PTY Service->PTY Host Service: createPtyProcess(options)
PTY Host Service->PTY Process: new PtyProcess()
PTY Host Service->PTY Service: ptyId of the process is returned
PTY Service->PTY Host Service: establish exchangeEvents(ptyId) channel
note left of PTY Service:
client has been created,
so PTY Service can attach event handlers
to the channel (onData/onOpen/onExit)
end note
PTY Service->Document Terminal: pty process object
Document Terminal->PTY Service: start()
PTY Service->PTY Host Service: exchangeEvents.start()
note right of PTY Host Service:
exchangeEvents attaches event handlers
to the PTY Process (onData/onOpen/onExit)
end note
PTY Host Service->PTY Process: start()

PTY Process->PTY Host Service: onOpen()
PTY Host Service->PTY Service: exchangeEvents.onOpen()
PTY Service->Document Terminal: onOpen()

Document Terminal->PTY Service: dispose()
PTY Service->PTY Host Service: end exchangeEvents channel
PTY Host Service->PTY Process: dispose process and remove it
