python+websocket+xterm实现windows下的实时交互的web命令行代码
代码语言:python
所属分类:其他
代码描述:python+websocket+xterm实现windows下的实时交互的web命令行代码,这个是专门针对windows系统的,可以按ctrl+c可中断,与本地命令行体验相同。
代码标签: python websocket xterm windows 实时 交互 web 命令行 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
#!/usr/bin/env python3
# -*- coding: utf-8 -*
import asyncio
import websockets
from http.server import HTTPServer, SimpleHTTPRequestHandler
import threading
import subprocess
import os
import sys
import time
import signal
# HTML template with xterm.js
HTML = """
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Windows CMD Terminal</title>
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/xterm.4.19.0.css">
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/xterm.4.19.0.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/xterm-addon-fit.4.19.0.js"></script>
<style>
body { margin: 0; height: 100vh; background: #000; }
#terminal { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="terminal"></div>
<script>
const term = new Terminal({
cursorBlink: true,
fontSize: 14,
fontFamily: 'Consolas,monospace',
theme: {
background: '#000000',
foreground: '#ffffff'
}
});
const fitAddon = new FitAddon.FitAddon();
term.loadAddon(fitAddon);
term.open(document.getElementById('terminal'));
fitAddon.fit();
const ws = new WebSocket('ws://' + window.location.hostname + ':8766');
let inpu.........完整代码请登录后点击上方下载按钮下载查看















网友评论0