UNPKG

1.41 kBJavaScriptView Raw
1const CliReplView = require('@src/view/cli-repl-view');
2
3module.exports = class DialogReplView extends CliReplView {
4 /**
5 * Constructor for DialogReplView.
6 * @param {Object} configuration config object.
7 */
8 constructor(configuration) {
9 const conf = configuration || {};
10 conf.prettifyHeaderFooter = (arg) => {
11 const lines = arg.split('\n');
12 const terminalWidth = process.stdout.columns;
13 const halfWidth = Math.floor(terminalWidth / 2);
14 const bar = '='.repeat(terminalWidth);
15 const formattedLines = lines.map((line) => {
16 const paddedLine = ` ${line.trim()} `;
17 const offset = halfWidth - Math.floor(paddedLine.length / 2);
18 if (offset < 0) {
19 return `===${paddedLine}===`;
20 }
21 return bar.slice(0, offset) + paddedLine + bar.slice(offset + paddedLine.length);
22 });
23 return `\n${formattedLines.join('\n')}\n`;
24 };
25 super(conf);
26 }
27
28 /**
29 * Specify the record special command.
30 * @param {Function} func What function to execute when .record command is inputted.
31 */
32 registerRecordCommand(func) {
33 this.registerSpecialCommand(
34 'record',
35 'Record input utterances to a replay file of a specified name.',
36 func
37 );
38 }
39};