Merge pull request #26 from phranck/refactor/eliminate-terminal-singleton

Refactor: Eliminate Terminal singleton
This commit is contained in:
phranck
2026-01-30 23:21:45 +01:00
4 changed files with 6 additions and 9 deletions
+2 -2
View File
@@ -74,7 +74,7 @@ internal final class AppRunner<A: App> {
init(app: A) {
self.app = app
self.terminal = Terminal.shared
self.terminal = Terminal()
self.statusBar = StatusBarState()
self.focusManager = FocusManager()
self.tuiContext = TUIContext()
@@ -203,7 +203,7 @@ internal protocol SceneRenderable {
extension WindowGroup: SceneRenderable {
func renderScene(context: RenderContext) {
let buffer = renderToBuffer(content, context: context)
let terminal = Terminal.shared
let terminal = context.terminal
let terminalWidth = terminal.width
let terminalHeight = context.availableHeight
+1 -1
View File
@@ -91,7 +91,7 @@ public struct RenderContext {
/// - environment: The environment values (defaults to empty).
/// - tuiContext: The TUI context (defaults to a fresh instance).
public init(
terminal: Terminal = .shared,
terminal: Terminal = Terminal(),
availableWidth: Int? = nil,
availableHeight: Int? = nil,
environment: EnvironmentValues = EnvironmentValues(),
+2 -5
View File
@@ -32,9 +32,6 @@ import Foundation
/// - Raw mode configuration
/// - Safe input and output
public final class Terminal: @unchecked Sendable {
/// The shared terminal instance.
public static let shared = Terminal()
/// The width of the terminal in characters.
public var width: Int {
getSize().width
@@ -51,8 +48,8 @@ public final class Terminal: @unchecked Sendable {
/// The original terminal settings.
private var originalTermios: termios?
/// Private initializer for singleton.
private init() {}
/// Creates a new terminal instance.
public init() {}
/// Destructor ensures raw mode is disabled.
deinit {
+1 -1
View File
@@ -30,7 +30,7 @@ public final class ViewRenderer {
/// Creates a new ViewRenderer.
///
/// - Parameter terminal: The target terminal.
public init(terminal: Terminal = .shared) {
public init(terminal: Terminal = Terminal()) {
self.terminal = terminal
}