@@ -150,24 +150,30 @@ public class LineReader {
150150 /// throw an error if the terminal cannot be written to.
151151 public func readLine( prompt: String ,
152152 maxCount: Int ? = nil ,
153+ strippingNewline: Bool = true ,
153154 promptProperties: TextProperties = TextProperties . none,
154155 readProperties: TextProperties = TextProperties . none,
155156 parenProperties: TextProperties = TextProperties . none) throws -> String {
156157 tempBuf = nil
157158 if self . termSupported {
158159 return try self . readLineSupported ( prompt: prompt,
159160 maxCount: maxCount,
161+ strippingNewline: strippingNewline,
160162 promptProperties: promptProperties,
161163 readProperties: readProperties,
162164 parenProperties: parenProperties)
163165 } else {
164- return try self . readLineUnsupported ( prompt: prompt, maxCount: maxCount)
166+ return try self . readLineUnsupported ( prompt: prompt,
167+ maxCount: maxCount,
168+ strippingNewline: strippingNewline)
165169 }
166170 }
167171
168- private func readLineUnsupported( prompt: String , maxCount: Int ? ) throws -> String {
172+ private func readLineUnsupported( prompt: String ,
173+ maxCount: Int ? ,
174+ strippingNewline: Bool ) throws -> String {
169175 print ( prompt, terminator: " " )
170- if let line = Swift . readLine ( ) {
176+ if let line = Swift . readLine ( strippingNewline : strippingNewline ) {
171177 return maxCount != nil ? String ( line. prefix ( maxCount!) ) : line
172178 } else {
173179 throw LineReaderError . EOF
@@ -176,6 +182,7 @@ public class LineReader {
176182
177183 private func readLineSupported( prompt: String ,
178184 maxCount: Int ? ,
185+ strippingNewline: Bool ,
179186 promptProperties: TextProperties ,
180187 readProperties: TextProperties ,
181188 parenProperties: TextProperties ) throws -> String {
@@ -196,12 +203,17 @@ public class LineReader {
196203 char = completionChar
197204 }
198205 if let rv = try self . handleCharacter ( char, editState: editState) {
206+ if editState. moveEnd ( ) {
207+ try self . updateCursorPos ( editState: editState)
208+ }
209+ // It's unclear to me why it's necessary to set the cursor to column 0
210+ try self . output ( text: " \n " + AnsiCodes. setCursorColumn ( 0 ) )
199211 line = rv
200212 return
201213 }
202214 }
203215 }
204- return line
216+ return strippingNewline ? line : line + " \n "
205217 }
206218
207219 private func completeLine( editState: EditState ) throws -> UInt8 ? {
0 commit comments