Class TerminalSession
The center of a terminal: one emulator, one connection, one offscreen renderer. Any number of screens present its texture; input routes here from whichever screen has focus. Connection callbacks arrive on worker threads and are queued to the main thread.
Keyboard input goes to the focused session only, read from the Input System. Clicking a screen focuses its session. Focus moves only when told to, unless releaseFocusOnOutsideClick is on; AcceptsKeyboard turns typing off without losing focus, and while a uGUI or TextMeshPro input field is selected the session leaves the keyboard to it.
Assembly: DarkEffekt.Terminal
Section titled “Assembly: DarkEffekt.Terminal”[AddComponentMenu("Terminal/Terminal Session")][DisallowMultipleComponent][Icon("Packages/com.darkeffekt.terminal/Editor/Icons/Assets/TerminalSession.png")]public sealed class TerminalSession : MonoBehaviourInheritance: System.Object -> UnityEngine.Object -> UnityEngine.Component -> UnityEngine.Behaviour -> UnityEngine.MonoBehaviour
Properties
Section titled “Properties”Emulator
Section titled “Emulator”The terminal itself. Available before Awake, so a connection can be set from another component’s Awake.
public TerminalEmulator Emulator { get; }Renderer
Section titled “Renderer”Draws the emulator into its texture. Null until Awake, and when the package’s shaders are missing.
public TerminalRenderer Renderer { get; }Connection
Section titled “Connection”public ITerminalConnection Connection { get; }The font, colors, and cursor this session draws with. Setting it during play rebuilds the renderer at the session’s font size.
public TerminalTheme Theme { get; set; }FontSize
Section titled “FontSize”The cell size in pixels this session renders at. Starts at the theme’s font size; SetFontSize changes it.
public int FontSize { get; }AcceptsKeyboard
Section titled “AcceptsKeyboard”Read the keyboard while focused. Off keeps focus but sends nothing typed.
public bool AcceptsKeyboard { get; set; }ReleaseFocusOnOutsideClick
Section titled “ReleaseFocusOnOutsideClick”Clicking anywhere off this session’s screens takes focus away from it.
public bool ReleaseFocusOnOutsideClick { get; set; }PrintCloseReason
Section titled “PrintCloseReason”Write a line into the terminal when the connection closes.
public bool PrintCloseReason { get; set; }Focused
Section titled “Focused”The session receiving keyboard input, or null.
public static TerminalSession Focused { get; }HasFocus
Section titled “HasFocus”public bool HasFocus { get; }SurfaceProgram
Section titled “SurfaceProgram”The surface program on screen, or null while the terminal shows.
public ISurfaceProgram SurfaceProgram { get; }Methods
Section titled “Methods”SetFontSize(int)
Section titled “SetFontSize(int)”Sets the cell pixel size, and so the render resolution, for this session. It rebuilds the renderer and its target; the grid (columns and rows) and the theme asset are unaffected.
public void SetFontSize(int pixels)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
System.Int32 |
pixels |
RebuildRenderer()
Section titled “RebuildRenderer()”Recreates the renderer at the session’s font size, for a font change on the theme.
public void RebuildRenderer()RunSurface(ISurfaceProgram)
Section titled “RunSurface(ISurfaceProgram)”Hands the screen to a program that draws cells directly, with no escape parsing: the fast path for a full-screen interface that animates. The terminal and its connection keep running underneath and return when the program exits. While it runs, the keyboard and the pointer go to the program as events when it implements DarkEffekt.Terminal.ITerminalInput, and selection and scrollback are off.
public void RunSurface(ISurfaceProgram program)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
| DarkEffekt.Terminal.ISurfaceProgram | program |
ExitSurface()
Section titled “ExitSurface()”Ends the surface program, if one is running, and shows the terminal again.
public void ExitSurface()BindTexture(string, Texture)
Section titled “BindTexture(string, Texture)”Shows a texture in the region a surface program reserves under this name, as a DarkEffekt.Terminal.UI.TextureView does. The texture draws under the text of those cells and is treated as live. Null removes it.
public void BindTexture(string slot, Texture texture)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
System.String |
slot |
UnityEngine.Texture |
texture |
SetConnection(ITerminalConnection)
Section titled “SetConnection(ITerminalConnection)”Attach and open a connection. An existing one is disposed.
public void SetConnection(ITerminalConnection connection)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
| DarkEffekt.Terminal.ITerminalConnection | connection |
Focus()
Section titled “Focus()”Gives this session keyboard focus.
public void Focus()Blur()
Section titled “Blur()”Takes keyboard focus away from this session, if it has it.
public void Blur()SkipKeyboardThisFrame()
Section titled “SkipKeyboardThisFrame()”Keeps this frame’s key presses from the terminal, for a key your own code has just used. Call it before the session’s Update: from a script with an earlier execution order.
public void SkipKeyboardThisFrame()SetSize(int, int)
Section titled “SetSize(int, int)”public void SetSize(int cols, int newRows)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
System.Int32 |
cols |
System.Int32 |
newRows |
Send(byte[])
Section titled “Send(byte[])”public void Send(byte[] data)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
System.Byte[] |
data |
SendText(string)
Section titled “SendText(string)”public void SendText(string text)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
System.String |
text |
SendMouse(TermMouseButton, bool, bool, int, int, TermModifiers)
Section titled “SendMouse(TermMouseButton, bool, bool, int, int, TermModifiers)”A pointer event from a screen, in cell coordinates. It goes to the surface program while one runs. Otherwise it reports to the host when mouse tracking is on, and scrolls history on the wheel when it is off.
public void SendMouse(TermMouseButton button, bool press, bool motion, int col, int row, TermModifiers mods)Parameters
Section titled “Parameters”| Type | Name |
|---|---|
| DarkEffekt.Terminal.TermMouseButton | button |
System.Boolean |
press |
System.Boolean |
motion |
System.Int32 |
col |
System.Int32 |
row |
| DarkEffekt.Terminal.TermModifiers | mods |
Events
Section titled “Events”FocusChanged
Section titled “FocusChanged”Raised when focus moves, with the newly focused session or null.
public static event Action<TerminalSession> FocusChangedEvent Type
Section titled “Event Type”System.Action<DarkEffekt.Terminal.Unity.TerminalSession>
ConnectionOpened
Section titled “ConnectionOpened”Raised on the main thread when the connection opens.
public event Action ConnectionOpenedEvent Type
Section titled “Event Type”System.Action
ConnectionClosed
Section titled “ConnectionClosed”Raised on the main thread when the connection closes or a connect fails.
public event Action<CloseReason> ConnectionClosedEvent Type
Section titled “Event Type”System.Action<DarkEffekt.Terminal.CloseReason>
SurfaceClosed
Section titled “SurfaceClosed”Raised when a surface program ends and the terminal returns.
public event Action SurfaceClosedEvent Type
Section titled “Event Type”System.Action