Skip to content

Commit b5c00f9

Browse files
feat: integrate emoji detection in preview command
• Update displayCommitList and displayCommitDetails to strip emojis • Detect emoji support independently in preview command • Adapt commit subject and body display based on terminal capabilities • Ensure clean output on non-emoji terminals
1 parent 1f8afac commit b5c00f9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/cli/commands/preview/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { Command } from "commander";
88
import { Logger } from "../../../lib/logger.js";
9+
import { detectEmojiSupport } from "../../../lib/util/emoji.js";
910
import {
1011
isGitRepository,
1112
getCurrentBranch,
@@ -93,6 +94,9 @@ async function previewAction(options: {
9394
process.exit(0);
9495
}
9596

97+
// Detect emoji support for display
98+
const emojiModeActive = detectEmojiSupport();
99+
96100
// Main loop
97101
let exit = false;
98102
let viewingDetails = false;
@@ -105,7 +109,7 @@ async function previewAction(options: {
105109

106110
if (viewingDetails && currentDetailCommit) {
107111
// Detail view
108-
displayCommitDetails(currentDetailCommit, showBody, showFiles);
112+
displayCommitDetails(currentDetailCommit, showBody, showFiles, emojiModeActive);
109113
console.log(
110114
` ${textColors.white("Press")} ${textColors.brightYellow("b")} ${textColors.white("to toggle body,")} ${textColors.brightYellow("f")} ${textColors.white("to toggle files,")} ${textColors.brightYellow("d")} ${textColors.white("for diff,")} ${textColors.brightYellow("r")} ${textColors.white("to revert,")} ${textColors.brightYellow("←")} ${textColors.white("to go back")}`,
111115
);
@@ -188,6 +192,7 @@ async function previewAction(options: {
188192
hasMore,
189193
hasPreviousPage,
190194
hasMorePages,
195+
emojiModeActive,
191196
);
192197

193198
const action = await waitForListAction(

src/cli/commands/preview/prompts.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { select, isCancel } from "@clack/prompts";
88
import { labelColors, textColors } from "../init/colors.js";
9+
import { formatForDisplay } from "../../../lib/util/emoji.js";
910
import type { CommitInfo } from "../shared/types.js";
1011
import { getCommitDetails, getCommitDiff } from "../shared/git-operations.js";
1112
import readline from "readline";
@@ -46,6 +47,7 @@ export function displayCommitList(
4647
hasMore: boolean,
4748
hasPreviousPage: boolean = false,
4849
hasMorePages: boolean = false,
50+
emojiModeActive: boolean = true,
4951
): void {
5052
console.log();
5153
console.log(
@@ -64,10 +66,11 @@ export function displayCommitList(
6466
const commit = commits[i];
6567
const number = i.toString();
6668
const mergeIndicator = commit.isMerge ? " [Merge]" : "";
69+
const displaySubject = formatForDisplay(commit.subject, emojiModeActive);
6770
const truncatedSubject =
68-
commit.subject.length > 50
69-
? commit.subject.substring(0, 47) + "..."
70-
: commit.subject;
71+
displaySubject.length > 50
72+
? displaySubject.substring(0, 47) + "..."
73+
: displaySubject;
7174

7275
console.log(
7376
` ${textColors.brightCyan(`[${number}]`)} ${textColors.brightWhite(commit.shortHash)} ${truncatedSubject}${mergeIndicator}`,
@@ -124,14 +127,16 @@ export function displayCommitDetails(
124127
commit: CommitInfo,
125128
showBody: boolean = true,
126129
showFiles: boolean = true,
130+
emojiModeActive: boolean = true,
127131
): void {
128132
console.log();
129133
console.log(
130134
`${label("detail", "green")} ${textColors.pureWhite("Commit Details")}`,
131135
);
132136
console.log();
133137
console.log(` ${textColors.brightWhite("Hash:")} ${commit.hash}`);
134-
console.log(` ${textColors.brightWhite("Subject:")} ${commit.subject}`);
138+
const displaySubject = formatForDisplay(commit.subject, emojiModeActive);
139+
console.log(` ${textColors.brightWhite("Subject:")} ${displaySubject}`);
135140
console.log();
136141
console.log(
137142
` ${textColors.brightWhite("Author:")} ${commit.author.name} <${commit.author.email}>`,
@@ -174,7 +179,8 @@ export function displayCommitDetails(
174179
if (showBody) {
175180
if (commit.body) {
176181
console.log(` ${textColors.brightWhite("Body:")}`);
177-
const bodyLines = commit.body.split("\n");
182+
const displayBody = formatForDisplay(commit.body, emojiModeActive);
183+
const bodyLines = displayBody.split("\n");
178184
bodyLines.forEach((line) => {
179185
console.log(` ${line}`);
180186
});

0 commit comments

Comments
 (0)