UNPKG

@trap_stevo/filetide-cli

Version:

Seamless, real-time file transfers between devices with effortless connectivity. A powerful command-line tool built for instant, secure, and cross-platform file sharing, enabling efficient and reliable data transfers in any network environment.

54 lines (53 loc) 1.18 kB
"use strict"; class CLIHistoryManager { constructor(maxSize = 50) { this.history = []; this.maxSize = maxSize; this.currentIndex = -1; } add(command) { if (!command.trim()) { return; } if (this.history[this.history.length - 1] === command) { return; } this.history.push(command); if (this.history.length > this.maxSize) { this.history.shift(); } this.currentIndex = this.history.length - 1; } getPrevious() { if (this.currentIndex > 0) { this.currentIndex--; return this.history[this.currentIndex]; } return this.history[this.currentIndex] || null; } getNext() { if (this.currentIndex < this.history.length - 1) { this.currentIndex++; return this.history[this.currentIndex]; } this.currentIndex = this.history.length - 1; return null; } get(key = "up") { if (key === "up") { return this.getPrevious(); } if (key === "down") { return this.getNext(); } return null; } clear() { this.history = []; this.currentIndex = -1; } getAll() { return [...this.history]; } } module.exports = CLIHistoryManager;