diff --git a/MSG Desktop/ContentView.swift b/MSG Desktop/ContentView.swift index e367b39..0f3e008 100644 --- a/MSG Desktop/ContentView.swift +++ b/MSG Desktop/ContentView.swift @@ -28,7 +28,7 @@ struct ContentView: View { // App icon let appIcon = NSImage(named: NSImage.applicationIconName) Image(nsImage: appIcon ?? NSImage()) - .resizable() + . resizable() .scaledToFit() .frame(maxHeight: 150) .background( @@ -44,19 +44,18 @@ struct ContentView: View { // ScrollView fills remaining height ScrollViewReader { proxy in ScrollView { - VStack(alignment: .leading) { - TextEditor(text: $appState.output) - .font(.system(.body, design: .monospaced)) - .frame( - width: geometry.size.width - 60, - height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding - ) - .padding() - .disabled(true) + LazyVStack(alignment: .leading, spacing: 0) { + let lines = appState.output.components(separatedBy: .newlines) - Text("") - .id("bottom") + ForEach(lines.indices, id: \.self) { index in + Text(lines[index]) + .font(.system(.body, design: .monospaced)) + .frame(maxWidth: .infinity, alignment: .leading) + } + + Color.clear.frame(height: 1).id("bottom") } + .padding() } .onChange(of: appState.output) { _, _ in trimLinesIfNeeded() @@ -64,6 +63,28 @@ struct ContentView: View { proxy.scrollTo("bottom", anchor: .bottom) } } + +// ScrollView { +// VStack(alignment: .leading) { +// TextEditor(text: $appState.output) +// .font(.system(.body, design: .monospaced)) +// .frame( +// width: geometry.size.width - 60, +// height: max(0, geometry.size.height - imageHeight - 120) // - rough height of button row and padding +// ) +// .padding() +// .disabled(true) +// +// Text("") +// .id("bottom") +// } +// } +// .onChange(of: appState.output) { _, _ in +// trimLinesIfNeeded() +// withAnimation { +// proxy.scrollTo("bottom", anchor: .bottom) +// } +// } } // Buttons diff --git a/MSG Desktop/MSG_DesktopApp.swift b/MSG Desktop/MSG_DesktopApp.swift index 0420810..70254a3 100644 --- a/MSG Desktop/MSG_DesktopApp.swift +++ b/MSG Desktop/MSG_DesktopApp.swift @@ -34,6 +34,7 @@ func runShellCommandAsync(command: String, outputText: Binding?, showBut var observer: NSObjectProtocol? + observer = NotificationCenter.default.addObserver(forName: .NSFileHandleDataAvailable, object: fileHandle, queue: nil) { _ in let data = fileHandle.availableData if let output = String(data: data, encoding: .utf8), !output.isEmpty {