betterdisplaycli 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "betterdisplaycli",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "TypeScript bindings for `betterdisplaycli`.",
5
5
  "author": "Lucas Garron <code@garron.net>",
6
6
  "exports": {
package/src/Device.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { PrintableShellCommand } from "printable-shell-command";
2
+ import { print, type QuietOption } from "./get";
3
+
1
4
  export type NumberString = string;
2
5
 
3
6
  export interface DeviceInfoCommon {
@@ -35,13 +38,75 @@ export class Device {
35
38
  constructor(public readonly info: DeviceInfoCommon) {}
36
39
  }
37
40
 
38
- export class Display extends Device {
41
+ class SingleDisplay extends Device {
42
+ constructor(public override readonly info: DeviceInfoCommon) {
43
+ super(info);
44
+ }
45
+ boolean = {
46
+ get: async (
47
+ settingName: "connected" | "hiDPI",
48
+ options: QuietOption,
49
+ ): Promise<boolean> => {
50
+ switch (
51
+ (
52
+ await print(
53
+ new PrintableShellCommand("betterdisplaycli", [
54
+ "get",
55
+ `--name=${this.info.name}`,
56
+ `--${settingName}`,
57
+ ]),
58
+ { argumentLineWrapping: "inline" },
59
+ options,
60
+ ).text()
61
+ ).trim()
62
+ ) {
63
+ case "on": {
64
+ return true;
65
+ }
66
+ case "off": {
67
+ return true;
68
+ }
69
+ default:
70
+ throw new Error("Invalid value") as never;
71
+ }
72
+ },
73
+
74
+ set: async (
75
+ setting: "connected" | "hiDPI",
76
+ on: boolean,
77
+ options: QuietOption,
78
+ ): Promise<void> => {
79
+ await print(
80
+ new PrintableShellCommand("betterdisplaycli", [
81
+ "set",
82
+ `--name=${this.info.name}`,
83
+ `--${setting}=${on ? "on" : "off"}`,
84
+ ]),
85
+ { argumentLineWrapping: "inline" },
86
+ options,
87
+ ).shellOut();
88
+ },
89
+
90
+ toggle: async (
91
+ settingName: "connected" | "hiDPI",
92
+ options: QuietOption,
93
+ ): Promise<void> => {
94
+ await this.boolean.set(
95
+ settingName,
96
+ await this.boolean.get(settingName, options),
97
+ options,
98
+ );
99
+ },
100
+ };
101
+ }
102
+
103
+ export class Display extends SingleDisplay {
39
104
  constructor(public override readonly info: DisplayInfo) {
40
105
  super(info);
41
106
  }
42
107
  }
43
108
 
44
- export class VirtualScreen extends Device {
109
+ export class VirtualScreen extends SingleDisplay {
45
110
  constructor(public override readonly info: VirtualScreenInfo) {
46
111
  super(info);
47
112
  }
package/src/get.test.ts CHANGED
@@ -2,6 +2,8 @@ import { expect, spyOn, test } from "bun:test";
2
2
  import { stderr } from "node:process";
3
3
  import { getAllDevices } from "./get";
4
4
 
5
+ stderr.isTTY = true;
6
+
5
7
  const stderrMock = spyOn(stderr, "write");
6
8
 
7
9
  test("getAllDevices", async () => {
package/src/get.ts CHANGED
@@ -7,11 +7,11 @@ import {
7
7
  type VirtualScreen,
8
8
  } from "./Device";
9
9
 
10
- interface QuietOption {
10
+ export interface QuietOption {
11
11
  quiet?: boolean;
12
12
  }
13
13
 
14
- function print(
14
+ export function print(
15
15
  command: PrintableShellCommand,
16
16
  printOptions?: Parameters<PrintableShellCommand["print"]>[0],
17
17
  quietOptions?: QuietOption,