Terminal
open class Terminal
The Terminal class provides the terminal emulation engine, and can be used to feed data to the
terminal emulator. Typically users will intereact with a higher-level implementation that provides a
UI toolkit-specific rendering and connects the input to the UI toolkit.
A front-end would draw the contents of the terminal, and take input from the user, which is in turn
either mapped to one of the public APIs here, or if it is user input is passed to the feed methods here.
The terminal is also connected to a backend that is conneted to the client, and data from this
client is fed into the emulator by calling the sendResponse method
The behavior of the terminal is configured by implementing the TerminalDelegate protocol
that is provided in the constructor call.
-
The current terminal columns (counting from 1)
Declaration
Swift
public private(set) var cols: Int { get } -
The current terminal rows (counting from 1)
Declaration
Swift
public private(set) var rows: Int { get } -
This variable if set, contains an URI representing the host and directory of the process running in the terminal it is often used by applciations to track the working directory. It might be nil, or might not be correct, the contents are entirely under the control of the remote application, and require the terminal to be trusted (see the
isProcessTrustedmethod in theTerminalDelegate). When this is set thehostCurrentDirectoryUpdatedmethod on the delegate is invoked.Declaration
Swift
public private(set) var hostCurrentDirectory: String? { get } -
Represents the mouse operation mode that the terminal is currently using and higher level implementations should use the functions in this enumeration to determine what events to send
See moreDeclaration
Swift
public enum MouseMode -
Undocumented
Declaration
Swift
public private(set) var mouseMode: MouseMode { get set } -
Undocumented
Declaration
Swift
public func getDims() -> (cols: Int, rows: Int) -
Undocumented
Declaration
Swift
public init(delegate: TerminalDelegate, options: TerminalOptions = TerminalOptions.default) -
Returns the character at the specified column and row, these are zero-based
Declaration
Swift
public func getCharacter(col: Int, row: Int) -> Character?Parameters
colcolumn to retrieve, starts at 0
rowrow to retrieve, starts at 0
Return Value
nil if the col or row are out of bounds, or the Character contained in that cell otherwise
-
Commands send to the
See morewindowCommanddelegate for the front-end to implement capabilities on behalf of the client. The expected return strings in some of these enumeration values is documented below. Returns are only expected for the enum values that start with the prefixreportDeclaration
Swift
public enum WindowManipulationCommand -
Performs a terminal soft-reset, the equivalent of the DECSTR sequence For a full reset see
resetToInitialStateDeclaration
Swift
public func softReset() -
Sends the provided text to the connected backend
Declaration
Swift
public func sendResponse(text: String) -
Undocumented
Declaration
Swift
public func sendResponse(_ items: Any...) -
Undocumented
Declaration
Swift
public var silentLog: Bool -
Undocumented
Declaration
Swift
public func error(_ text: String) -
Undocumented
Declaration
Swift
public func log(_ text: String) -
Processes the provided byte-array coming from the backend
Declaration
Swift
public func feed(byteArray: [UInt8]) -
Undocumented
Declaration
Swift
public func feed(text: String) -
Undocumented
Declaration
Swift
public func feed(buffer: ArraySlice<UInt8>) -
Undocumented
Declaration
Swift
public func parse(buffer: ArraySlice<UInt8>) -
Undocumented
Declaration
Swift
public func updateFullScreen() -
Returns the starting and ending lines that need to be redrawn, or nil if no part of the screen needs to be updated.
Declaration
Swift
public func getUpdateRange() -> (startY: Int, endY: Int)? -
Clears the state of the pending display redraw region.
Declaration
Swift
public func clearUpdateRange() -
This performs a full reset of the terminal, like a soft reset, but additionally resets the buffer conents and scroll area. for a soft reset see
softResetDeclaration
Swift
public func resetToInitialState() -
Undocumented
Declaration
Swift
public func scroll(isWrapped: Bool = false) -
Undocumented
Declaration
Swift
public func emitLineFeed() -
Undocumented
Declaration
Swift
public func resize(cols: Int, rows: Int) -
Registers that the region between startRow and endRow was modified and needs to be updated by the
Declaration
Swift
public func refresh(startRow: Int, endRow: Int) -
Undocumented
Declaration
Swift
public func showCursor() -
Encodes the button action in the format expected by the client
Declaration
Swift
public func encodeButton(button: Int, release: Bool, shift: Bool, meta: Bool, control: Bool) -> IntParameters
buttonThe button to encode
releasetrueif this is a mouse release eventshifttrueif the shift key is pressedmetatrueif the meta/alt key is pressedcontroltrueif the control key is pressedReturn Value
the encoded value
-
Sends a mouse event for a specific button at the specific location
Declaration
Swift
public func sendEvent(buttonFlags: Int, x: Int, y: Int)Parameters
buttonFlagsButton flags encoded in Cb mode.
xX coordinate for the event
yY coordinate for the event
-
Sends a mouse motion event for a specific button at the specific location
Declaration
Swift
public func sendMotion(buttonFlags: Int, x: Int, y: Int)Parameters
buttonFlagsButton flags encoded in Cb mode.
xX coordinate for the event
yY coordinate for the event
-
Undocumented
Declaration
Swift
public func setTitle(text: String) -
Undocumented
Declaration
Swift
public func setIconTitle(text: String) -
Provides a baseline set of environment variables that would be useful to run the terminal, you can customzie these accordingly.
Declaration
Swift
public static func getEnvironmentVariables(termName: String? = nil) -> [String]Return Value
View on GitHub
Install in Dash
Terminal Class Reference