Skip to content

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.

Declaration
[AddComponentMenu("Terminal/Terminal Session")]
[DisallowMultipleComponent]
[Icon("Packages/com.darkeffekt.terminal/Editor/Icons/Assets/TerminalSession.png")]
public sealed class TerminalSession : MonoBehaviour

Inheritance: System.Object -> UnityEngine.Object -> UnityEngine.Component -> UnityEngine.Behaviour -> UnityEngine.MonoBehaviour

The terminal itself. Available before Awake, so a connection can be set from another component’s Awake.

Declaration
public TerminalEmulator Emulator { get; }

Draws the emulator into its texture. Null until Awake, and when the package’s shaders are missing.

Declaration
public TerminalRenderer Renderer { get; }
Declaration
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.

Declaration
public TerminalTheme Theme { get; set; }

The cell size in pixels this session renders at. Starts at the theme’s font size; SetFontSize changes it.

Declaration
public int FontSize { get; }

Read the keyboard while focused. Off keeps focus but sends nothing typed.

Declaration
public bool AcceptsKeyboard { get; set; }

Clicking anywhere off this session’s screens takes focus away from it.

Declaration
public bool ReleaseFocusOnOutsideClick { get; set; }

Write a line into the terminal when the connection closes.

Declaration
public bool PrintCloseReason { get; set; }

The session receiving keyboard input, or null.

Declaration
public static TerminalSession Focused { get; }
Declaration
public bool HasFocus { get; }

The surface program on screen, or null while the terminal shows.

Declaration
public ISurfaceProgram SurfaceProgram { get; }

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.

Declaration
public void SetFontSize(int pixels)
Type Name
System.Int32 pixels

Recreates the renderer at the session’s font size, for a font change on the theme.

Declaration
public void RebuildRenderer()

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.

Declaration
public void RunSurface(ISurfaceProgram program)
Type Name
DarkEffekt.Terminal.ISurfaceProgram program

Ends the surface program, if one is running, and shows the terminal again.

Declaration
public void ExitSurface()

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.

Declaration
public void BindTexture(string slot, Texture texture)
Type Name
System.String slot
UnityEngine.Texture texture

Attach and open a connection. An existing one is disposed.

Declaration
public void SetConnection(ITerminalConnection connection)
Type Name
DarkEffekt.Terminal.ITerminalConnection connection

Gives this session keyboard focus.

Declaration
public void Focus()

Takes keyboard focus away from this session, if it has it.

Declaration
public void Blur()

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.

Declaration
public void SkipKeyboardThisFrame()
Declaration
public void SetSize(int cols, int newRows)
Type Name
System.Int32 cols
System.Int32 newRows
Declaration
public void Send(byte[] data)
Type Name
System.Byte[] data
Declaration
public void SendText(string text)
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.

Declaration
public void SendMouse(TermMouseButton button, bool press, bool motion, int col, int row, TermModifiers mods)
Type Name
DarkEffekt.Terminal.TermMouseButton button
System.Boolean press
System.Boolean motion
System.Int32 col
System.Int32 row
DarkEffekt.Terminal.TermModifiers mods

Raised when focus moves, with the newly focused session or null.

Declaration
public static event Action<TerminalSession> FocusChanged

System.Action<DarkEffekt.Terminal.Unity.TerminalSession>

Raised on the main thread when the connection opens.

Declaration
public event Action ConnectionOpened

System.Action

Raised on the main thread when the connection closes or a connect fails.

Declaration
public event Action<CloseReason> ConnectionClosed

System.Action<DarkEffekt.Terminal.CloseReason>

Raised when a surface program ends and the terminal returns.

Declaration
public event Action SurfaceClosed

System.Action