forked from nikitabobko/AeroSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
141 additions
and
2 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
54 changes: 54 additions & 0 deletions
54
LocalPackage/Sources/Common/cmdArgs/query/ListWorkspacesCmdArgs.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,54 @@ | ||
private let onitors = "<monitors>" | ||
|
||
public struct ListWorkspacesCmdArgs: RawCmdArgs, CmdArgs { | ||
public static let parser: CmdParser<Self> = cmdParser( | ||
kind: .listWorkspaces, | ||
allowInConfig: false, | ||
help: """ | ||
USAGE: list-workspaces [-h|--help] [--visible [no]] [--focused [no]] [--mouse [no]] | ||
[--on-monitors \(onitors)] | ||
OPTIONS: | ||
-h, --help Print help | ||
--visible [no] Filter results to only print currently visible workspaces or not | ||
--mouse [no] Filter results to only print the workspace with the mouse or not | ||
--focused [no] Filter results to only print the focused workspace or not | ||
--on-monitors \(onitors) Filter results to only print the workspaces that are attached to specified monitors. | ||
\(onitors) is a comma separated list of monitor IDs | ||
""", | ||
options: [ | ||
"--visible": boolFlag(\.visible), | ||
"--mouse": boolFlag(\.mouse), | ||
"--focused": boolFlag(\.focused), | ||
"--on-monitors": ArgParser(\.onMonitors, parseMonitorIds) | ||
], | ||
arguments: [] | ||
) | ||
|
||
public var visible: Bool? | ||
public var mouse: Bool? | ||
public var focused: Bool? | ||
public var onMonitors: [Int] = [] | ||
|
||
public init() {} | ||
} | ||
|
||
public func parseListWorkspaces(_ args: [String]) -> ParsedCmd<ListWorkspacesCmdArgs> { | ||
parseRawCmdArgs(ListWorkspacesCmdArgs(), args) | ||
} | ||
|
||
private func parseMonitorIds(arg: String, nextArgs: inout [String]) -> Parsed<[Int]> { | ||
if let nextArg = nextArgs.nextNonFlagOrNil() { | ||
var monitors: [Int] = [] | ||
for monitor in nextArg.split(separator: ",").map({ String($0) }) { | ||
if let unwrapped = Int(monitor) { | ||
monitors.append(unwrapped - 1) | ||
} else { | ||
return .failure("Can't parse '\(monitor)'. It must be a number") | ||
} | ||
} | ||
return .success(monitors) | ||
} else { | ||
return .failure("\(onitors) is mandatory") | ||
} | ||
} |
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,33 @@ | ||
= aerospace-list-workspaces(1) | ||
include::util/man-attributes.adoc[] | ||
:manname: aerospace-list-workspaces | ||
// tag::purpose[] | ||
:manpurpose: Prints the list of workspaces on new lines | ||
// end::purpose[] | ||
|
||
== Synopsis | ||
[verse] | ||
// tag::synopsis[] | ||
list-workspaces [-h|--help] [--visible [no]] [--focused [no]] [--mouse [no]] | ||
[--on-monitors <monitors>] | ||
|
||
// end::synopsis[] | ||
|
||
== Description | ||
|
||
// tag::body[] | ||
{manpurpose} | ||
|
||
include::util/conditional-options-header.adoc[] | ||
|
||
-h, --help:: Print help | ||
--focused [no]:: Filter results to only print the focused workspace or not | ||
--mouse [no]:: Filter results to only print the workspace with the mouse or not | ||
--focused [no]:: Filter results to only print the focused workspace or not | ||
--on-monitors <monitors>:: | ||
Filter results to only print the workspaces that are attached to specified monitors. | ||
<monitors> is a comma separated list of monitor IDs | ||
|
||
// end::body[] | ||
|
||
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
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,36 @@ | ||
import Common | ||
|
||
struct ListWorkspacesCommand: Command { | ||
let info: CmdStaticInfo = ListWorkspacesCmdArgs.info | ||
let args: ListWorkspacesCmdArgs | ||
|
||
func _run(_ state: CommandMutableState, stdin: String) -> Bool { | ||
check(Thread.current.isMainThread) | ||
var result: [Workspace] = Workspace.all | ||
if let visible = args.visible { | ||
result = result.filter { $0.isVisible == visible } | ||
} | ||
if let mouse = args.mouse { | ||
let mouseWorkspace = mouseLocation.monitorApproximation.activeWorkspace | ||
result = result.filter { ($0 == mouseWorkspace) == mouse } | ||
} | ||
if let focused = args.focused { | ||
result = result.filter { ($0 == Workspace.focused) == focused } | ||
} | ||
if !args.onMonitors.isEmpty { | ||
let sortedMonitors = sortedMonitors | ||
var requested: Set<CGPoint> = [] | ||
for id in args.onMonitors { | ||
if let monitor = sortedMonitors.getOrNil(atIndex: id) { | ||
requested.insert(monitor.rect.topLeftCorner) | ||
} else { | ||
state.stdout.append("Invalid monitor ID: \(id)") | ||
return false | ||
} | ||
} | ||
result = result.filter { requested.contains($0.monitor.rect.topLeftCorner) } | ||
} | ||
state.stdout += result.map(\.name) | ||
return true | ||
} | ||
} |