| ... | @@ -119,6 +119,21 @@ private enum TerminalHardwareKeyEncoder { | ... | @@ -119,6 +119,21 @@ private enum TerminalHardwareKeyEncoder { |
| 119 | } | 119 | } |
| 120 | } | 120 | } |
| 121 | | 121 | |
| | 122 | private enum TerminalInputSequence { |
| | 123 | /// Terminal Enter is carriage return. Sending line feed instead is Ctrl+J, |
| | 124 | /// which raw-mode TUIs may interpret as the literal J key. |
| | 125 | static let carriageReturn = "\r" |
| | 126 | |
| | 127 | static func normalizingReturn(_ input: String) -> String { |
| | 128 | switch input { |
| | 129 | case "\n", "\r\n": |
| | 130 | return carriageReturn |
| | 131 | default: |
| | 132 | return input |
| | 133 | } |
| | 134 | } |
| | 135 | } |
| | 136 | |
| 122 | private final class TerminalInputField: UITextField { | 137 | private final class TerminalInputField: UITextField { |
| 123 | var onDeleteBackward: (() -> Void)? | 138 | var onDeleteBackward: (() -> Void)? |
| 124 | var onInsert: ((String) -> Void)? | 139 | var onInsert: ((String) -> Void)? |
| ... | @@ -352,7 +367,9 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate { | ... | @@ -352,7 +367,9 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate { |
| 352 | | 367 | |
| 353 | public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | 368 | public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { |
| 354 | if !string.isEmpty { | 369 | if !string.isEmpty { |
| 355 | emitInput(string) | 370 | // Some software keyboards deliver Return through this delegate instead of |
| | 371 | // textFieldShouldReturn, so normalize that path too. |
| | 372 | emitInput(TerminalInputSequence.normalizingReturn(string)) |
| 356 | return false | 373 | return false |
| 357 | } | 374 | } |
| 358 | | 375 | |
| ... | @@ -360,7 +377,7 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate { | ... | @@ -360,7 +377,7 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate { |
| 360 | } | 377 | } |
| 361 | | 378 | |
| 362 | public func textFieldShouldReturn(_ textField: UITextField) -> Bool { | 379 | public func textFieldShouldReturn(_ textField: UITextField) -> Bool { |
| 363 | emitInput("\n") | 380 | emitInput(TerminalInputSequence.carriageReturn) |
| 364 | textField.text = "" | 381 | textField.text = "" |
| 365 | return false | 382 | return false |
| 366 | } | 383 | } |