#!/usr/bin/env node
/**
* Windows TUI Screen Stacking Fix - Testing Script
*
* This script tests the Windows terminal screen clearing functionality
* and verifies that the TUI renders without screen stacking/flickering.
*/
import { spawn } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('š„ļø Windows TUI Screen Stacking Fix - Test Script');
console.log('================================================\n');
// Check if we're on Windows
if (process.platform !== 'win32') {
console.log('ā This test script is specifically for Windows.');
console.log(' Current platform:', process.platform);
process.exit(1);
}
// Terminal detection
console.log('š Terminal Environment Detection:');
console.log(` Platform: ${process.platform}`);
console.log(` Terminal Columns: ${process.stdout.columns || 'unknown'}`);
console.log(` Terminal Rows: ${process.stdout.rows || 'unknown'}`);
console.log(` TTY Support: ${process.stdout.isTTY ? 'ā
' : 'ā'}`);
console.log(` Windows Terminal: ${process.env.WT_SESSION ? 'ā
' : 'ā'}`);
console.log(` VSCode Terminal: ${process.env.TERM_PROGRAM === 'vscode' ? 'ā
' : 'ā'}`);
console.log(` TERM Program: ${process.env.TERM_PROGRAM || 'none'}`);
console.log('');
// Test ANSI escape codes
console.log('šØ Testing ANSI Escape Code Support:');
// Test 1: Basic screen clearing
console.log(' Test 1: Basic screen clear (\\x1b[2J\\x1b[H)');
try {
process.stdout.write('\x1b[2J\x1b[H');
console.log(' ā
Basic clear executed');
} catch (error) {
console.log(' ā Basic clear failed:', error.message);
}
// Test 2: Cursor manipulation
console.log(' Test 2: Cursor hide/show (\\x1b[?25l/\\x1b[?25h)');
try {
process.stdout.write('\x1b[?25l'); // Hide cursor
setTimeout(() => {
process.stdout.write('\x1b[?25h'); // Show cursor
console.log(' ā
Cursor manipulation executed');
}, 100);
} catch (error) {
console.log(' ā Cursor manipulation failed:', error.message);
}
// Test 3: Alternate screen buffer
setTimeout(() => {
console.log(' Test 3: Alternate screen buffer (\\x1b[?1049h/\\x1b[?1049l)');
try {
process.stdout.write('\x1b[?1049h'); // Switch to alternate screen
process.stdout.write('\x1b[2J\x1b[H'); // Clear alternate screen
setTimeout(() => {
process.stdout.write('\x1b[?1049l'); // Switch back to main screen
console.log(' ā
Alternate screen buffer executed');
// Run the actual TUI test
runTUITest();
}, 500);
} catch (error) {
console.log(' ā Alternate screen buffer failed:', error.message);
runTUITest();
}
}, 200);
function runTUITest() {
console.log('\nš Starting TUI Application Test:');
console.log(' This will launch the folder-mcp TUI interface.');
console.log(' Watch for:');
console.log(' - ā
Clean screen clearing (no stacking/accumulation)');
console.log(' - ā
Smooth navigation without visual artifacts');
console.log(' - ā
Proper text rendering without overlapping');
console.log(' - ā
Tab navigation works correctly');
console.log('');
console.log(' Press ESC to exit the TUI when done testing.');
console.log(' Press any key to continue...');
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', () => {
process.stdin.setRawMode(false);
process.stdin.pause();
console.log('\nšÆ Launching TUI...\n');
// Launch the TUI
const tuiPath = path.join(__dirname, '..', '..', '..', 'dist', 'interfaces', 'tui-ink', 'index.js');
const tui = spawn('node', [tuiPath], {
stdio: 'inherit',
cwd: process.cwd()
});
tui.on('close', (code) => {
console.log('\nš TUI Test Complete');
console.log(` Exit code: ${code}`);
if (code === 0) {
console.log(' ā
TUI exited normally');
} else {
console.log(' ā ļø TUI exited with error code');
}
console.log('\nš Post-Test Analysis:');
console.log(' Did you observe any of the following issues?');
console.log(' - Screen stacking/flickering? (ā if yes, ā
if no)');
console.log(' - Text accumulation/overlapping? (ā if yes, ā
if no)');
console.log(' - Navigation artifacts? (ā if yes, ā
if no)');
console.log(' - Unreadable output? (ā if yes, ā
if no)');
console.log('');
console.log('š” If you encountered any issues, please report them with:');
console.log(' - Terminal type (Command Prompt, PowerShell, Windows Terminal)');
console.log(' - Windows version');
console.log(' - Specific visual behavior observed');
});
tui.on('error', (error) => {
console.log('\nā Failed to launch TUI:', error.message);
console.log(' Make sure the project is built: npm run build');
});
});
}