Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat(color): enhance color command with normalization for input values

zhengkailan2470e67f28bb
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/color.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/color.ts
index 899ad10bb4..02b92b642e 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/color.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/color.ts
@@ -1,8 +1,19 @@
import { addError, addInfo } from "../helpers.js";
import { CommandKind, type SlashCommand } from "../types.js";
-import { getAccentColorOptions } from "../../../ui/theme.js";
+import { getAccentColorOptions, type AccentColorName } from "../../../ui/theme.js";
const COLOR_OPTIONS = getAccentColorOptions();
+const RESET_ALIASES = ["default", "reset", "none", "gray", "grey"] as const;
+
+function normalizeColorArg(value: string): AccentColorName | null {
+ if (RESET_ALIASES.includes(value as (typeof RESET_ALIASES)[number])) {
+ return "default";
+ }
+ if (COLOR_OPTIONS.includes(value as AccentColorName)) {
+ return value as AccentColorName;
+ }
+ return null;
+}
export function createColorCommand(): SlashCommand {
return {
@@ -28,7 +39,8 @@ export function createColorCommand(): SlashCommand {
);
return;
}
- if (!COLOR_OPTIONS.includes(value as (typeof COLOR_OPTIONS)[number])) {
+ const normalizedColor = normalizeColorArg(value);
+ if (!normalizedColor) {
ctx.addItem(
addError(
ctx.sessionId,
@@ -37,8 +49,8 @@ export function createColorCommand(): SlashCommand {
);
return;
}
- ctx.setAccentColor(value as (typeof COLOR_OPTIONS)[number]);
- ctx.addItem(addInfo(ctx.sessionId, `Session accent color set to ${value}`, "c"));
+ ctx.setAccentColor(normalizedColor);
+ ctx.addItem(addInfo(ctx.sessionId, `Session accent color set to ${normalizedColor}`, "c"));
},
};
}