Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/ui/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import inquirer from "inquirer";
import { colorizeCommitMessage } from "../utils/commitColors";

export async function confirmCommit(message: string): Promise<string | null> {
console.log("\n" + message + "\n");
console.log("\n" + colorizeCommitMessage(message) + "\n");

const { action } = await inquirer.prompt([
{
Expand Down
43 changes: 43 additions & 0 deletions src/utils/commitColors.ts
Original file line number Diff line number Diff line change
@@ -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, (text: string) => 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;
}