", to: &stream)
75 |
76 | print("", to: &stream)
77 | let pipe = Pipe()
78 | let process = Process()
79 | process.launchPath = "/usr/bin/man"
80 | process.arguments = ["\(section)/\(file)"]
81 | process.standardOutput = pipe
82 | process.launch()
83 | let data = pipe.fileHandleForReading.readDataToEndOfFile()
84 | var newData = [AttributedCharacter]()
85 | var i = 0
86 | while i < data.count {
87 | if data[i] == 0x08 {
88 | if newData.count > 0 && i + 1 < data.count {
89 | let last = newData.last!.value
90 | newData.removeLast(1)
91 | newData.append(AttributedCharacter(value: data[i + 1], bold: last == data[i + 1], understrike: last == 0x5f && data[i + 1] != 0x5f))
92 | i += 1
93 | }
94 | }
95 | else {
96 | newData.append(AttributedCharacter(value: data[i], bold: false, understrike: false))
97 | }
98 | i += 1
99 | }
100 | pipe.fileHandleForReading.closeFile()
101 | pipe.fileHandleForWriting.closeFile()
102 | print(newData.map({$0.escapedString}).joined()
103 | .replacingOccurrences(of: "", with: "")
104 | .replacingOccurrences(of: "", with: "")
105 | //.replacingOccurrences(of: "-
", with: "") // there are spaces; man by itself doesn't handle such case
106 | , to: &stream)
107 | print("
", to: &stream)
108 |
109 | print("