mirror of
https://github.com/phranck/TUIkit.git
synced 2026-06-20 09:54:37 +00:00
Merge pull request #26 from phranck/refactor/eliminate-terminal-singleton
Refactor: Eliminate Terminal singleton
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user