diff --git a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift index 9b7b936..f10b91a 100644 --- a/peekaboo-cli/Sources/peekaboo/ImageCommand.swift +++ b/peekaboo-cli/Sources/peekaboo/ImageCommand.swift @@ -153,37 +153,37 @@ struct ImageCommand: ParsableCommand { return savedFiles } - + private func getActiveDisplays() throws(CaptureError) -> [CGDirectDisplayID] { var displayCount: UInt32 = 0 let result = CGGetActiveDisplayList(0, nil, &displayCount) guard result == .success && displayCount > 0 else { throw CaptureError.noDisplaysAvailable } - + var displays = [CGDirectDisplayID](repeating: 0, count: Int(displayCount)) let listResult = CGGetActiveDisplayList(displayCount, &displays, nil) guard listResult == .success else { throw CaptureError.noDisplaysAvailable } - + return displays } - + private func captureSpecificScreen( - displays: [CGDirectDisplayID], + displays: [CGDirectDisplayID], screenIndex: Int ) throws(CaptureError) -> [SavedFile] { if screenIndex >= 0 && screenIndex < displays.count { let displayID = displays[screenIndex] let labelSuffix = " (Index \(screenIndex))" - return [try captureSingleDisplay(displayID: displayID, index: screenIndex, labelSuffix: labelSuffix)] + return try [captureSingleDisplay(displayID: displayID, index: screenIndex, labelSuffix: labelSuffix)] } else { Logger.shared.debug("Screen index \(screenIndex) is out of bounds. Capturing all screens instead.") return try captureAllScreens(displays: displays) } } - + private func captureAllScreens(displays: [CGDirectDisplayID]) throws(CaptureError) -> [SavedFile] { var savedFiles: [SavedFile] = [] for (index, displayID) in displays.enumerated() { @@ -192,17 +192,17 @@ struct ImageCommand: ParsableCommand { } return savedFiles } - + private func captureSingleDisplay( - displayID: CGDirectDisplayID, - index: Int, + displayID: CGDirectDisplayID, + index: Int, labelSuffix: String ) throws(CaptureError) -> SavedFile { let fileName = generateFileName(displayIndex: index) let filePath = getOutputPath(fileName) - + try captureDisplay(displayID, to: filePath) - + return SavedFile( path: filePath, item_label: "Display \(index + 1)\(labelSuffix)", diff --git a/peekaboo-cli/Tests/peekabooTests/ImageCaptureLogicTests.swift b/peekaboo-cli/Tests/peekabooTests/ImageCaptureLogicTests.swift index 3da832d..5d5cdbf 100644 --- a/peekaboo-cli/Tests/peekabooTests/ImageCaptureLogicTests.swift +++ b/peekaboo-cli/Tests/peekabooTests/ImageCaptureLogicTests.swift @@ -445,7 +445,7 @@ struct AdvancedImageCaptureLogicTests { @Test("Command execution readiness matrix", .tags(.fast)) func commandExecutionReadinessMatrix() { let scenarios = createTestScenarios() - + for scenario in scenarios { do { let command = try ImageCommand.parse(scenario.args) @@ -500,60 +500,60 @@ struct AdvancedImageCaptureLogicTests { } } } - + // MARK: - Helper Functions - + private struct TestScenario { let args: [String] let shouldBeReady: Bool let description: String } - + private func createTestScenarios() -> [TestScenario] { - return [ + [ TestScenario( - args: ["--mode", "screen"], - shouldBeReady: true, + args: ["--mode", "screen"], + shouldBeReady: true, description: "Basic screen capture" ), TestScenario( - args: ["--mode", "screen", "--screen-index", "0"], - shouldBeReady: true, + args: ["--mode", "screen", "--screen-index", "0"], + shouldBeReady: true, description: "Screen with index" ), TestScenario( - args: ["--mode", "window", "--app", "Finder"], - shouldBeReady: true, + args: ["--mode", "window", "--app", "Finder"], + shouldBeReady: true, description: "Basic window capture" ), TestScenario( - args: ["--mode", "window", "--app", "Safari", "--window-title", "Main"], - shouldBeReady: true, + args: ["--mode", "window", "--app", "Safari", "--window-title", "Main"], + shouldBeReady: true, description: "Window with title" ), TestScenario( - args: ["--mode", "window", "--app", "Terminal", "--window-index", "0"], - shouldBeReady: true, + args: ["--mode", "window", "--app", "Terminal", "--window-index", "0"], + shouldBeReady: true, description: "Window with index" ), TestScenario( - args: ["--mode", "multi"], - shouldBeReady: true, + args: ["--mode", "multi"], + shouldBeReady: true, description: "Multi-screen capture" ), TestScenario( - args: ["--mode", "multi", "--app", "Xcode"], - shouldBeReady: true, + args: ["--mode", "multi", "--app", "Xcode"], + shouldBeReady: true, description: "Multi-window capture" ), TestScenario( - args: ["--app", "Finder"], - shouldBeReady: true, + args: ["--app", "Finder"], + shouldBeReady: true, description: "Implicit window mode" ), TestScenario( - args: [], - shouldBeReady: true, + args: [], + shouldBeReady: true, description: "Default screen capture" ) ]