@flowscripter/dynamic-cli-framework 1.0.0

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.
Files changed (133) hide show
  1. package/.github/workflows/check-bun-dependencies.yml +9 -0
  2. package/.github/workflows/lint-pr-message.yml +11 -0
  3. package/.github/workflows/release-bun-library.yml +8 -0
  4. package/.github/workflows/validate-bun-library-pr.yml +8 -0
  5. package/LICENSE +21 -0
  6. package/README.md +1475 -0
  7. package/bun.lock +63 -0
  8. package/index.ts +89 -0
  9. package/package.json +23 -0
  10. package/src/api/CLI.ts +17 -0
  11. package/src/api/CLIConfig.ts +19 -0
  12. package/src/api/Context.ts +25 -0
  13. package/src/api/RunResult.ts +142 -0
  14. package/src/api/argument/Argument.ts +36 -0
  15. package/src/api/argument/ArgumentValueTypes.ts +87 -0
  16. package/src/api/argument/ComplexOption.ts +31 -0
  17. package/src/api/argument/GlobalCommandArgument.ts +17 -0
  18. package/src/api/argument/Option.ts +32 -0
  19. package/src/api/argument/Positional.ts +27 -0
  20. package/src/api/argument/SubCommandArgument.ts +20 -0
  21. package/src/api/command/Command.ts +22 -0
  22. package/src/api/command/GlobalCommand.ts +33 -0
  23. package/src/api/command/GlobalModifierCommand.ts +12 -0
  24. package/src/api/command/GroupCommand.ts +20 -0
  25. package/src/api/command/SubCommand.ts +41 -0
  26. package/src/api/command/UsageExample.ts +21 -0
  27. package/src/api/service/ServiceProvider.ts +52 -0
  28. package/src/api/service/core/AsciiBannerGeneratorService.ts +35 -0
  29. package/src/api/service/core/KeyValueService.ts +28 -0
  30. package/src/api/service/core/PrinterService.ts +266 -0
  31. package/src/api/service/core/ShutdownService.ts +12 -0
  32. package/src/api/service/core/SyntaxHighlighterService.ts +42 -0
  33. package/src/cli/BaseCLI.ts +312 -0
  34. package/src/cli/DefaultRuntimeCLI.ts +54 -0
  35. package/src/command/MultiCommandCliHelpCommand.ts +394 -0
  36. package/src/command/SingleCommandCliHelpCommand.ts +183 -0
  37. package/src/command/UsageCommand.ts +35 -0
  38. package/src/command/VersionCommand.ts +22 -0
  39. package/src/launcher.ts +127 -0
  40. package/src/runtime/DefaultContext.ts +32 -0
  41. package/src/runtime/argument/ArgumentTypeGuards.ts +8 -0
  42. package/src/runtime/command/CommandTypeGuards.ts +30 -0
  43. package/src/runtime/command/CommandValidator.ts +549 -0
  44. package/src/runtime/parser.ts +219 -0
  45. package/src/runtime/registry/CommandRegistry.ts +121 -0
  46. package/src/runtime/registry/DefaultCommandRegistry.ts +318 -0
  47. package/src/runtime/registry/DefaultServiceProviderRegistry.ts +26 -0
  48. package/src/runtime/registry/ServiceProviderRegistry.ts +11 -0
  49. package/src/runtime/runner.ts +697 -0
  50. package/src/runtime/scanner.ts +417 -0
  51. package/src/runtime/values/ValuePopulationResult.ts +41 -0
  52. package/src/runtime/values/argumentValueMerge.ts +201 -0
  53. package/src/runtime/values/argumentValueValidation.ts +610 -0
  54. package/src/runtime/values/globalCommandValuePopulation.ts +96 -0
  55. package/src/runtime/values/subCommandValuePopulation.ts +680 -0
  56. package/src/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.ts +45 -0
  57. package/src/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.ts +38 -0
  58. package/src/service/asciiBannerGenerator/standard.flf.json +3 -0
  59. package/src/service/banner/BannerServiceProvider.ts +99 -0
  60. package/src/service/banner/command/NoBannerCommand.ts +42 -0
  61. package/src/service/configuration/ConfigurationServiceProvider.ts +571 -0
  62. package/src/service/configuration/DefaultKeyValueService.ts +60 -0
  63. package/src/service/configuration/command/ConfigCommand.ts +43 -0
  64. package/src/service/configuration/command/DumpConfigCommand.ts +47 -0
  65. package/src/service/printer/DefaultPrinterService.ts +256 -0
  66. package/src/service/printer/PrinterServiceProvider.ts +61 -0
  67. package/src/service/printer/command/DarkModeCommand.ts +43 -0
  68. package/src/service/printer/command/LogLevelCommand.ts +68 -0
  69. package/src/service/printer/command/NoColorCommand.ts +43 -0
  70. package/src/service/printer/terminal/Ansi.ts +10 -0
  71. package/src/service/printer/terminal/Color.ts +14 -0
  72. package/src/service/printer/terminal/Progress.ts +373 -0
  73. package/src/service/printer/terminal/Spinner.ts +100 -0
  74. package/src/service/printer/terminal/Styler.ts +5 -0
  75. package/src/service/printer/terminal/Terminal.ts +8 -0
  76. package/src/service/printer/terminal/Theme.ts +34 -0
  77. package/src/service/printer/terminal/TtyStyler.ts +39 -0
  78. package/src/service/printer/terminal/TtyTerminal.ts +65 -0
  79. package/src/service/shutdown/DefaultShutdownService.ts +9 -0
  80. package/src/service/shutdown/ShutdownServiceProvider.ts +55 -0
  81. package/src/service/syntaxHighlighter/DefaultSyntaxHighlighterService.ts +52 -0
  82. package/src/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.ts +51 -0
  83. package/src/util/configHelper.ts +95 -0
  84. package/src/util/envVarHelper.ts +338 -0
  85. package/src/util/helpHelper.ts +751 -0
  86. package/src/util/logger.ts +84 -0
  87. package/src/util/runnerHelper.ts +112 -0
  88. package/tests/cli/BaseCLI.test.ts +344 -0
  89. package/tests/command/MultiCommandCliHelpCommand.test.ts +650 -0
  90. package/tests/command/SingleCommandCliHelpCommand.test.ts +384 -0
  91. package/tests/command/UsageCommand.test.ts +53 -0
  92. package/tests/command/VersionCommand.test.ts +36 -0
  93. package/tests/fixtures/CLIConfig.ts +9 -0
  94. package/tests/fixtures/Command.ts +229 -0
  95. package/tests/fixtures/CommandRegistry.ts +8 -0
  96. package/tests/fixtures/ConfigurationServiceProvider.ts +28 -0
  97. package/tests/fixtures/Context.ts +33 -0
  98. package/tests/fixtures/ServiceProviderRegistry.ts +16 -0
  99. package/tests/fixtures/StreamString.ts +37 -0
  100. package/tests/fixtures/util.ts +41 -0
  101. package/tests/runtime/DefaultContext.test.ts +20 -0
  102. package/tests/runtime/argument/ArgumentTypeGuards.test.ts +49 -0
  103. package/tests/runtime/command/CommandTypeGuards.test.ts +43 -0
  104. package/tests/runtime/command/CommandValidator.test.ts +816 -0
  105. package/tests/runtime/parser.test.ts +766 -0
  106. package/tests/runtime/registry/DefaultCommandRegistry.test.ts +166 -0
  107. package/tests/runtime/registry/DefaultServiceProviderRegistry.test.ts +42 -0
  108. package/tests/runtime/runner.test.ts +1298 -0
  109. package/tests/runtime/scanner.test.ts +1113 -0
  110. package/tests/runtime/values/argumentValueMerge.test.ts +314 -0
  111. package/tests/runtime/values/argumentValueValidation.test.ts +1020 -0
  112. package/tests/runtime/values/globalCommandValuePopulation.test.ts +662 -0
  113. package/tests/runtime/values/subCommandValuePopulation.test.ts +2658 -0
  114. package/tests/service/asciiBannerGenerator/AsciiBannerGeneratorServiceProvider.test.ts +22 -0
  115. package/tests/service/asciiBannerGenerator/DefaultAsciiBannerGeneratorService.test.ts +70 -0
  116. package/tests/service/asciiBannerGenerator/__snapshots__/DefaultAsciiBannerGeneratorService.test.ts.snap +22 -0
  117. package/tests/service/asciiBannerGenerator/small.flf.json +3 -0
  118. package/tests/service/configuration/ConfigurationServiceProvider.test.ts +249 -0
  119. package/tests/service/configuration/DefaultKeyValueService.test.ts +65 -0
  120. package/tests/service/launchBanner/BannerServiceProvider.test.ts +49 -0
  121. package/tests/service/launchBanner/__snapshots__/BannerServiceProvider.test.ts.snap +3 -0
  122. package/tests/service/launchBanner/command/NoBannerCommand.test.ts +21 -0
  123. package/tests/service/printer/DefaultPrinterService.test.ts +409 -0
  124. package/tests/service/printer/PrinterServiceProvider.test.ts +29 -0
  125. package/tests/service/printer/command/LogLevelCommand.test.ts +58 -0
  126. package/tests/service/printer/terminal/Progress.test.ts +40 -0
  127. package/tests/service/printer/terminal/Spinner.test.ts +57 -0
  128. package/tests/service/shutdown/ShutdownServiceProvider.test.ts +13 -0
  129. package/tests/service/syntaxHighlighter/DefaultSyntaxHighlighterService.test.ts +123 -0
  130. package/tests/service/syntaxHighlighter/SyntaxHighlighterServiceProvider.test.ts +41 -0
  131. package/tests/util/configHelper.test.ts +275 -0
  132. package/tests/util/envVarHelper.test.ts +318 -0
  133. package/tests/util/logger.test.ts +10 -0
@@ -0,0 +1,47 @@
1
+ import type Context from "../../../api/Context.ts";
2
+ import type GlobalCommand from "../../../api/command/GlobalCommand.ts";
3
+ import type ConfigurationServiceProvider from "../ConfigurationServiceProvider.ts";
4
+ import type PrinterService from "../../../api/service/core/PrinterService.ts";
5
+ import {
6
+ PRINTER_SERVICE_ID,
7
+ } from "../../../api/service/core/PrinterService.ts";
8
+ import type SyntaxHighlighterService from "../../../api/service/core/SyntaxHighlighterService.ts";
9
+ import {
10
+ SYNTAX_HIGHLIGHTER_SERVICE_ID,
11
+ } from "../../../api/service/core/SyntaxHighlighterService.ts";
12
+
13
+ /**
14
+ * Command which dumps the configuration loaded by the {@link ConfigurationServiceProvider}.
15
+ */
16
+ export default class DumpConfigCommand implements GlobalCommand {
17
+ readonly name = "dump-config";
18
+ readonly description = "Dump configuration values";
19
+
20
+ readonly #configurationServiceProvider: ConfigurationServiceProvider;
21
+
22
+ public constructor(
23
+ configurationServiceProvider: ConfigurationServiceProvider,
24
+ ) {
25
+ this.#configurationServiceProvider = configurationServiceProvider;
26
+ }
27
+
28
+ public async execute(
29
+ context: Context,
30
+ ): Promise<void> {
31
+ const printerService = context.getServiceById(
32
+ PRINTER_SERVICE_ID,
33
+ ) as PrinterService;
34
+ const syntaxHighlighterService = context.getServiceById(
35
+ SYNTAX_HIGHLIGHTER_SERVICE_ID,
36
+ ) as SyntaxHighlighterService;
37
+
38
+ await printerService.print(
39
+ `${
40
+ syntaxHighlighterService.highlight(
41
+ this.#configurationServiceProvider.getConfigString(),
42
+ "json",
43
+ )
44
+ }\n`,
45
+ );
46
+ }
47
+ }
@@ -0,0 +1,256 @@
1
+ import { default as Spinner } from "./terminal/Spinner.ts";
2
+ import { default as Progress } from "./terminal/Progress.ts";
3
+ import type PrinterService from "../../api/service/core/PrinterService.ts";
4
+ import { type Icon, Level } from "../../api/service/core/PrinterService.ts";
5
+ import Terminal from "./terminal/Terminal.ts";
6
+ import { Color } from "./terminal/Color.ts";
7
+ import { getDarkModeTheme, getLightModeTheme } from "./terminal/Theme.ts";
8
+ import { WritableStream } from "node:stream/web";
9
+ import Styler from "./terminal/Styler.ts";
10
+
11
+ export default class DefaultPrinterService implements PrinterService {
12
+ readonly stdoutWritable: WritableStream;
13
+ readonly stderrWritable: WritableStream;
14
+ #stdoutIsColor: boolean;
15
+ #stderrTerminal: Terminal;
16
+ #styler: Styler;
17
+ #isDarkMode = true;
18
+ #threshold = Level.INFO;
19
+ #iconDefinitions: Array<string> = [];
20
+ #theme: Array<number> = [];
21
+ #encoder = new TextEncoder();
22
+ #spinner: Spinner;
23
+ #progress: Progress;
24
+
25
+ async #log(
26
+ level: number,
27
+ message: string,
28
+ icon?: Icon,
29
+ ): Promise<void> {
30
+ if (this.#threshold > level) {
31
+ return;
32
+ }
33
+ await this.#spinner.pause();
34
+ await this.#progress.pause();
35
+ await this.#stderrTerminal.write(
36
+ `${
37
+ (icon !== undefined) ? `${this.#iconDefinitions[icon]} ` : ""
38
+ }${message}`,
39
+ );
40
+ this.#spinner.resume();
41
+ this.#progress.resume();
42
+ }
43
+
44
+ public constructor(
45
+ stdoutWritableStream: WritableStream,
46
+ stderrWritableStream: WritableStream,
47
+ stdoutIsColor: boolean,
48
+ stderrIsColor: boolean,
49
+ stderrTerminal: Terminal,
50
+ styler: Styler,
51
+ ) {
52
+ this.stdoutWritable = stdoutWritableStream;
53
+ this.stderrWritable = stderrWritableStream;
54
+ this.#stdoutIsColor = stdoutIsColor;
55
+ this.#stderrTerminal = stderrTerminal;
56
+ this.#styler = styler;
57
+ this.#styler.colorEnabled = stderrIsColor;
58
+ this.#spinner = new Spinner(this.#stderrTerminal, this.#styler);
59
+ this.#progress = new Progress(this.#stderrTerminal, this.#styler);
60
+ this.darkMode = false;
61
+ this.#iconDefinitions = [
62
+ this.green("✔"),
63
+ this.red("✖"),
64
+ this.yellow("‼"),
65
+ this.blue("ℹ"),
66
+ ];
67
+ }
68
+
69
+ set colorEnabled(enabled: boolean) {
70
+ this.#styler.colorEnabled = enabled;
71
+ this.#stdoutIsColor = enabled;
72
+ if (enabled) {
73
+ this.#iconDefinitions = [
74
+ this.green("✔"),
75
+ this.red("✖"),
76
+ this.yellow("‼"),
77
+ this.blue("ℹ"),
78
+ ];
79
+ } else {
80
+ this.#iconDefinitions = [
81
+ "✔",
82
+ "✖",
83
+ "‼",
84
+ "ℹ",
85
+ ];
86
+ }
87
+ }
88
+
89
+ get colorEnabled(): boolean {
90
+ return this.#styler.colorEnabled;
91
+ }
92
+
93
+ set darkMode(isDarkMode: boolean) {
94
+ this.#isDarkMode = isDarkMode;
95
+ if (isDarkMode) {
96
+ this.#theme = getDarkModeTheme();
97
+ } else {
98
+ this.#theme = getLightModeTheme();
99
+ }
100
+ this.#spinner.spinnerColor = this.#theme[Color.EMPHASISED];
101
+ this.#spinner.messageColor = this.#theme[Color.PRIMARY];
102
+ this.#progress.completeColor = this.#theme[Color.GREEN];
103
+ this.#progress.remainingColor = this.#theme[Color.SECONDARY];
104
+ this.#progress.labelColor = this.#theme[Color.SECONDARY];
105
+ this.#progress.valueColor = this.#theme[Color.PRIMARY];
106
+ }
107
+
108
+ get darkMode(): boolean {
109
+ return this.#isDarkMode;
110
+ }
111
+
112
+ public primary(message: string): string {
113
+ return this.#styler.colorText(message, this.#theme[Color.PRIMARY]);
114
+ }
115
+
116
+ public secondary(message: string): string {
117
+ return this.#styler.colorText(message, this.#theme[Color.SECONDARY]);
118
+ }
119
+
120
+ public emphasised(message: string): string {
121
+ return this.#styler.colorText(message, this.#theme[Color.EMPHASISED]);
122
+ }
123
+
124
+ public selected(message: string): string {
125
+ return this.#styler.colorText(message, this.#theme[Color.SELECTED]);
126
+ }
127
+
128
+ public italic(message: string): string {
129
+ return this.#styler.italicText(message);
130
+ }
131
+
132
+ public yellow(message: string): string {
133
+ return this.#styler.colorText(message, this.#theme[Color.YELLOW]);
134
+ }
135
+
136
+ public orange(message: string): string {
137
+ return this.#styler.colorText(message, this.#theme[Color.ORANGE]);
138
+ }
139
+
140
+ public red(message: string): string {
141
+ return this.#styler.colorText(message, this.#theme[Color.RED]);
142
+ }
143
+
144
+ public magenta(message: string): string {
145
+ return this.#styler.colorText(message, this.#theme[Color.MAGENTA]);
146
+ }
147
+
148
+ public violet(message: string): string {
149
+ return this.#styler.colorText(message, this.#theme[Color.VIOLET]);
150
+ }
151
+
152
+ public blue(message: string): string {
153
+ return this.#styler.colorText(message, this.#theme[Color.BLUE]);
154
+ }
155
+
156
+ public cyan(message: string): string {
157
+ return this.#styler.colorText(message, this.#theme[Color.CYAN]);
158
+ }
159
+
160
+ public green(message: string): string {
161
+ return this.#styler.colorText(message, this.#theme[Color.GREEN]);
162
+ }
163
+
164
+ public async debug(message: string, icon?: Icon): Promise<void> {
165
+ await this.#log(Level.DEBUG, this.secondary(message), icon);
166
+ }
167
+
168
+ public async info(message: string, icon?: Icon): Promise<void> {
169
+ await this.#log(Level.INFO, this.primary(message), icon);
170
+ }
171
+
172
+ public async warn(message: string, icon?: Icon): Promise<void> {
173
+ await this.#log(Level.WARN, this.yellow(message), icon);
174
+ }
175
+
176
+ public async error(message: string, icon?: Icon): Promise<void> {
177
+ await this.#log(Level.ERROR, this.red(message), icon);
178
+ }
179
+
180
+ public async print(message: string, icon?: Icon): Promise<void> {
181
+ await this.#spinner.pause();
182
+ await this.#progress.pause();
183
+ const writer = this.stdoutWritable.getWriter();
184
+ const colorMessage = this.#stdoutIsColor ? this.primary(message) : message;
185
+
186
+ const encoded = this.#encoder.encode(
187
+ `${
188
+ (icon !== undefined) ? `${this.#iconDefinitions[icon]} ` : ""
189
+ }${colorMessage}`,
190
+ );
191
+
192
+ await writer.ready;
193
+ await writer.write(encoded);
194
+
195
+ writer.releaseLock();
196
+ this.#spinner.resume();
197
+ this.#progress.resume();
198
+ }
199
+
200
+ public async setLevel(level: Level): Promise<void> {
201
+ if (this.#threshold > Level.INFO) {
202
+ await this.#spinner.hide();
203
+ await this.#progress.hideAll();
204
+ }
205
+ this.#threshold = level;
206
+ }
207
+
208
+ public getLevel(): Level {
209
+ return this.#threshold;
210
+ }
211
+
212
+ public async showSpinner(message?: string): Promise<void> {
213
+ await this.#progress.hideAll();
214
+ if (this.#threshold > Level.INFO) {
215
+ return;
216
+ }
217
+ await this.#spinner.show(message);
218
+ }
219
+
220
+ public async hideSpinner(): Promise<void> {
221
+ await this.#spinner.hide();
222
+ }
223
+
224
+ public async showProgressBar(
225
+ units: string,
226
+ message = "",
227
+ total = 100,
228
+ current = 0,
229
+ ): Promise<number> {
230
+ await this.#spinner.hide();
231
+ if (this.#threshold > Level.INFO) {
232
+ return -1;
233
+ }
234
+
235
+ return this.#progress.add(units, message, total, current);
236
+ }
237
+
238
+ public async hideProgressBar(handle: number): Promise<void> {
239
+ await this.#progress.hide(handle);
240
+ }
241
+
242
+ public async hideAllProgressBars(): Promise<void> {
243
+ await this.#progress.hideAll();
244
+ }
245
+
246
+ public updateProgressBar(
247
+ handle: number,
248
+ current: number,
249
+ message?: string,
250
+ ): void {
251
+ if (this.#threshold > Level.INFO) {
252
+ return;
253
+ }
254
+ this.#progress.update(handle, current, message);
255
+ }
256
+ }
@@ -0,0 +1,61 @@
1
+ import type Context from "../../api/Context.ts";
2
+ import LogLevelCommand from "./command/LogLevelCommand.ts";
3
+ import type {
4
+ ServiceInfo,
5
+ ServiceProvider,
6
+ } from "../../api/service/ServiceProvider.ts";
7
+ import PrinterService, {
8
+ PRINTER_SERVICE_ID,
9
+ } from "../../api/service/core/PrinterService.ts";
10
+ import DarkModeCommand from "./command/DarkModeCommand.ts";
11
+ import NoColorCommand from "./command/NoColorCommand.ts";
12
+ import type CLIConfig from "../../api/CLIConfig.ts";
13
+ import ShutdownService, {
14
+ SHUTDOWN_SERVICE_ID,
15
+ } from "../../api/service/core/ShutdownService.ts";
16
+
17
+ /**
18
+ * Provides a {@link PrinterService}.
19
+ */
20
+ export default class PrinterServiceProvider implements ServiceProvider {
21
+ readonly serviceId: string = PRINTER_SERVICE_ID;
22
+ readonly servicePriority: number;
23
+ readonly printerService: PrinterService;
24
+
25
+ /**
26
+ * Create an instance of the service provider with the specified details.
27
+ *
28
+ * @param servicePriority the priority of the service.
29
+ * @param printerService the PrinterService implementation to use.
30
+ */
31
+ public constructor(
32
+ servicePriority: number,
33
+ printerService: PrinterService,
34
+ ) {
35
+ this.servicePriority = servicePriority;
36
+ this.printerService = printerService;
37
+ }
38
+
39
+ public provide(_cliConfig: CLIConfig): Promise<ServiceInfo> {
40
+ return Promise.resolve({
41
+ service: this.printerService,
42
+ commands: [
43
+ new DarkModeCommand(this, this.servicePriority + 2),
44
+ new NoColorCommand(this, this.servicePriority + 1),
45
+ new LogLevelCommand(this, this.servicePriority),
46
+ ],
47
+ });
48
+ }
49
+
50
+ initService(context: Context): Promise<void> {
51
+ const shutdownService = context.getServiceById(
52
+ SHUTDOWN_SERVICE_ID,
53
+ ) as ShutdownService;
54
+ shutdownService.addShutdownListener(async () => {
55
+ await this.printerService.hideSpinner();
56
+ await this.printerService.hideAllProgressBars();
57
+ });
58
+
59
+ return Promise.resolve();
60
+ }
61
+ }
@@ -0,0 +1,43 @@
1
+ import type GlobalModifierCommand from "../../../api/command/GlobalModifierCommand.ts";
2
+ import type GlobalCommandArgument from "../../../api/argument/GlobalCommandArgument.ts";
3
+ import {
4
+ type ArgumentSingleValueType,
5
+ ArgumentValueTypeName,
6
+ } from "../../../api/argument/ArgumentValueTypes.ts";
7
+ import type Context from "../../../api/Context.ts";
8
+ import type PrinterServiceProvider from "../PrinterServiceProvider.ts";
9
+
10
+ /**
11
+ * Command allowing the specification of dark/light mode for {@link PrinterServiceProvider}.
12
+ */
13
+ export default class DarkModeCommand implements GlobalModifierCommand {
14
+ readonly name = "dark-mode";
15
+ readonly description = "Enable dark mode for output";
16
+ readonly enableConfiguration = true;
17
+ readonly argument: GlobalCommandArgument = {
18
+ type: ArgumentValueTypeName.BOOLEAN,
19
+ defaultValue: false,
20
+ configurationKey: "DARK_MODE",
21
+ };
22
+ readonly executePriority: number;
23
+
24
+ readonly #printerServiceProvider: PrinterServiceProvider;
25
+
26
+ public constructor(
27
+ printerServiceProvider: PrinterServiceProvider,
28
+ executePriority: number,
29
+ ) {
30
+ this.#printerServiceProvider = printerServiceProvider;
31
+ this.executePriority = executePriority;
32
+ }
33
+
34
+ public execute(
35
+ _context: Context,
36
+ argumentValue: ArgumentSingleValueType,
37
+ ): Promise<void> {
38
+ this.#printerServiceProvider.printerService!.darkMode =
39
+ argumentValue as boolean;
40
+
41
+ return Promise.resolve();
42
+ }
43
+ }
@@ -0,0 +1,68 @@
1
+ import type GlobalCommandArgument from "../../../api/argument/GlobalCommandArgument.ts";
2
+ import {
3
+ type ArgumentSingleValueType,
4
+ ArgumentValueTypeName,
5
+ } from "../../../api/argument/ArgumentValueTypes.ts";
6
+ import type GlobalModifierCommand from "../../../api/command/GlobalModifierCommand.ts";
7
+ import type Context from "../../../api/Context.ts";
8
+ import type PrinterServiceProvider from "../PrinterServiceProvider.ts";
9
+ import { Level } from "../../../api/service/core/PrinterService.ts";
10
+
11
+ /**
12
+ * Command allowing the setting of the log level for {@link PrinterServiceProvider}.
13
+ */
14
+ export default class LogLevelCommand implements GlobalModifierCommand {
15
+ readonly name = "log-level";
16
+ readonly description = "Set the logging threshold";
17
+ readonly enableConfiguration = true;
18
+ readonly argument: GlobalCommandArgument = {
19
+ type: ArgumentValueTypeName.STRING,
20
+ allowableValues: [
21
+ "DEBUG",
22
+ "INFO",
23
+ "WARN",
24
+ "ERROR",
25
+ ],
26
+ defaultValue: "INFO",
27
+ configurationKey: "LOG_LEVEL",
28
+ };
29
+ readonly executePriority: number;
30
+
31
+ readonly #printerServiceProvider: PrinterServiceProvider;
32
+
33
+ public constructor(
34
+ printerServiceProvider: PrinterServiceProvider,
35
+ executePriority: number,
36
+ ) {
37
+ this.#printerServiceProvider = printerServiceProvider;
38
+ this.executePriority = executePriority;
39
+ }
40
+
41
+ public execute(
42
+ _context: Context,
43
+ argumentValue: ArgumentSingleValueType,
44
+ ): Promise<void> {
45
+ const logLevel = argumentValue as string;
46
+
47
+ switch (logLevel) {
48
+ case "DEBUG":
49
+ return this.#printerServiceProvider.printerService!.setLevel(
50
+ Level.DEBUG,
51
+ );
52
+ case "INFO":
53
+ return this.#printerServiceProvider.printerService!.setLevel(
54
+ Level.INFO,
55
+ );
56
+ case "WARN":
57
+ return this.#printerServiceProvider.printerService!.setLevel(
58
+ Level.WARN,
59
+ );
60
+ case "ERROR":
61
+ return this.#printerServiceProvider.printerService!.setLevel(
62
+ Level.ERROR,
63
+ );
64
+ }
65
+
66
+ return Promise.resolve();
67
+ }
68
+ }
@@ -0,0 +1,43 @@
1
+ import type GlobalModifierCommand from "../../../api/command/GlobalModifierCommand.ts";
2
+ import type GlobalCommandArgument from "../../../api/argument/GlobalCommandArgument.ts";
3
+ import {
4
+ type ArgumentSingleValueType,
5
+ ArgumentValueTypeName,
6
+ } from "../../../api/argument/ArgumentValueTypes.ts";
7
+ import type Context from "../../../api/Context.ts";
8
+ import type PrinterServiceProvider from "../PrinterServiceProvider.ts";
9
+
10
+ /**
11
+ * Command allowing the disabling of color for {@link PrinterServiceProvider}.
12
+ */
13
+ export default class NoColorCommand implements GlobalModifierCommand {
14
+ readonly name = "no-color";
15
+ readonly description = "Disable color for output";
16
+ readonly enableConfiguration = true;
17
+ readonly argument: GlobalCommandArgument = {
18
+ type: ArgumentValueTypeName.BOOLEAN,
19
+ defaultValue: false,
20
+ configurationKey: "NO_COLOR",
21
+ };
22
+ readonly executePriority: number;
23
+
24
+ readonly #printerServiceProvider: PrinterServiceProvider;
25
+
26
+ public constructor(
27
+ printerServiceProvider: PrinterServiceProvider,
28
+ executePriority: number,
29
+ ) {
30
+ this.#printerServiceProvider = printerServiceProvider;
31
+ this.executePriority = executePriority;
32
+ }
33
+
34
+ public execute(
35
+ _context: Context,
36
+ argumentValue: ArgumentSingleValueType,
37
+ ): Promise<void> {
38
+ this.#printerServiceProvider.printerService!.colorEnabled =
39
+ !argumentValue as boolean;
40
+
41
+ return Promise.resolve();
42
+ }
43
+ }
@@ -0,0 +1,10 @@
1
+ const CSI = "\x1b[";
2
+
3
+ export const CLEAR_LINE = CSI + "2K";
4
+ export const CURSOR_LEFT = CSI + "G";
5
+ export const CURSOR_UP = CSI + "1A";
6
+ export const HIDE_CURSOR = CSI + "?25l";
7
+ export const SHOW_CURSOR = CSI + "?25h";
8
+ export const ITALIC_START = CSI + "3m";
9
+ export const ITALIC_END = CSI + "23m";
10
+ export const COLOR_END = CSI + "39m";
@@ -0,0 +1,14 @@
1
+ export enum Color {
2
+ PRIMARY,
3
+ SECONDARY,
4
+ EMPHASISED,
5
+ SELECTED,
6
+ YELLOW,
7
+ ORANGE,
8
+ RED,
9
+ MAGENTA,
10
+ VIOLET,
11
+ BLUE,
12
+ CYAN,
13
+ GREEN,
14
+ }