@s-hiroshi/bks
Version:
Cli bookmarks application
67 lines • 2.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HistoryControl = void 0;
const inquirer = require("inquirer");
const fs = require("fs");
const createChoices_1 = require("../service/createChoices");
// export class HistoryControl implements Control {
class HistoryControl {
constructor(reader) {
this.reader = reader;
this.controlCharactor = "history";
this.increment = 10;
}
getControlCharactor() {
return this.controlCharactor;
}
async execute(query) {
let histories = this.reader.read(0, 10);
this.start = 0;
const choices = (0, createChoices_1.createChoices)(histories, ["Exit", "Next", "Prev"]);
return this.choice(choices);
}
async choice(choices) {
const choiced = await inquirer
.prompt([
{
type: "list",
name: "context",
message: "Which one do you want to open",
choices: choices,
loop: false,
},
])
.then((answer) => {
return answer.context;
});
if (choiced == "Next") {
this.start += this.increment;
this.choice((0, createChoices_1.createChoices)(this.read(this.start, this.increment, false), [
"Exit",
"Next",
"Prev",
]));
}
if (choiced == "Prev") {
this.choice((0, createChoices_1.createChoices)(this.read(this.start, this.increment, true), [
"Exit",
"Next",
"Prev",
]));
this.start -= this.increment;
}
if (choiced !== "Exit") {
return;
}
}
read(start, offset, isReverse) {
if (isReverse) {
return this.reader.readReverse(start, offset);
}
else {
return this.reader.read(start, offset);
}
}
}
exports.HistoryControl = HistoryControl;
//# sourceMappingURL=HistoryControl.js.map