Skip to content

Commit

Permalink
[app] Really badly make sample view work for now
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Dec 27, 2022
1 parent 66c4902 commit 91fcda6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions App/UI/Terminal/TerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TerminalHostingView: UIHostingView<AnyView> {
}

struct TerminalSampleView: View {
fileprivate class TerminalSampleViewDelegate: NSObject, TerminalDelegate {
private class TerminalSampleViewDelegate: NSObject, TerminalDelegate {
func send(source: Terminal, data: ArraySlice<UInt8>) {}
}

Expand All @@ -83,6 +83,9 @@ struct TerminalSampleView: View {
private let delegate = TerminalSampleViewDelegate()
private let state = TerminalState()

private let timer = Timer.publish(every: 1, on: .main, in: .common)
.autoconnect()

init(fontMetrics: FontMetrics = FontMetrics(font: AppFont(), fontSize: 12),
colorMap: ColorMap = ColorMap(theme: AppTheme())) {
self.fontMetrics = fontMetrics
Expand All @@ -103,6 +106,10 @@ struct TerminalSampleView: View {
var body: some View {
TerminalView()
.environmentObject(state)
.onAppear {
stringSupplier.colorMap = colorMap
stringSupplier.fontMetrics = fontMetrics
}
.onChange(of: colorMap, perform: { stringSupplier.colorMap = $0 })
.onChange(of: fontMetrics, perform: { stringSupplier.fontMetrics = $0 })
.onChangeOfFrame(perform: { size in
Expand All @@ -112,9 +119,9 @@ struct TerminalSampleView: View {
terminal.resize(cols: Int(size.width / glyphSize.width),
rows: 32)
})
.onAppear {
stringSupplier.colorMap = colorMap
stringSupplier.fontMetrics = fontMetrics
.onReceive(timer) { _ in
state.lines = Array(0...(terminal.rows + terminal.getTopVisibleRow()))
.map { stringSupplier.attributedString(forScrollInvariantRow: $0) }
}
}
}
Expand All @@ -123,6 +130,5 @@ struct TerminalView_Previews: PreviewProvider {
static var previews: some View {
TerminalSampleView()
.preferredColorScheme(.dark)
.previewLayout(.fixed(width: 640, height: 480))
}
}

0 comments on commit 91fcda6

Please sign in to comment.