feat: add components
This commit is contained in:
61
components/component-console.js
Normal file
61
components/component-console.js
Normal file
@@ -0,0 +1,61 @@
|
||||
var System = java.lang.System;
|
||||
|
||||
var readLineEx = (prompt) => {
|
||||
var ret = null;
|
||||
while ((ret == null) || $STR(ret).trim() == '') {
|
||||
ret = readLine(prompt);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
var readLine = (prompt) => {
|
||||
print(prompt);
|
||||
return System.console().readLine();
|
||||
};
|
||||
|
||||
var readYNEx = (prompt) => {
|
||||
var ret = null;
|
||||
while (ret == null) {
|
||||
ret = readYN(prompt);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
var readYN = (prompt) => {
|
||||
print(prompt);
|
||||
var read = readLine();
|
||||
if ($STR(read).toLowerCase() == 'y') {
|
||||
return true;
|
||||
}
|
||||
if ($STR(read).toLowerCase() == 'n') {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var readListToMark = (prompt, mark) => {
|
||||
if (!(mark)) { throw 'Mark cannot be null or empty.'; }
|
||||
print(prompt);
|
||||
var list = [];
|
||||
while (true) {
|
||||
var ln = System.console().readLine();
|
||||
if ($STR(ln) == $STR(mark)) {
|
||||
return list;
|
||||
}
|
||||
list.push(ln);
|
||||
}
|
||||
};
|
||||
|
||||
var readListToCustomMark = (prompt) => {
|
||||
var mark = readLineEx(prompt);
|
||||
return readListToMark('', mark);
|
||||
};
|
||||
|
||||
if (typeof exports == 'object') {
|
||||
exports.readYN = readYN;
|
||||
exports.readYNEx = readYNEx;
|
||||
exports.readLine = readLine;
|
||||
exports.readLineEx = readLineEx;
|
||||
exports.readListToMark = readListToMark;
|
||||
exports.readListToCustomMark = readListToCustomMark;
|
||||
}
|
||||
Reference in New Issue
Block a user