|
1 | 1 | import { spawn } from "child_process"; |
| 2 | +import React from "react"; |
2 | 3 | import * as fs from "fs"; |
3 | 4 | import * as os from "os"; |
4 | 5 | import * as path from "path"; |
5 | | -import * as readline from "readline/promises"; |
| 6 | +import { render, type Instance } from "ink"; |
| 7 | +import chalk from "chalk"; |
| 8 | +import { UpdatePrompt, type UpdatePromptChoice } from "./ui/UpdatePrompt"; |
6 | 9 |
|
7 | 10 | export type PackageInfo = { |
8 | 11 | name: string; |
@@ -52,7 +55,7 @@ export async function promptForPendingUpdate(packageInfo: PackageInfo): Promise< |
52 | 55 | const ok = await runNpmInstallGlobal(installSpec); |
53 | 56 | if (ok) { |
54 | 57 | writeUpdateState({ ...state, pending: null }); |
55 | | - process.stdout.write("Deep Code has been updated. Please restart the CLI to use the new version.\n"); |
| 58 | + process.stdout.write(`\n${chalk.red("Deep Code has been updated. Please restart the CLI to use the new version.")}\n\n`); |
56 | 59 | } |
57 | 60 | return { installed: ok }; |
58 | 61 | } |
@@ -129,29 +132,28 @@ async function promptUpdateChoice({ |
129 | 132 | latestVersion: string; |
130 | 133 | installCommand: string; |
131 | 134 | }): Promise<"install" | "ignore-once" | "ignore-version"> { |
132 | | - const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); |
133 | | - try { |
134 | | - process.stdout.write(`Deep Code latest version has been released: ${currentVersion} -> ${latestVersion}\n`); |
135 | | - process.stdout.write(`1. Install the latest version with \`${installCommand}\`\n`); |
136 | | - process.stdout.write("2. Ignore once\n"); |
137 | | - process.stdout.write(`3. Ignore this version (${latestVersion})\n`); |
138 | | - |
139 | | - while (true) { |
140 | | - const answer = (await rl.question("Choose 1, 2, or 3: ")).trim(); |
141 | | - if (answer === "1") { |
142 | | - return "install"; |
143 | | - } |
144 | | - if (answer === "2" || answer === "") { |
145 | | - return "ignore-once"; |
146 | | - } |
147 | | - if (answer === "3") { |
148 | | - return "ignore-version"; |
| 135 | + return new Promise<UpdatePromptChoice>((resolve) => { |
| 136 | + let selected = false; |
| 137 | + let instance: Instance | null = null; |
| 138 | + const handleSelect = (choice: UpdatePromptChoice): void => { |
| 139 | + if (selected) { |
| 140 | + return; |
149 | 141 | } |
150 | | - process.stdout.write("Please enter 1, 2, or 3.\n"); |
151 | | - } |
152 | | - } finally { |
153 | | - rl.close(); |
154 | | - } |
| 142 | + selected = true; |
| 143 | + resolve(choice); |
| 144 | + instance?.unmount(); |
| 145 | + }; |
| 146 | + |
| 147 | + instance = render( |
| 148 | + React.createElement(UpdatePrompt, { |
| 149 | + currentVersion, |
| 150 | + latestVersion, |
| 151 | + installCommand, |
| 152 | + onSelect: handleSelect |
| 153 | + }), |
| 154 | + { exitOnCtrlC: false } |
| 155 | + ); |
| 156 | + }); |
155 | 157 | } |
156 | 158 |
|
157 | 159 | async function runNpmInstallGlobal(installSpec: string): Promise<boolean> { |
|
0 commit comments