@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
swift 59 lines 1.9 KB
Raw
1 import UIKit
2
3 final class TerminalTextSelectionViewController: UIViewController {
4 private let text: String
5 private let fontSize: CGFloat
6
7 init(text: String, fontSize: CGFloat) {
8 self.text = text
9 self.fontSize = fontSize
10 super.init(nibName: nil, bundle: nil)
11 }
12
13 required init?(coder: NSCoder) {
14 return nil
15 }
16
17 override func viewDidLoad() {
18 super.viewDidLoad()
19 title = "Terminal text"
20 view.backgroundColor = .systemBackground
21
22 navigationItem.leftBarButtonItem = UIBarButtonItem(
23 title: "Copy All", style: .plain, target: self, action: #selector(copyAll))
24 navigationItem.rightBarButtonItem = UIBarButtonItem(
25 barButtonSystemItem: .done, target: self, action: #selector(close))
26
27 let textView = UITextView()
28 textView.text = text
29 textView.font = .monospacedSystemFont(ofSize: max(fontSize, 14), weight: .regular)
30 textView.textColor = .label
31 textView.backgroundColor = .systemBackground
32 textView.isEditable = false
33 textView.isSelectable = true
34 // Login flows print auth URLs; tapping one opens it.
35 textView.dataDetectorTypes = .link
36 textView.accessibilityLabel = "Terminal output"
37 textView.textContainerInset = UIEdgeInsets(top: 16, left: 12, bottom: 16, right: 12)
38 textView.translatesAutoresizingMaskIntoConstraints = false
39 view.addSubview(textView)
40
41 NSLayoutConstraint.activate([
42 textView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
43 textView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
44 textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
45 textView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
46 ])
47 }
48
49 @objc
50 private func copyAll() {
51 UIPasteboard.general.string = text
52 close()
53 }
54
55 @objc
56 private func close() {
57 dismiss(animated: !UIAccessibility.isReduceMotionEnabled)
58 }
59 }