@imisbahk/hive 0.1.1 → 0.1.3

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.
@@ -0,0 +1,88 @@
1
+ import chalk, { type ChalkInstance } from "chalk";
2
+
3
+ import {
4
+ closeHiveDatabase,
5
+ getMetaValue,
6
+ openHiveDatabase,
7
+ } from "../storage/db.js";
8
+
9
+ export const DEFAULT_THEME_NAME = "amber";
10
+ export const DEFAULT_THEME_HEX = "#FFA500";
11
+
12
+ export const BUILT_IN_THEMES = {
13
+ amber: "#FFA500",
14
+ cyan: "#00BCD4",
15
+ rose: "#FF4081",
16
+ slate: "#90A4AE",
17
+ green: "#00E676",
18
+ } as const;
19
+
20
+ export const HEX_COLOR_PATTERN = /^#[0-9A-Fa-f]{6}$/;
21
+
22
+ export type BuiltInThemeName = keyof typeof BUILT_IN_THEMES;
23
+ export type ThemeName = BuiltInThemeName | "custom";
24
+
25
+ export interface HiveTheme {
26
+ name: ThemeName;
27
+ hex: string;
28
+ accent: ChalkInstance;
29
+ }
30
+
31
+ export function applyTheme(hex: string): ChalkInstance {
32
+ const normalizedHex = normalizeHex(hex);
33
+ return chalk.hex(normalizedHex);
34
+ }
35
+
36
+ export function getTheme(): HiveTheme {
37
+ let db: ReturnType<typeof openHiveDatabase> | null = null;
38
+
39
+ try {
40
+ db = openHiveDatabase();
41
+ const storedName = getMetaValue(db, "theme");
42
+ const storedHex = getMetaValue(db, "theme_hex");
43
+ return resolveTheme(storedName, storedHex);
44
+ } catch {
45
+ return makeTheme(DEFAULT_THEME_NAME, DEFAULT_THEME_HEX);
46
+ } finally {
47
+ if (db) {
48
+ closeHiveDatabase(db);
49
+ }
50
+ }
51
+ }
52
+
53
+ export function isValidHexColor(value: string): boolean {
54
+ return HEX_COLOR_PATTERN.test(value);
55
+ }
56
+
57
+ function resolveTheme(storedName: string | null, storedHex: string | null): HiveTheme {
58
+ if (isBuiltInTheme(storedName)) {
59
+ return makeTheme(storedName, BUILT_IN_THEMES[storedName]);
60
+ }
61
+
62
+ if (storedName === "custom" && storedHex && isValidHexColor(storedHex)) {
63
+ return makeTheme("custom", storedHex);
64
+ }
65
+
66
+ return makeTheme(DEFAULT_THEME_NAME, DEFAULT_THEME_HEX);
67
+ }
68
+
69
+ function makeTheme(name: ThemeName, hex: string): HiveTheme {
70
+ const normalizedHex = normalizeHex(hex);
71
+ return {
72
+ name,
73
+ hex: normalizedHex,
74
+ accent: applyTheme(normalizedHex),
75
+ };
76
+ }
77
+
78
+ function normalizeHex(value: string): string {
79
+ if (!isValidHexColor(value)) {
80
+ return DEFAULT_THEME_HEX;
81
+ }
82
+
83
+ return value.toUpperCase();
84
+ }
85
+
86
+ function isBuiltInTheme(value: string | null): value is BuiltInThemeName {
87
+ return value !== null && value in BUILT_IN_THEMES;
88
+ }
package/src/cli/ui.ts CHANGED
@@ -3,6 +3,8 @@ import process from "node:process";
3
3
 
4
4
  import chalk from "chalk";
5
5
 
6
+ import { getTheme } from "./theme.js";
7
+
6
8
  const WORDMARK_LINES = [
7
9
  " ██╗ ██╗██╗██╗ ██╗███████╗",
8
10
  " ██║ ██║██║██║ ██║██╔════╝",
@@ -21,9 +23,10 @@ let cachedVersion: string | null = null;
21
23
  export function renderHiveHeader(pageTitle?: string): void {
22
24
  const terminalWidth = getTerminalWidth();
23
25
  const separator = "─".repeat(getSeparatorWidth(terminalWidth));
26
+ const accent = getTheme().accent;
24
27
 
25
28
  for (const line of WORDMARK_LINES) {
26
- console.log(chalk.bold.whiteBright(centerText(line, terminalWidth)));
29
+ console.log(accent.bold(centerText(line, terminalWidth)));
27
30
  }
28
31
 
29
32
  console.log("");
@@ -34,12 +37,13 @@ export function renderHiveHeader(pageTitle?: string): void {
34
37
  ? `${COMMAND_CENTRE_LABEL} · ${normalizedTitle}`
35
38
  : COMMAND_CENTRE_LABEL;
36
39
 
37
- console.log(chalk.whiteBright(centerText(commandCentreTitle, terminalWidth)));
38
- console.log(chalk.dim(centerText(separator, terminalWidth)));
40
+ console.log(accent(centerText(commandCentreTitle, terminalWidth)));
41
+ console.log(accent(centerText(separator, terminalWidth)));
39
42
  }
40
43
 
41
44
  export function renderSuccess(message: string): void {
42
- console.log(chalk.green(message));
45
+ const accent = getTheme().accent;
46
+ console.log(`${accent("✓")} ${message}`);
43
47
  }
44
48
 
45
49
  export function renderError(message: string): void {
@@ -47,7 +51,8 @@ export function renderError(message: string): void {
47
51
  }
48
52
 
49
53
  export function renderStep(message: string): void {
50
- console.log(chalk.whiteBright(message));
54
+ const accent = getTheme().accent;
55
+ console.log(`${accent("›")} ${message}`);
51
56
  }
52
57
 
53
58
  export function renderInfo(message: string): void {
@@ -55,12 +60,14 @@ export function renderInfo(message: string): void {
55
60
  }
56
61
 
57
62
  export function renderSeparator(text?: string): void {
63
+ const accent = getTheme().accent;
64
+
58
65
  if (text) {
59
- console.log(chalk.dim(text));
66
+ console.log(accent(text));
60
67
  return;
61
68
  }
62
69
 
63
- console.log(chalk.dim("─".repeat(getSeparatorWidth(getTerminalWidth()))));
70
+ console.log(accent("─".repeat(getSeparatorWidth(getTerminalWidth()))));
64
71
  }
65
72
 
66
73
  function getCliVersion(): string {