emotionctl
Version:
A secure terminal-based journaling system designed as a safe space for developers going through heartbreak, breakups, or betrayal
189 lines • 8.84 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Editor = void 0;
const readline = __importStar(require("readline"));
class Editor {
constructor() {
this.content = '';
this.lines = [];
this.resolved = false;
// Simple constructor - no setup needed for this approach
}
clearScreen() {
process.stdout.write('\x1b[2J\x1b[0f');
}
displayContent() {
this.clearScreen();
console.log('╔══════════════════════════════════════════════════════════════╗');
console.log('║ EmotionCtl Editor ║');
console.log('║ Your Safe Space for Emotional Expression ║');
console.log('╠══════════════════════════════════════════════════════════════╣');
console.log('║ Commands: ║');
console.log('║ :save - Save and exit ║');
console.log('║ :quit - Exit without saving ║');
console.log('║ :help - Show this help ║');
console.log('║ Enter empty line to finish typing ║');
console.log('╚══════════════════════════════════════════════════════════════╝');
console.log();
if (this.lines.length > 0) {
console.log('Current content:');
console.log('─'.repeat(60));
this.lines.forEach((line, index) => {
console.log(`${(index + 1).toString().padStart(3)}: ${line}`);
});
console.log('─'.repeat(60));
console.log();
}
}
async showHelp() {
this.clearScreen();
console.log('╔══════════════════════════════════════════════════════════════╗');
console.log('║ EmotionCtl Editor Help ║');
console.log('╚══════════════════════════════════════════════════════════════╝');
console.log();
console.log('This is your safe space for expressing emotions and thoughts.');
console.log();
console.log('How to use:');
console.log('• Type your content line by line');
console.log('• Press Enter to go to the next line');
console.log('• Enter an empty line to stop adding content');
console.log('• Use :save to save and exit');
console.log('• Use :quit to exit without saving');
console.log('• Use :help to see this help again');
console.log();
console.log('Remember: Every step in processing your emotions is progress. 💙');
console.log();
console.log('Press Enter to continue...');
return new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('', () => {
rl.close();
resolve();
});
});
}
/**
* Opens the editor and returns the content when user saves and exits
*/
async edit(initialContent = '') {
return new Promise(async (resolve) => {
this.lines = initialContent ? initialContent.split('\n') : [];
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const processInput = async (input) => {
const trimmedInput = input.trim();
// Handle commands
if (trimmedInput.startsWith(':')) {
switch (trimmedInput.toLowerCase()) {
case ':save':
this.content = this.lines.join('\n');
rl.close();
resolve(this.content);
return;
case ':quit':
if (this.lines.length > 0) {
rl.question('Exit without saving? (y/N): ', (answer) => {
if (answer.toLowerCase() === 'y') {
rl.close();
resolve('');
}
else {
this.displayContent();
rl.prompt();
}
});
return;
}
else {
rl.close();
resolve('');
return;
}
case ':help':
await this.showHelp();
this.displayContent();
rl.prompt();
return;
default:
console.log(`Unknown command: ${trimmedInput}`);
console.log('Available commands: :save, :quit, :help');
rl.prompt();
return;
}
}
// Handle empty line (finish input)
if (trimmedInput === '') {
if (this.lines.length === 0) {
console.log('No content entered. Use :quit to exit or start typing.');
rl.prompt();
return;
}
console.log();
console.log('Content entry finished. Use :save to save and exit, or :quit to exit without saving.');
rl.prompt();
return;
}
// Add the line to content
this.lines.push(input);
rl.prompt();
};
// Set up the readline interface
rl.on('line', processInput);
rl.on('close', () => {
if (!this.resolved) {
this.resolved = true;
resolve(this.content);
}
});
// Handle Ctrl+C
rl.on('SIGINT', () => {
console.log('\nUse :quit to exit or :save to save and exit');
rl.prompt();
});
// Start the editor
this.displayContent();
console.log('Start typing your entry (press Enter after each line):');
rl.prompt();
});
}
}
exports.Editor = Editor;
//# sourceMappingURL=Editor.js.map