Browser-based terminal with full ANSI support, real-time WebSocket communication, and automatic language detection for seamless code execution.
- Engine: xterm.js with FitAddon
- ANSI Support: Colors, formatting, cursor control
- Interactive: Real-time input/output
- Scrollback: 1000 lines history
- Detects language from file extension
- Executes code with correct runtime
- Supports: Python, JavaScript, Java, C++
- One-click execution
- Real-time output streaming
- Low latency (<100ms)
- Bidirectional communication
- Session persistence
- Create multiple terminals
- Independent sessions
- Switch between terminals
- Close individual sessions
# Run current file (auto-detected)
Click "Run" button or Ctrl+Enter
# Python
> python3 script.py
Hello, World!
# JavaScript
> node app.js
Server started on port 3000
# Java
> javac Main.java && java Main
Output from Java program
# C++
> g++ main.cpp -o main && ./main
Compiled and executed# Clear terminal
Ctrl+L or type 'clear'
# Cancel running process
Ctrl+C
# Navigate history
Up/Down arrow keys
# Copy selection
Select text β Right-click β Copy
# Paste
Right-click β Paste or Ctrl+Shift+V- Location:
frontend/src/components/Terminal.jsx - Library:
xtermv5.3.0,xterm-addon-fitv0.8.0 - Backend: WebSocket manager in
backend/src/lib/terminalManager.js
// Client β Server
{
type: 'input',
data: 'python3 script.py\n'
}
// Server β Client
{
type: 'output',
data: 'Hello, World!\n'
}
{
type: 'exit',
code: 0
}const languageDetection = {
'.py': {
command: 'python3',
example: 'python3 script.py'
},
'.js': {
command: 'node',
example: 'node app.js'
},
'.java': {
command: 'javac && java',
example: 'javac Main.java && java Main'
},
'.cpp': {
command: 'g++',
example: 'g++ main.cpp -o main && ./main'
}
};// When you click "Run":
1. Detects file extension (.py, .js, .java, .cpp)
2. Sends file to backend
3. Creates Docker container
4. Executes with correct runtime
5. Streams output to terminal# Python script with output
for i in range(10):
print(f"Progress: {i}")
time.sleep(1)
# Output appears line-by-line in real-time# Python script with input
name = input("Enter your name: ")
print(f"Hello, {name}!")
# Terminal accepts user input
> python3 interactive.py
Enter your name: <user types here>
Hello, John!// In Terminal.jsx
const terminal = new Terminal({
cursorBlink: true,
cursorStyle: 'block',
fontSize: 14,
fontFamily: 'Consolas, monospace',
theme: {
background: '#1e1e1e',
foreground: '#ffffff',
cursor: '#ffffff'
},
scrollback: 1000
});// Backend: backend/src/lib/terminalManager.js
const wss = new WebSocketServer({
port: 3002,
perMessageDeflate: false,
clientTracking: true
});theme: {
background: '#1e1e1e',
foreground: '#ffffff',
black: '#000000',
red: '#cd3131',
green: '#0dbc79',
yellow: '#e5e510',
blue: '#2472c8',
magenta: '#bc3fbc',
cyan: '#11a8cd',
white: '#e5e5e5'
}βββββββββββββββ
β Editor β
β (click Run) β
ββββββββ¬βββββββ
β
β
βββββββββββββββββββ
β Terminal β
β Auto-detect β
β language β
ββββββββ¬βββββββββββ
β
β
βββββββββββββββββββ
β WebSocket β
β Send command β
ββββββββ¬βββββββββββ
β
β
βββββββββββββββββββ
β Backend β
β Create Docker β
β container β
ββββββββ¬βββββββββββ
β
β
βββββββββββββββββββ
β Execute Code β
β Stream output β
ββββββββ¬βββββββββββ
β
β
βββββββββββββββββββ
β Terminal β
β Display output β
βββββββββββββββββββ
Solution:
# Check WebSocket connection
Browser Console β Network β WS tab
# Should show connected WebSocket
# Restart backend
cd backend
npm run devSolution:
- Check Docker container is running:
docker ps - Check backend logs for errors
- Verify file path is correct
Solution:
- Click inside terminal to focus
- Check if process is running (Ctrl+C to cancel)
- Refresh page if frozen
// Connect
ws://localhost:3002
// Events
- 'connection': New terminal session
- 'input': User command/input
- 'output': Command output
- 'exit': Process terminated
- 'error': Execution error
- 'close': Session closed