/* * Copyright (C) SapphireCode - All Rights Reserved * This file is part of Snippeteer which is released under BSD-3-Clause. * See file 'LICENSE' for full license details. * Created by Timo Hocker , June 2020 */ import { StringOption } from '@sapphirecode/console-app'; export class Menu { private _options: Recordvoid|Promise> = {}; private _title: string; public constructor (title: string) { this._title = title; } public async run (): Promise { const options = Object.keys (this._options); const selected = await (new StringOption ({ name: 'menu_select', message: this._title, sources: { console: false }, exit_on_interrupt: true, preset: options })) .parse (); if (typeof this._options[selected] !== 'undefined') await new Promise (this._options[selected]); } public register_option (name:string, callback:()=>void|Promise): void { this._options[name] = callback; } }