Bring back the terminal backend to life.#210
Bring back the terminal backend to life.#210migueldeicaza wants to merge 1 commit intomoreSwift:mainfrom
Conversation
It renames 'CursesBackend' to TermKit, as now TermKit has various console drivers, and curses is just one of them. The challenge is that TermKit deals with screen sizes like 80x24, not things like 600x400, so both the default sizes and spacing in the codebase will need to compensate for that. The AppBackend introduces a defaultStackSpacingAmount which is the spacing that VStack and HStack would use, it is currently kept as a default to the existing value, but for the TermKit backend, this value is set to zero. Now HStack and VStack rather than storing a resolved value like 'spacing: Int', they store the request 'spacing: Int?', which is resolved before it is actually needed by querying the backend for this data. There is also a new 'limitScreenBounds' that is a no-op for most, but on the curses cases, ensures that a misuse of the defaultSize does not trickle up and down the stack with unrealistic view sizes.
stackotter
left a comment
There was a problem hiding this comment.
Just had a quick look out of interest and left a few comments (mostly formatting related). I'll change this PR to a draft for now
| // name: "CursesBackend", | ||
| // dependencies: ["SwiftCrossUI", "TermKit"] | ||
| // ), | ||
| .target( |
There was a problem hiding this comment.
Fix indentation (and for the TermKit package above and TermKitBackend product above that)
| // ), | ||
| .target( | ||
| name: "TermKitBackend", | ||
| dependencies: ["SwiftCrossUI", .product(name: "TermKit", package: "TermKit")] |
There was a problem hiding this comment.
Use "TermKit" spelling instead of .product(name: "TermKit", package: "TermKit")
| todo() | ||
| } | ||
|
|
||
| public func limitScreenBounds(_ bounds: SIMD2<Int>) -> SIMD2<Int> { |
There was a problem hiding this comment.
I feel like this should be reworked to func clampWindowSize(_ size: SIMD2<Int>, for window: Window) -> SIMD2<Int>. Renamed for clarity, and extra parameter added for future proofing (future purposes could want the window in question to access properties such as scaling factors).
| proposedWindowSize: isFirstUpdate && isProgramaticallyResizable | ||
| ? (newScene ?? scene).defaultSize | ||
| : backend.size(ofWindow: window), | ||
| ? backend.limitScreenBounds((newScene ?? scene).defaultSize) |
There was a problem hiding this comment.
Indent these two hanging lines
| } | ||
|
|
||
| public func runInMainThread(action: @escaping @MainActor () -> Void) { | ||
| #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) |
There was a problem hiding this comment.
Indent this body two levels
It renames 'CursesBackend' to TermKit, as now TermKit has various console drivers, and curses is just one of them.
The challenge is that TermKit deals with screen sizes like 80x24, not things like 600x400, so both the default sizes and spacing in the codebase will need to compensate for that.
The AppBackend introduces a defaultStackSpacingAmount which is the spacing that VStack and HStack would use, it is currently kept as a default to the existing value, but for the TermKit backend, this value is set to zero.
Now HStack and VStack rather than storing a resolved value like 'spacing: Int', they store the request 'spacing: Int?', which is resolved before it is actually needed by querying the backend for this data.
There is also a new 'limitScreenBounds' that is a no-op for most, but on the curses cases, ensures that a misuse of the defaultSize does not trickle up and down the stack with unrealistic view sizes.