@@ -28,18 +28,26 @@ enum TerminalTestHarness {
2828 return ( terminal, delegate)
2929 }
3030
31- static func visibleLinesText( buffer: Buffer , trimRight: Bool = true ) -> [ String ] {
31+ static func visibleLinesText( buffer: Buffer , terminal : Terminal ? = nil , trimRight: Bool = true ) -> [ String ] {
3232 let start = buffer. yDisp
3333 let end = min ( buffer. yDisp + buffer. rows, buffer. lines. count)
3434 guard start < end else { return [ ] }
35- return ( start..< end) . map { bufferLineText ( buffer: buffer, lineIndex: $0, trimRight: trimRight) }
35+ let characterProvider = makeCharacterProvider ( terminal)
36+ return ( start..< end) . map {
37+ bufferLineText ( buffer: buffer, lineIndex: $0, trimRight: trimRight, characterProvider: characterProvider)
38+ }
3639 }
3740
38- static func lineText( buffer: Buffer , row: Int , trimRight: Bool = true ) -> String ? {
41+ static func lineText( buffer: Buffer , terminal : Terminal ? = nil , row: Int , trimRight: Bool = true ) -> String ? {
3942 guard row >= 0 , row < buffer. rows else { return nil }
4043 let index = buffer. yDisp + row
4144 guard index >= 0 , index < buffer. lines. count else { return nil }
42- return bufferLineText ( buffer: buffer, lineIndex: index, trimRight: trimRight)
45+ return bufferLineText (
46+ buffer: buffer,
47+ lineIndex: index,
48+ trimRight: trimRight,
49+ characterProvider: makeCharacterProvider ( terminal)
50+ )
4351 }
4452
4553 static func charData( buffer: Buffer , row: Int , col: Int ) -> CharData ? {
@@ -65,18 +73,29 @@ enum TerminalTestHarness {
6573 #expect( buffer. y == row)
6674 }
6775
68- static func assertLineText( _ buffer: Buffer , row: Int , equals expected: String ) {
69- let actual = lineText ( buffer: buffer, row: row) ?? " "
76+ static func assertLineText( _ buffer: Buffer , terminal : Terminal ? = nil , row: Int , equals expected: String ) {
77+ let actual = lineText ( buffer: buffer, terminal : terminal , row: row) ?? " "
7078 #expect( actual == expected)
7179 }
7280}
7381
74- private func bufferLineText( buffer: Buffer , lineIndex: Int , trimRight: Bool ) -> String {
82+ private func bufferLineText(
83+ buffer: Buffer ,
84+ lineIndex: Int ,
85+ trimRight: Bool ,
86+ characterProvider: ( ( CharData ) -> Character ) ? = nil
87+ ) -> String {
7588 return buffer. translateBufferLineToString (
7689 lineIndex: lineIndex,
7790 trimRight: trimRight,
7891 startCol: 0 ,
7992 endCol: - 1 ,
80- skipNullCellsFollowingWide: true
93+ skipNullCellsFollowingWide: true ,
94+ characterProvider: characterProvider
8195 ) . replacingOccurrences ( of: " \u{0} " , with: " " )
8296}
97+
98+ private func makeCharacterProvider( _ terminal: Terminal ? ) -> ( ( CharData ) -> Character ) ? {
99+ guard let terminal else { return nil }
100+ return { terminal. getCharacter ( for: $0) }
101+ }
0 commit comments