Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Use the new dynamic list for the history
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 6, 2024
1 parent eb6ec43 commit 03026ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PackageDescription
let package = Package(
name: "Scripter",
dependencies: [
.package(url: "https://github.com/AparokshaUI/Adwaita", from: "0.1.8"),
.package(url: "https://github.com/AparokshaUI/Adwaita", from: "0.1.9"),
.package(url: "https://github.com/AparokshaUI/CodeEditor", from: "0.1.0")
],
targets: [
Expand Down
47 changes: 20 additions & 27 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@ struct ContentView: View {
var app: GTUIApp
var window: GTUIApplicationWindow
var importContent: String
let box = Libadwaita.ListBox()

var view: Body {
OverlaySplitView(visible: sidebarVisible) {
ScrollView {
box
.style("navigation-sidebar")
.onAppear {
_ = box.handler {
if let text = output[safe: box.getSelectedRow()] {
selectedText = text
}
}
}
List(output, selection: $selectedText) { output in
Text(output)
.halign(.start)
.padding()
}
.style("navigation-sidebar")
}
.topToolbar {
HeaderBar.start {
Expand Down Expand Up @@ -75,25 +71,22 @@ struct ContentView: View {
}

func run() {
Task {
let process = Process()
process.executableURL = .init(fileURLWithPath: "/usr/bin/python3")
process.arguments = ["-c", text]
let process = Process()
process.executableURL = .init(fileURLWithPath: "/usr/bin/python3")
process.arguments = ["-c", text]

let pipe = Pipe()
process.standardOutput = pipe
try process.run()
let pipe = Pipe()
process.standardOutput = pipe
try? process.run()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
if let output = String(data: data, encoding: .utf8) {
let output = output.components(separatedBy: "\n").filter { !$0.isEmpty }
for element in output {
self.output.insert(element, at: 0)
_ = box.prepend(Label(element).halign(.start))
box.selectRow(at: 0)
if !sidebarVisible {
outputSignal.signal()
}
let data = pipe.fileHandleForReading.readDataToEndOfFile()
if let output = String(data: data, encoding: .utf8) {
let output = output.components(separatedBy: "\n").filter { !$0.isEmpty }
for element in output {
self.output.insert(element, at: 0)
selectedText = element
if !sidebarVisible {
outputSignal.signal()
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/String.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// ContentView.swift
// Scripter
//

extension String: Identifiable {

/// The identifier.
public var id: Self { self }

}

0 comments on commit 03026ee

Please sign in to comment.