UNPKG

dop-stick

Version:

Source control tooling for versionable-upgradeable smart contracts

82 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TreeLogger = void 0; const terminal_1 = require("./terminal"); const TreeLogStyles = { icons: { tree: { pipe: '│', branch: '├─', lastBranch: '└─', empty: ' ' } } }; class TreeLogger { constructor() { this.depth = 0; this.branches = []; } /** * Creates a new branch in the tree */ branch(text, callback) { this.log(text); this.depth++; callback(); this.depth--; } /** * Logs a tree item */ item(text, isLast = false) { const prefix = this.getPrefix(isLast); const icon = isLast ? TreeLogStyles.icons.tree.lastBranch : TreeLogStyles.icons.tree.branch; this.log(`${prefix}${icon} ${text}`); this.branches[this.depth] = !isLast; } /** * Logs a message with proper formatting */ log(text) { const prefix = this.getPrefix(false); terminal_1.Terminal.write(`${prefix}${text}\n`); } /** * Gets the proper prefix based on current depth */ getPrefix(isLast) { let result = ''; for (let i = 0; i < this.depth; i++) { result += this.branches[i] ? `${TreeLogStyles.icons.tree.pipe} ` : `${TreeLogStyles.icons.tree.empty} `; } return result; } /** * Creates a colored tree item */ itemWithColor(text, color, isLast = false) { const prefix = this.getPrefix(isLast); const icon = isLast ? TreeLogStyles.icons.tree.lastBranch : TreeLogStyles.icons.tree.branch; this.log(`${prefix}${icon} ${terminal_1.Terminal.colors[color]}${text}${terminal_1.Terminal.colors.reset}`); this.branches[this.depth] = !isLast; } /** * Static method to format an array of strings into a tree structure */ static format(lines) { const logger = new TreeLogger(); const result = []; lines.forEach((line, index) => { const isLast = index === lines.length - 1; const prefix = logger.getPrefix(isLast); const icon = isLast ? TreeLogStyles.icons.tree.lastBranch : TreeLogStyles.icons.tree.branch; result.push(`${prefix}${icon} ${line}`); }); return result.join('\n'); } } exports.TreeLogger = TreeLogger; //# sourceMappingURL=treeLogger.js.map