-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
createPrompt, | ||
useState, | ||
useKeypress, | ||
isEnterKey, | ||
usePrefix, | ||
makeTheme, | ||
type Theme, | ||
type Status, | ||
} from "@inquirer/core"; | ||
import type { PartialDeep } from "@inquirer/type"; | ||
import chalk from "chalk"; | ||
import figures from "@inquirer/figures"; | ||
|
||
type ConfirmConfig = { | ||
message?: string; | ||
theme?: PartialDeep<Theme>; | ||
}; | ||
|
||
export default createPrompt<boolean, ConfirmConfig>((config, done) => { | ||
const [status, setStatus] = useState<Status>("idle"); | ||
const theme = makeTheme( | ||
{ | ||
prefix: { | ||
idle: chalk.blue(figures.info), | ||
done: chalk.green(figures.tick), | ||
}, | ||
}, | ||
config.theme, | ||
); | ||
const prefix = usePrefix({ status, theme }); | ||
|
||
useKeypress((key) => { | ||
if (isEnterKey(key)) { | ||
setStatus("done"); | ||
done(true); | ||
} | ||
}); | ||
|
||
const message = theme.style.message( | ||
config.message ?? "Press Enter to continue...", | ||
status, | ||
); | ||
return `${prefix} ${message}`; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters