diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index b03be72..244ecfd 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -5,10 +5,10 @@ import chalk from 'chalk'; import { Table } from 'console-table-printer'; import { OpenAPIV3 } from 'openapi-types'; import { Config } from '../config'; +import { showInteractiveMessage } from '../tty'; import { sleep } from './../utils'; import args, { InspectFormat } from './args'; import { error } from './messages'; - interface row { Deployments: string; Status: string; @@ -225,6 +225,7 @@ const inspectPrint: InspectPrint = { const res = await api.inspect(); console.clear(); + showInteractiveMessage(); const p = new Table({ columns: [ diff --git a/src/cli/selection.ts b/src/cli/selection.ts index 03142fd..452392f 100644 --- a/src/cli/selection.ts +++ b/src/cli/selection.ts @@ -5,9 +5,11 @@ import { } from '@metacall/protocol/language'; import { Plans } from '@metacall/protocol/plan'; import { prompt } from 'inquirer'; +import { showInteractiveMessage } from '../tty'; -export const loginSelection = (methods: string[]): Promise => - prompt<{ method: string }>([ +export const loginSelection = (methods: string[]): Promise => { + showInteractiveMessage(); + return prompt<{ method: string }>([ { type: 'list', name: 'method', @@ -15,12 +17,15 @@ export const loginSelection = (methods: string[]): Promise => choices: methods } ]).then((res: { method: string }) => res.method); +}; export const fileSelection = ( message: string, files: string[] = [] -): Promise => - prompt<{ scripts: string[] }>([ +): Promise => { + showInteractiveMessage(); + + return prompt<{ scripts: string[] }>([ { type: 'checkbox', name: 'scripts', @@ -28,11 +33,13 @@ export const fileSelection = ( choices: files } ]).then((res: { scripts: string[] }) => res.scripts); +}; export const languageSelection = ( languages: LanguageId[] = [] -): Promise => - prompt<{ langs: string[] }>([ +): Promise => { + showInteractiveMessage(); + return prompt<{ langs: string[] }>([ { type: 'checkbox', name: 'langs', @@ -42,12 +49,14 @@ export const languageSelection = ( ]).then((res: { langs: string[] }) => res.langs.map(lang => DisplayNameToLanguageId[lang]) ); +}; export const planSelection = ( message: string, availablePlans: string[] -): Promise => - prompt<{ plan: Plans }>([ +): Promise => { + showInteractiveMessage(); + return prompt<{ plan: Plans }>([ { type: 'list', name: 'plan', @@ -55,12 +64,14 @@ export const planSelection = ( choices: availablePlans } ]).then((res: { plan: Plans }) => res.plan); +}; export const listSelection = ( list: string[] | { name: string; value: string }[], message: string -): Promise => - prompt<{ container: string }>([ +): Promise => { + showInteractiveMessage(); + return prompt<{ container: string }>([ { type: 'list', name: 'container', @@ -68,9 +79,11 @@ export const listSelection = ( choices: list } ]).then((res: { container: string }) => res.container); +}; -export const consentSelection = (message: string): Promise => - prompt<{ consent: boolean }>([ +export const consentSelection = (message: string): Promise => { + showInteractiveMessage(); + return prompt<{ consent: boolean }>([ { type: 'confirm', name: 'consent', @@ -78,3 +91,4 @@ export const consentSelection = (message: string): Promise => default: false } ]).then((res: { consent: boolean }) => res.consent); +}; diff --git a/src/tty.ts b/src/tty.ts index 456c8d5..cb71032 100644 --- a/src/tty.ts +++ b/src/tty.ts @@ -10,3 +10,12 @@ export const isInteractive = () => { return process.stdin.isTTY === true; }; + +export const showInteractiveMessage = (): void => { + const isTTY: boolean = process.stdout.isTTY; + const isInteractiveMode: boolean = isInteractive(); + + if (isTTY || isInteractiveMode) { + console.log('Press Ctrl+C to exit'); + } +};