Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cli/commands/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from "chalk";
import { logger } from "../../shared/logger";
import { showMainMenu, showGoodbyeScreen, pressAnyKey } from "../tui";
import { authCommand, loadConfig } from "./auth";
import { configCommand } from "./config";
Expand All @@ -10,6 +11,9 @@ import { startCommand } from "./start";
export async function interactiveMode(): Promise<void> {
let running = true;

// Initialize logger early so logs dir is created on first run
logger.debug("TxtCode interactive mode started");

while (running) {
console.clear();

Expand Down
10 changes: 10 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#!/usr/bin/env node
// Suppress deprecation warnings from dependencies (e.g. punycode, Buffer)
// before any imports that might trigger them
process.removeAllListeners("warning");
process.on("warning", (warning) => {
if (warning.name === "DeprecationWarning") {
return;
}
console.warn(warning);
});

import chalk from "chalk";
import { interactiveMode } from "./commands/interactive";

Expand Down
7 changes: 6 additions & 1 deletion src/cli/tui/components/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as readline from "readline";
import chalk from "chalk";
import { centerText, getTerminalWidth } from "./centered-text";

let keypressInitialized = false;

export interface MenuItem {
name: string;
value: string;
Expand Down Expand Up @@ -80,7 +82,10 @@ export async function showMenu(options: MenuOptions): Promise<string> {

render(true);

readline.emitKeypressEvents(process.stdin);
if (!keypressInitialized) {
readline.emitKeypressEvents(process.stdin);
keypressInitialized = true;
}
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
Expand Down
13 changes: 10 additions & 3 deletions src/shared/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ class Logger {
if (this.initialized) {
return;
}
this.initialized = true;
try {
// Ensure parent .txtcode dir exists first, then logs subdir
const txtcodeDir = path.join(os.homedir(), ".txtcode");
if (!fs.existsSync(txtcodeDir)) {
fs.mkdirSync(txtcodeDir, { mode: 0o700, recursive: true });
}
if (!fs.existsSync(LOG_DIR)) {
fs.mkdirSync(LOG_DIR, { recursive: true });
}
this.sessionFile = path.join(LOG_DIR, `session-${this.fileTimestamp()}.log`);
this.cleanOldLogs();
this.stream = fs.createWriteStream(this.sessionFile, { flags: "a" });
this.stream.on("error", () => {});
this.initialized = true;
this.stream.on("error", () => {
this.stream = null;
});
} catch {
this.initialized = true;
// Logger should never crash the app
}
}

Expand Down