@spencer-kit/coder-studio 0.4.5 → 0.4.6

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.
@@ -6870,7 +6870,8 @@ var init_manager3 = __esm({
6870
6870
  ...cmd.env,
6871
6871
  CODER_STUDIO_SESSION_ID: sessionId
6872
6872
  },
6873
- title: req.provider.displayName
6873
+ title: req.provider.displayName,
6874
+ themeBackground: req.themeBackground
6874
6875
  };
6875
6876
  const terminal = this.deps.terminalMgr.create(terminalSpec);
6876
6877
  const active = new ActiveSession({
@@ -12130,6 +12131,39 @@ var init_types2 = __esm({
12130
12131
  function isTerminalTraceEnabled() {
12131
12132
  return process.env.CODER_STUDIO_TERMINAL_TRACE === "1";
12132
12133
  }
12134
+ function parseHexColor(input) {
12135
+ const trimmed = input.trim();
12136
+ if (!trimmed.startsWith("#")) {
12137
+ return null;
12138
+ }
12139
+ const hex = trimmed.slice(1);
12140
+ let r;
12141
+ let g;
12142
+ let b;
12143
+ if (hex.length === 3) {
12144
+ r = Number.parseInt(hex[0] + hex[0], 16);
12145
+ g = Number.parseInt(hex[1] + hex[1], 16);
12146
+ b = Number.parseInt(hex[2] + hex[2], 16);
12147
+ } else if (hex.length === 6 || hex.length === 8) {
12148
+ r = Number.parseInt(hex.slice(0, 2), 16);
12149
+ g = Number.parseInt(hex.slice(2, 4), 16);
12150
+ b = Number.parseInt(hex.slice(4, 6), 16);
12151
+ } else {
12152
+ return null;
12153
+ }
12154
+ if ([r, g, b].some((v) => Number.isNaN(v))) {
12155
+ return null;
12156
+ }
12157
+ return { r, g, b };
12158
+ }
12159
+ function computeColorFgBg(background) {
12160
+ const rgb = parseHexColor(background);
12161
+ if (!rgb) {
12162
+ return void 0;
12163
+ }
12164
+ const luma = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
12165
+ return luma > 0.5 ? "0;15" : "15;0";
12166
+ }
12133
12167
  function countOccurrences(text, needle) {
12134
12168
  return text.split(needle).length - 1;
12135
12169
  }
@@ -12186,6 +12220,7 @@ var init_manager5 = __esm({
12186
12220
  */
12187
12221
  create(spec) {
12188
12222
  const id = generateId();
12223
+ const derivedColorFgBg = spec.themeBackground ? computeColorFgBg(spec.themeBackground) : void 0;
12189
12224
  const terminalEnv = {
12190
12225
  ...Object.fromEntries(
12191
12226
  Object.entries(process.env).filter((e) => e[1] != null)
@@ -12193,6 +12228,7 @@ var init_manager5 = __esm({
12193
12228
  TERM: "xterm-256color",
12194
12229
  COLORTERM: "truecolor",
12195
12230
  FORCE_COLOR: "3",
12231
+ ...derivedColorFgBg ? { COLORFGBG: derivedColorFgBg } : {},
12196
12232
  ...spec.env
12197
12233
  };
12198
12234
  let pty;
@@ -13737,7 +13773,8 @@ var init_terminal = __esm({
13737
13773
  workspaceId: z6.string(),
13738
13774
  cols: z6.number().int().positive().optional(),
13739
13775
  rows: z6.number().int().positive().optional(),
13740
- cwdPath: z6.string().optional()
13776
+ cwdPath: z6.string().optional(),
13777
+ themeBackground: z6.string().regex(/^#[0-9a-fA-F]{3,8}$/).optional()
13741
13778
  }),
13742
13779
  async (args, ctx) => {
13743
13780
  const workspace = ctx.workspaceMgr.get(args.workspaceId);
@@ -13775,7 +13812,8 @@ var init_terminal = __esm({
13775
13812
  title: shell.title,
13776
13813
  cwd,
13777
13814
  cols: args.cols ?? 120,
13778
- rows: args.rows ?? 30
13815
+ rows: args.rows ?? 30,
13816
+ themeBackground: args.themeBackground
13779
13817
  });
13780
13818
  return terminal;
13781
13819
  }
@@ -15347,7 +15385,8 @@ var init_session2 = __esm({
15347
15385
  z12.object({
15348
15386
  workspaceId: z12.string(),
15349
15387
  providerId: z12.string(),
15350
- draft: z12.string().optional()
15388
+ draft: z12.string().optional(),
15389
+ themeBackground: z12.string().regex(/^#[0-9a-fA-F]{3,8}$/).optional()
15351
15390
  }),
15352
15391
  async (args, ctx) => {
15353
15392
  const workspace = ctx.workspaceMgr.get(args.workspaceId);
@@ -15375,7 +15414,8 @@ var init_session2 = __esm({
15375
15414
  workspacePath: workspace.path,
15376
15415
  providerId: args.providerId,
15377
15416
  provider,
15378
- draft: args.draft
15417
+ draft: args.draft,
15418
+ themeBackground: args.themeBackground
15379
15419
  });
15380
15420
  }
15381
15421
  );