@@ -71,7 +71,7 @@ class TerminalHostingView: UIHostingView<AnyView> {
7171}
7272
7373struct TerminalSampleView : View {
74- fileprivate class TerminalSampleViewDelegate : NSObject , TerminalDelegate {
74+ private class TerminalSampleViewDelegate : NSObject , TerminalDelegate {
7575 func send( source: Terminal , data: ArraySlice < UInt8 > ) { }
7676 }
7777
@@ -83,6 +83,9 @@ struct TerminalSampleView: View {
8383 private let delegate = TerminalSampleViewDelegate ( )
8484 private let state = TerminalState ( )
8585
86+ private let timer = Timer . publish ( every: 1 , on: . main, in: . common)
87+ . autoconnect ( )
88+
8689 init ( fontMetrics: FontMetrics = FontMetrics ( font: AppFont ( ) , fontSize: 12 ) ,
8790 colorMap: ColorMap = ColorMap ( theme: AppTheme ( ) ) ) {
8891 self . fontMetrics = fontMetrics
@@ -103,6 +106,10 @@ struct TerminalSampleView: View {
103106 var body : some View {
104107 TerminalView ( )
105108 . environmentObject ( state)
109+ . onAppear {
110+ stringSupplier. colorMap = colorMap
111+ stringSupplier. fontMetrics = fontMetrics
112+ }
106113 . onChange ( of: colorMap, perform: { stringSupplier. colorMap = $0 } )
107114 . onChange ( of: fontMetrics, perform: { stringSupplier. fontMetrics = $0 } )
108115 . onChangeOfFrame ( perform: { size in
@@ -112,9 +119,9 @@ struct TerminalSampleView: View {
112119 terminal. resize ( cols: Int ( size. width / glyphSize. width) ,
113120 rows: 32 )
114121 } )
115- . onAppear {
116- stringSupplier . colorMap = colorMap
117- stringSupplier. fontMetrics = fontMetrics
122+ . onReceive ( timer ) { _ in
123+ state . lines = Array ( 0 ... ( terminal . rows + terminal . getTopVisibleRow ( ) ) )
124+ . map { stringSupplier. attributedString ( forScrollInvariantRow : $0 ) }
118125 }
119126 }
120127}
@@ -123,6 +130,5 @@ struct TerminalView_Previews: PreviewProvider {
123130 static var previews : some View {
124131 TerminalSampleView ( )
125132 . preferredColorScheme ( . dark)
126- . previewLayout ( . fixed( width: 640 , height: 480 ) )
127133 }
128134}
0 commit comments