aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-04-28 01:45:02 +0530
committerRoopesh Chander <roop@roopc.net>2019-04-28 14:29:22 +0530
commit5914e868ab541de675cd6e8fa8be6ff2340f30f6 (patch)
tree01bbbccfa42997e3384df58242f2adcc67add4f8 /WireGuard
parentwireguard-go-bridge: add missing format specifier for error (diff)
downloadwireguard-apple-5914e868ab541de675cd6e8fa8be6ff2340f30f6.tar.xz
wireguard-apple-5914e868ab541de675cd6e8fa8be6ff2340f30f6.zip
iOS: Log view: Improve the look
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift26
1 files changed, 23 insertions, 3 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift
index 0c881f3..4e4412d 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift
@@ -20,6 +20,15 @@ class LogViewController: UIViewController {
return busyIndicator
}()
+ let paragraphStyle: NSParagraphStyle = {
+ let paragraphStyle = NSMutableParagraphStyle()
+ paragraphStyle.setParagraphStyle(NSParagraphStyle.default)
+ paragraphStyle.lineHeightMultiple = 1.2
+ return paragraphStyle
+ }()
+
+ var isNextLineHighlighted = false
+
var logViewHelper: LogViewHelper?
var isFetchingLogEntries = false
private var updateLogEntriesTimer: Timer?
@@ -68,9 +77,20 @@ class LogViewController: UIViewController {
}
guard !fetchedLogEntries.isEmpty else { return }
let isScrolledToEnd = self.textView.contentSize.height - self.textView.bounds.height - self.textView.contentOffset.y < 1
- let text = fetchedLogEntries.reduce("") { $0 + $1.text() + "\n" }
- let font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body)
- let richText = NSAttributedString(string: text, attributes: [.font: font])
+
+ let richText = NSMutableAttributedString()
+ let bodyFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body)
+ let captionFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.caption1)
+ let lightGrayColor = UIColor(white: 0.88, alpha: 1.0)
+
+ for logEntry in fetchedLogEntries {
+ let bgColor = self.isNextLineHighlighted ? lightGrayColor : UIColor.white
+ let timestampText = NSAttributedString(string: logEntry.timestamp + "\n", attributes: [.font: captionFont, .backgroundColor: bgColor, .paragraphStyle: self.paragraphStyle])
+ let messageText = NSAttributedString(string: logEntry.message + "\n", attributes: [.font: bodyFont, .backgroundColor: bgColor, .paragraphStyle: self.paragraphStyle])
+ richText.append(timestampText)
+ richText.append(messageText)
+ self.isNextLineHighlighted.toggle()
+ }
self.textView.textStorage.append(richText)
if isScrolledToEnd {
let endOfCurrentText = NSRange(location: (self.textView.text as NSString).length, length: 0)