11import { usePrefix , useCache , useCellar , useDownload , useOffLicense , useFetch , useConfig } from "hooks"
2- import { host , panic , pkg as pkgutils } from "utils"
2+ import { host , panic , pkg as pkgutils , undent } from "utils"
33import useLogger , { Logger , red , teal , gray , logJSON } from "hooks/useLogger.ts"
4- import { Installation , StowageNativeBottle } from "types"
4+ import { ExitError , Installation , StowageNativeBottle } from "types"
55import { crypto , toHashString } from "deno/crypto/mod.ts"
66import { Package } from "types"
77import Path from "path"
@@ -19,29 +19,37 @@ export default async function install(pkg: Package, logger?: Logger): Promise<In
1919 const tarball = useCache ( ) . path ( stowage )
2020 const shelf = tea_prefix . join ( pkg . project )
2121
22- if ( env . TEA_MAGIC === "prompt" ) {
22+ const pkg_prefix_str = ( pkg : Package ) => [
23+ gray ( usePrefix ( ) . prettyString ( ) ) ,
24+ pkg . project ,
25+ `${ gray ( 'v' ) } ${ pkg . version } `
26+ ] . join ( gray ( '/' ) )
27+
28+ if ( env . TEA_MAGIC === "prompt" ) {
29+ if ( ! Deno . isatty ( Deno . stdin . rid ) ) {
30+ throw new Error ( "TEA_MAGIC=prompt but stdin is not a tty" )
31+ }
32+
2333 do {
24- const val = prompt ( `┌ ⚠️ Tea requests to install ${ pkg . project } (v${ pkg . version } )\n└ \x1B[1mAllow?\x1B[0m [y/n]` ) ?. toLowerCase ( ) ;
25- // If val is undefined, there was no prompt given since this isn't an interactive tty
26- if ( ! val || val === "y" ) {
27- break ;
34+ const val = prompt ( undent `
35+ ┌ ⚠️ tea requests to install ${ pkg_prefix_str ( pkg ) }
36+ └ \x1B[1mallow?\x1B[0m [y/n]`
37+ ) ?. toLowerCase ( )
38+
39+ if ( val === "y" ) {
40+ break
2841 }
29- if ( val === "n" ) {
30- Deno . exit ( 1 ) ;
42+ if ( val === "n" ) {
43+ throw new ExitError ( 1 )
3144 }
32- }
33- while ( true )
45+ } while ( true )
3446 }
3547
3648 const log_install_msg = ( install : Installation , title = 'installed' ) => {
3749 if ( json ) {
3850 logJSON ( { status : title , pkg : pkgutils . str ( install . pkg ) } )
3951 } else {
40- const str = [
41- gray ( usePrefix ( ) . prettyString ( ) ) ,
42- install . pkg . project ,
43- `${ gray ( 'v' ) } ${ install . pkg . version } `
44- ] . join ( gray ( '/' ) )
52+ const str = pkg_prefix_str ( install . pkg )
4553 logger ! . replace ( `${ title } : ${ str } ` , { prefix : false } )
4654 }
4755 }
0 commit comments