UNPKG

jack-cli

Version:

Chop through that Git log wicked fast!

168 lines 8.41 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var actions_1 = require("../state/actions"); var store_1 = require("../state/store"); var types_1 = require("../types/types"); var stash_1 = require("../util/stash"); var interface_elements_1 = require("./interface-elements"); var notification_1 = require("./notification"); var search_bar_1 = require("./search-bar"); var keys_def_1 = require("../util/keys-def"); var search_1 = require("../util/search"); exports.getCommitListElement = function () { var commitListElement = interface_elements_1.getListElement({ bottom: 0, left: 0, name: 'commitLogContainer', right: 0, style: { selected: { bg: '#555', }, }, tags: true, top: 0, }); var doUpdateIndex = function (action) { var interval = stash_1.stash.has(stash_1.NAV_INTERVAL) ? stash_1.stash.get(stash_1.NAV_INTERVAL) : 1; action(interval); if (stash_1.stash.has(stash_1.NAV_INTERVAL)) { stash_1.stash.delete(stash_1.NAV_INTERVAL); notification_1.notifier.info("Movement interval reset."); } }; commitListElement.key(keys_def_1.NUMBER_KEYS, function (keyName) { var newInterval = stash_1.stash.has(stash_1.NAV_INTERVAL) ? "" + stash_1.stash.get(stash_1.NAV_INTERVAL) + keyName : keyName; stash_1.stash.set(stash_1.NAV_INTERVAL, parseInt(newInterval, 10)); notification_1.notifier.info("Movement interval: " + newInterval); }); commitListElement.key([keys_def_1.keys.DOWN, keys_def_1.keys.J], function () { return doUpdateIndex(actions_1.Actions.updateIndex); }); commitListElement.key([keys_def_1.keys.K, keys_def_1.keys.UP], function () { return doUpdateIndex(function (interval) { return actions_1.Actions.updateIndex(-interval); }); }); commitListElement.key([keys_def_1.keys.B, keys_def_1.keys.PAGEUP], function () { return actions_1.Actions.updateIndex(-commitListElement.height); }); commitListElement.key([keys_def_1.keys.F, keys_def_1.keys.PAGEDOWN], function () { return actions_1.Actions.updateIndex(+commitListElement.height); }); commitListElement.key([keys_def_1.keys.ENTER, keys_def_1.keys.SPACE], function () { return actions_1.Actions.updateView(types_1.View.COMMIT); }); commitListElement.key(keys_def_1.keys.FORWARD_SLASH, function () { var searchInput = search_bar_1.getSearchInput(function (value) { return __awaiter(void 0, void 0, void 0, function () { var results; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, search_1.searchIndex.search(value)]; case 1: results = _a.sent(); actions_1.Actions.updateSearch({ indexesMatchingSearch: results, searchTerm: value, }); return [2 /*return*/]; } }); }); }); commitListElement.screen.append(searchInput); searchInput.show(); searchInput.focus(); commitListElement.screen.render(); }); commitListElement.key(keys_def_1.keys.N, function () { return actions_1.Actions.nextSearchResult(); }); commitListElement.key(keys_def_1.keys.SHIFT_N, function () { return actions_1.Actions.previousSearchResult(); }); commitListElement.focus(); store_1.doSubscribe(['index', 'search'], commitListElement, renderIndex); store_1.doSubscribe(['visibleLines'], commitListElement, renderLines); return commitListElement; }; var renderIndex = function (_a) { var commitListElement = _a.element, lastState = _a.lastState, state = _a.state; return __awaiter(void 0, void 0, void 0, function () { var index, visibleLines, listHeight, nextLine; return __generator(this, function (_b) { index = state.index, visibleLines = state.visibleLines; listHeight = commitListElement.height; nextLine = visibleLines[index]; if (!visibleLines.length) { commitListElement.setItems(visibleLines); } else if (commitListElement.getItemIndex(nextLine) !== -1) { commitListElement.select(commitListElement.getItemIndex(nextLine)); } else if (index > lastState.index) { commitListElement.setItems(visibleLines.slice(index - listHeight, index + 1)); commitListElement.select(commitListElement.children.length - 1); } else if (index < lastState.index || state.search !== lastState.search) { commitListElement.setItems(visibleLines.slice(index, index + listHeight)); commitListElement.select(0); } else { return [2 /*return*/, false]; } return [2 /*return*/, true]; }); }); }; var renderLines = function (_a) { var element = _a.element, state = _a.state; return __awaiter(void 0, void 0, void 0, function () { var index, visibleLines, listHeight, lineIndex; return __generator(this, function (_b) { index = state.index, visibleLines = state.visibleLines; listHeight = element.height; if (element.children.length < listHeight || visibleLines.length < listHeight) { lineIndex = state.indexesWithSHAs[index]; element.setItems(visibleLines.slice(lineIndex, lineIndex + listHeight)); return [2 /*return*/, true]; } return [2 /*return*/, false]; }); }); }; //# sourceMappingURL=list-view.js.map