Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Ctrl + C message to interactive screens #173

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cli/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -225,6 +225,7 @@ const inspectPrint: InspectPrint = {
const res = await api.inspect();

console.clear();
showInteractiveMessage();

const p = new Table({
columns: [
Expand Down
38 changes: 26 additions & 12 deletions src/cli/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,41 @@ 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<string> =>
prompt<{ method: string }>([
export const loginSelection = (methods: string[]): Promise<string> => {
showInteractiveMessage();
return prompt<{ method: string }>([
{
type: 'list',
name: 'method',
message: 'Select the login method',
choices: methods
}
]).then((res: { method: string }) => res.method);
};

export const fileSelection = (
message: string,
files: string[] = []
): Promise<string[]> =>
prompt<{ scripts: string[] }>([
): Promise<string[]> => {
showInteractiveMessage();

return prompt<{ scripts: string[] }>([
{
type: 'checkbox',
name: 'scripts',
message,
choices: files
}
]).then((res: { scripts: string[] }) => res.scripts);
};

export const languageSelection = (
languages: LanguageId[] = []
): Promise<LanguageId[]> =>
prompt<{ langs: string[] }>([
): Promise<LanguageId[]> => {
showInteractiveMessage();
return prompt<{ langs: string[] }>([
{
type: 'checkbox',
name: 'langs',
Expand All @@ -42,39 +49,46 @@ export const languageSelection = (
]).then((res: { langs: string[] }) =>
res.langs.map(lang => DisplayNameToLanguageId[lang])
);
};

export const planSelection = (
message: string,
availablePlans: string[]
): Promise<Plans> =>
prompt<{ plan: Plans }>([
): Promise<Plans> => {
showInteractiveMessage();
return prompt<{ plan: Plans }>([
{
type: 'list',
name: 'plan',
message,
choices: availablePlans
}
]).then((res: { plan: Plans }) => res.plan);
};

export const listSelection = (
list: string[] | { name: string; value: string }[],
message: string
): Promise<string> =>
prompt<{ container: string }>([
): Promise<string> => {
showInteractiveMessage();
return prompt<{ container: string }>([
{
type: 'list',
name: 'container',
message,
choices: list
}
]).then((res: { container: string }) => res.container);
};

export const consentSelection = (message: string): Promise<boolean> =>
prompt<{ consent: boolean }>([
export const consentSelection = (message: string): Promise<boolean> => {
showInteractiveMessage();
return prompt<{ consent: boolean }>([
{
type: 'confirm',
name: 'consent',
message,
default: false
}
]).then((res: { consent: boolean }) => res.consent);
};
9 changes: 9 additions & 0 deletions src/tty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
};