diff --git a/package-lock.json b/package-lock.json index 6252833..af28478 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gitbun", - "version": "1.4.0", + "version": "1.12.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gitbun", - "version": "1.4.0", + "version": "1.12.1", "license": "MIT", "dependencies": { "chalk": "^5.6.2", diff --git a/src/index.ts b/src/index.ts index 65735b7..6aca151 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,7 @@ import { isOllamaRunning, getBestModel } from "./llm/checkOllama"; import { analyzeSemanticChanges } from "./analyzer/semanticAnalyzer"; import { SemanticEvent } from "./analyzer/semanticTypes"; import { ValidationError, CancellationError } from "./utils/errors"; +import { colorizeCommitMessage } from "./utils/commitColors"; interface CliOptions { ai?: boolean; @@ -218,7 +219,7 @@ export async function run(options: CliOptions) { // Dry run if (options.dryRun) { - console.log("\n" + commitMessage + "\n"); + console.log("\n" + colorizeCommitMessage(commitMessage) + "\n"); process.exit(0); } diff --git a/src/ui/interactive.ts b/src/ui/interactive.ts index 2bab032..47849e3 100644 --- a/src/ui/interactive.ts +++ b/src/ui/interactive.ts @@ -1,7 +1,8 @@ import inquirer from "inquirer"; +import { colorizeCommitMessage } from "../utils/commitColors"; export async function confirmCommit(message: string): Promise { - console.log("\n" + message + "\n"); + console.log("\n" + colorizeCommitMessage(message) + "\n"); const { action } = await inquirer.prompt([ { diff --git a/src/utils/commitColors.ts b/src/utils/commitColors.ts new file mode 100644 index 0000000..3c9e2a5 --- /dev/null +++ b/src/utils/commitColors.ts @@ -0,0 +1,43 @@ +import chalk from "chalk"; + +/** + * Color theme map for conventional commit types. + * Each key maps to a chalk color function used to style + * the commit type prefix in terminal output. + */ +const commitTypeTheme: Record string> = { + feat: chalk.green, + fix: chalk.red, + docs: chalk.blue, + refactor: chalk.yellow, + test: chalk.cyan, + chore: chalk.magenta, + build: chalk.hex("#FFA500"), // orange + ci: chalk.hex("#FFA500"), // orange + perf: chalk.greenBright, + style: chalk.blueBright, + revert: chalk.redBright, +}; + +/** + * Colorizes the commit-type prefix of a conventional commit message + * for terminal display. The raw commit string is never modified — + * only the text printed to stdout receives ANSI colors. + * + * @param message - A conventional commit message string. + * @returns The message with a colorized type prefix. + */ + +export function colorizeCommitMessage(message: string): string { + const match = message.match(/^([a-z]+)(\([^)]*\))?(!?):/); + if (!match) return message; + + const type = match[1]; + const colorFn = commitTypeTheme[type]; + if (!colorFn) return message; + + const prefix = match[0].slice(0, -1); + const rest = message.slice(prefix.length); + + return colorFn(prefix) + rest; +}