File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
packages/cli/src/ui/utils Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 isSlashCommand ,
1414 copyToClipboard ,
1515 getUrlOpenCommand ,
16+ CodePage ,
1617} from './commandUtils.js' ;
1718
1819// Mock child_process
@@ -188,7 +189,10 @@ describe('commandUtils', () => {
188189
189190 await copyToClipboard ( testText ) ;
190191
191- expect ( mockSpawn ) . toHaveBeenCalledWith ( 'clip' , [ ] ) ;
192+ expect ( mockSpawn ) . toHaveBeenCalledWith ( 'cmd' , [
193+ '/c' ,
194+ `chcp ${ CodePage . UTF8 } >nul && clip` ,
195+ ] ) ;
192196 expect ( mockChild . stdin . write ) . toHaveBeenCalledWith ( testText ) ;
193197 expect ( mockChild . stdin . end ) . toHaveBeenCalled ( ) ;
194198 } ) ;
Original file line number Diff line number Diff line change 77import type { SpawnOptions } from 'node:child_process' ;
88import { spawn } from 'node:child_process' ;
99
10+ /**
11+ * Common Windows console code pages (CP) used for encoding conversions.
12+ *
13+ * @remarks
14+ * - `UTF8` (65001): Unicode (UTF-8) — recommended for cross-language scripts.
15+ * - `GBK` (936): Simplified Chinese — default on most Chinese Windows systems.
16+ * - `BIG5` (950): Traditional Chinese.
17+ * - `LATIN1` (1252): Western European — default on many Western systems.
18+ */
19+ export const CodePage = {
20+ UTF8 : 65001 ,
21+ GBK : 936 ,
22+ BIG5 : 950 ,
23+ LATIN1 : 1252 ,
24+ } as const ;
25+
26+ export type CodePage = ( typeof CodePage ) [ keyof typeof CodePage ] ;
1027/**
1128 * Checks if a query string potentially represents an '@' command.
1229 * It triggers if the query starts with '@' or contains '@' preceded by whitespace
@@ -80,7 +97,7 @@ export const copyToClipboard = async (text: string): Promise<void> => {
8097
8198 switch ( process . platform ) {
8299 case 'win32' :
83- return run ( 'clip ' , [ ] ) ;
100+ return run ( 'cmd ' , [ '/c' , `chcp ${ CodePage . UTF8 } >nul && clip` ] ) ;
84101 case 'darwin' :
85102 return run ( 'pbcopy' , [ ] ) ;
86103 case 'linux' :
You can’t perform that action at this time.
0 commit comments