FIX: fixed issues due to ScrollView limit and stream rate

This commit is contained in:
Etienne Roesch 2025-04-04 11:21:13 +01:00
parent 80cddb0314
commit 4abda00033
2 changed files with 34 additions and 12 deletions

View file

@ -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

View file

@ -34,6 +34,7 @@ func runShellCommandAsync(command: String, outputText: Binding<String>?, 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 {