1 /** 2 * Tty module for dcell defines the interface that platforms must implement 3 * for exchanging data for display, and key strokes and other events, between 4 * the specific terminal / pty subsystem, and the VT common core. 5 * 6 * Copyright: Copyright 2025 Garrett D'Amore 7 * Authors: Garrett D'Amore 8 * License: 9 * Distributed under the Boost Software License, Version 1.0. 10 * (See accompanying file LICENSE or https://www.boost.org/LICENSE_1_0.txt) 11 * SPDX-License-Identifier: BSL-1.0 12 */ 13 module dcell.tty; 14 15 import std.datetime; 16 import dcell.coord; 17 18 /** 19 * Tty is the interface that implementations should 20 * override or supply to support terminal I/O ioctls or 21 * equivalent functionality. It is provided in this form, as 22 * some implementations may not be based on actual tty devices. 23 */ 24 interface Tty 25 { 26 /** 27 * Save current tty settings. These can be subsequently 28 * restored using restore. 29 */ 30 void save() @trusted; 31 32 /** 33 * Restore tty settings saved with save(). 34 */ 35 void restore() @trusted; 36 37 /** 38 * Make the terminal suitable for raw mode input. 39 * In this mode the terminal is not suitable for 40 * typical interactive shell use, but is good if absolute 41 * control over input is needed. After this, reads 42 * will block until one character is presented. (Same 43 * effect as 'blocking(true)'. 44 */ 45 void raw() @trusted; 46 47 /** 48 * Read input. May return an empty slice if no data 49 * is present and blocking is disabled. 50 */ 51 string read(Duration dur = Duration.zero) @trusted; 52 53 /** 54 * Write output. 55 */ 56 void write(string s) @trusted; 57 58 /** 59 * Flush output. 60 */ 61 void flush() @trusted; 62 63 /** 64 * Get window size. 65 */ 66 Coord windowSize() @trusted; 67 68 /** 69 * Stop input scanning. 70 */ 71 void stop() @trusted; 72 73 /** 74 * Close the tty device. 75 */ 76 void close() @trusted; 77 78 /** 79 * Start termio. This will open the device. 80 */ 81 void start() @trusted; 82 83 /** 84 * Resized returns true if the window was resized since last checked. 85 * Normally resize will force the window into non-blocking mode so 86 * that the caller can see the resize in a timely fashion. 87 * This is edge triggered (reading it will clear the value.) 88 */ 89 bool resized() nothrow @nogc @safe; 90 91 /** 92 * Wake up any reader blocked in read(). 93 */ 94 void wakeUp() nothrow @trusted; 95 }