betterdisplaycli 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Makefile CHANGED
@@ -28,4 +28,4 @@ publish:
28
28
  npm publish
29
29
 
30
30
  .PHONY: prepublishOnly
31
- prepublishOnly: lint
31
+ prepublishOnly: lint test clean
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "betterdisplaycli",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "TypeScript bindings for `betterdisplaycli`.",
5
5
  "author": "Lucas Garron <code@garron.net>",
6
6
  "exports": {
package/src/get.test.ts CHANGED
@@ -1,8 +1,26 @@
1
- import { expect, test } from "bun:test";
1
+ import { expect, spyOn, test } from "bun:test";
2
+ import { stderr } from "node:process";
2
3
  import { getAllDevices } from "./get";
3
4
 
5
+ const stderrMock = spyOn(stderr, "write");
6
+
4
7
  test("getAllDevices", async () => {
5
8
  const numConnected = (await getAllDevices({ ignoreDisplayGroups: true }))
6
9
  .length;
7
10
  expect(numConnected).toBeTypeOf("number");
11
+ expect(stderrMock.mock.calls.slice(-2)).toEqual([
12
+ [
13
+ "\u001B[90m\u001B[1mbetterdisplaycli get --identifiers\u001B[22m\u001B[39m",
14
+ ],
15
+ ["\n"],
16
+ ]);
17
+ });
18
+
19
+ test("getAllDevices quiet", async () => {
20
+ stderrMock.mockReset();
21
+ const numConnected = (
22
+ await getAllDevices({ ignoreDisplayGroups: true, quiet: true })
23
+ ).length;
24
+ expect(numConnected).toBeTypeOf("number");
25
+ expect(stderrMock.mock.calls).toEqual([]);
8
26
  });
package/src/get.ts CHANGED
@@ -7,16 +7,36 @@ import {
7
7
  type VirtualScreen,
8
8
  } from "./Device";
9
9
 
10
- export async function getAllDevices(options?: {
11
- ignoreDisplayGroups: true;
12
- }): Promise<(Display | VirtualScreen)[]>;
13
- export async function getAllDevices(options?: {
14
- ignoreDisplayGroups?: boolean;
15
- }): Promise<Device[]> {
16
- const jsonStream = await new PrintableShellCommand("betterdisplaycli", [
17
- ["get", "--identifiers"],
18
- ])
19
- .print({ argumentLineWrapping: "inline" })
10
+ interface QuietOption {
11
+ quiet?: boolean;
12
+ }
13
+
14
+ function print(
15
+ command: PrintableShellCommand,
16
+ printOptions?: Parameters<PrintableShellCommand["print"]>[0],
17
+ quietOptions?: QuietOption,
18
+ ): PrintableShellCommand {
19
+ if (!quietOptions?.quiet) {
20
+ command.print(printOptions);
21
+ }
22
+ return command;
23
+ }
24
+
25
+ export async function getAllDevices(
26
+ options?: {
27
+ ignoreDisplayGroups?: true;
28
+ } & QuietOption,
29
+ ): Promise<(Display | VirtualScreen)[]>;
30
+ export async function getAllDevices(
31
+ options?: {
32
+ ignoreDisplayGroups?: boolean;
33
+ } & QuietOption,
34
+ ): Promise<Device[]> {
35
+ const jsonStream = await print(
36
+ new PrintableShellCommand("betterdisplaycli", [["get", "--identifiers"]]),
37
+ { argumentLineWrapping: "inline" },
38
+ options,
39
+ )
20
40
  .stdout()
21
41
  .text();
22
42
  const deviceInfos: DeviceInfo[] = JSON.parse(`[${jsonStream}]`);
@@ -30,10 +50,12 @@ export async function getAllDevices(options?: {
30
50
  });
31
51
  }
32
52
 
33
- export async function connectAllDisplays(): Promise<void> {
34
- await new PrintableShellCommand("betterdisplaycli", [
35
- ["perform", "--connectAllDisplays"],
36
- ])
37
- .print({ argumentLineWrapping: "inline" })
38
- .spawnTransparently().success;
53
+ export async function connectAllDisplays(options?: QuietOption): Promise<void> {
54
+ await print(
55
+ new PrintableShellCommand("betterdisplaycli", [
56
+ ["perform", "--connectAllDisplays"],
57
+ ]),
58
+ { argumentLineWrapping: "inline" },
59
+ options,
60
+ ).spawnTransparently().success;
39
61
  }