-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
LocalPackage/Sources/Common/cmdArgs/query/ListMonitorsCmdArgs.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public struct ListMonitorsCmdArgs: RawCmdArgs, CmdArgs, Equatable { | ||
public static let parser: CmdParser<Self> = cmdParser( | ||
kind: .listMonitors, | ||
allowInConfig: false, | ||
help: """ | ||
USAGE: list-monitors [-h|--help] [--focused] [--mouse] | ||
OPTIONS: | ||
-h, --help Print help | ||
--focused Only print the focused monitor | ||
--mouse Only print the monitor with the mouse | ||
""", | ||
options: [ | ||
"--focused": trueBoolFlag(\.focused), | ||
"--mouse": trueBoolFlag(\.mouse) | ||
], | ||
arguments: [] | ||
) | ||
|
||
public var focused: Bool? = false | ||
public var mouse: Bool? = false | ||
|
||
public init() {} | ||
} | ||
|
||
public func parseListMonitorsCmdArgs(_ args: [String]) -> ParsedCmd<ListMonitorsCmdArgs> { | ||
parseRawCmdArgs(ListMonitorsCmdArgs(), args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
= aerospace-list-monitors(1) | ||
include::util/man-attributes.adoc[] | ||
:manname: aerospace-list-monitors | ||
// tag::purpose[] | ||
:manpurpose: Prints the list of monitors | ||
// end::purpose[] | ||
|
||
== Synopsis | ||
// tag::synopsis[] | ||
list-monitors [-h|--help] [--focused] [--mouse] | ||
// end::synopsis[] | ||
|
||
== Description | ||
|
||
// tag::body[] | ||
{manpurpose} | ||
|
||
Output format is the table with 2 columns: | ||
|
||
* Monitor unique sequence ID (ID orders monitors from left to right) | ||
* Monitor name | ||
|
||
Output example: | ||
|
||
---- | ||
1 | Built-in Retina Display | ||
2 | DELL U2723QE | ||
---- | ||
|
||
NOTE: monitor sequence ID may change if you plug or unplug monitors | ||
|
||
You can use `awk` to get values of particular column: `awk -F '|' '{print $2}'` | ||
// end::body[] | ||
|
||
include::util/conditional-options-header.adoc[] | ||
|
||
-h, --help:: Print help | ||
--focused:: Only print the focused monitor | ||
--mouse:: Only print the monitor with the mouse | ||
|
||
include::util/man-footer.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Common | ||
|
||
struct ListMonitorsCommand: Command { | ||
let info: CmdStaticInfo = ListMonitorsCmdArgs.info | ||
let args: ListMonitorsCmdArgs | ||
|
||
func _run(_ subject: inout CommandSubject, _ stdout: inout String) -> Bool { | ||
check(Thread.current.isMainThread) | ||
var result: [(Int, Monitor)] = sortedMonitors.withIndex | ||
if args.getOptionWithDefault(\.focused) { | ||
result = result.filter { (_, monitor) in | ||
monitor.activeWorkspace.name == focusedWorkspaceName | ||
} | ||
} | ||
if args.getOptionWithDefault(\.mouse) { | ||
result = result.filter { (_, monitor) in | ||
monitor.activeWorkspace.name == mouseLocation.monitorApproximation.activeWorkspace.name | ||
} | ||
} | ||
stdout += result | ||
.map { (index, monitor) in | ||
[String(index + 1), monitor.name] | ||
} | ||
.toPaddingTable() | ||
+ "\n" | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import XCTest | ||
import Common | ||
@testable import AeroSpace_Debug | ||
|
||
final class ListMonitorsTest: XCTestCase { | ||
override func setUpWithError() throws { setUpWorkspacesForTests() } | ||
|
||
func testParseListMonitorsCommand() { | ||
XCTAssertEqual(parseCommand("list-monitors").cmdOrNil?.describe, .listMonitors(args: ListMonitorsCmdArgs())) | ||
XCTAssertEqual(parseCommand("list-monitors --focused").cmdOrNil?.describe, .listMonitors(args: ListMonitorsCmdArgs().copy(\.focused, true))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters