forked from jfraboni/javascript-thinking-in-objects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.js
More file actions
70 lines (58 loc) · 1.86 KB
/
view.js
File metadata and controls
70 lines (58 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use-strict';
const
Table = require('cli-table'),
prmpt = require("prompt"),
deepExtend = require('deep-extend'),
EventEmitter = require('events').EventEmitter;
/**
* makeMenu A factory that returns a menu object capable of prompting a user
* for input. On input, dispatches the 'userInput' event along with the input.
* @param {String} message The menu selection text to be shown to the user,
* usually someting like (1) Show, (2) Add, (q) Quit:.
* @param {RegEx} validator A regular expression to validate user input.
* @extends {events.EventEmitter}
*/
function makeMenu(message, validator) {
var menuProperties = [
{
name: 'input',
required: true,
message: message,
validator: validator
}
];
// TODO 11 : Create the menu object returned by the makeMenu factory //
// END TODO 11
}
module.exports.makeMenu = makeMenu;
function makeTable(headers) {
var _table = {
show: function(values) {
var table = createFormattedTable(headers);
table.push.apply(table, values);
console.log(table.toString());
}
}
return _table;
}
module.exports.makeTable = makeTable;
/**
* A private utility function that creates and returns a table
* object formatted with the given Array of String as headers.
*/
function createFormattedTable (headers) {
var chars = {
'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗',
'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚',
'bottom-right': '╝', 'left': '║', 'left-mid': '╟', 'mid': '─',
'mid-mid': '┼', 'right': '║', 'right-mid': '╢', 'middle': '│'
};
return new Table({
head: headers,
chars: chars
});
}
function onErr(err) {
console.log(err);
return 1;
}