-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daffdba
commit 5ff07a4
Showing
23 changed files
with
1,099 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
uenv/ | ||
res/tests/ | ||
**/build | ||
**/dist | ||
**/__pycache__ | ||
*.pyi | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import sys | ||
sys.dont_write_bytecode = True | ||
|
||
import os | ||
|
||
if getattr(sys, "frozen", False): | ||
if hasattr(sys, "_MEIPASS"): | ||
ROOT_PATH = sys._MEIPASS | ||
else: | ||
ROOT_PATH = os.path.dirname(os.path.realpath(sys.executable)) | ||
os.environ["UTERM_ROOT_PATH"] = ROOT_PATH | ||
else: | ||
ROOT_PATH = os.path.dirname(os.path.realpath(__file__)) | ||
os.environ["UTERM_ROOT_PATH"] = ROOT_PATH | ||
|
||
SRC_PATH = os.path.join(ROOT_PATH, "src") | ||
STATIC_PATH = os.path.join(ROOT_PATH, "static") | ||
TEMPLATES_PATH = os.path.join(ROOT_PATH, "templates") | ||
|
||
os.environ["UTERM_SRC_PATH"] = SRC_PATH | ||
os.environ["UTERM_STATIC_PATH"] = STATIC_PATH | ||
os.environ["UTERM_TEMPLATES_PATH"] = TEMPLATES_PATH | ||
|
||
#sys.path.append(os.path.join(ROOT_PATH)) | ||
#sys.path.append(os.path.join(SRC_PATH)) | ||
|
||
from aiohttp import web | ||
import socketio | ||
|
||
import src.urequirements as urequirements | ||
import src.uterm as uterm | ||
|
||
urequirements.main() | ||
|
||
usocket = socketio.AsyncServer() | ||
app = web.Application() | ||
usocket.attach(app) | ||
usocket_config = dict() | ||
|
||
terminal_api = uterm.TerminalCoreApi(rows=50, cols=50) | ||
|
||
async def read_and_forward_pty_output(): | ||
max_read_bytes = 1024 * 20 | ||
while True: | ||
await usocket.sleep(0.01) | ||
output = terminal_api.read(max_read_bytes) | ||
if output: | ||
await usocket.emit("pty-output", {"output": output}, namespace="/pty") | ||
|
||
async def index(request): | ||
"""Serve the client-side application.""" | ||
with open(os.path.join(TEMPLATES_PATH, 'index.html')) as f: | ||
return web.Response(text=f.read(), content_type='text/html') | ||
|
||
@usocket.on("pty-input", namespace="/pty") | ||
async def pty_input(sid, data): | ||
"""write to the child pty. The pty sees this as if you are typing in a real | ||
terminal. | ||
""" | ||
terminal_api.write(data["input"].encode()) | ||
|
||
@usocket.on("resize", namespace="/pty") | ||
async def resize(sid, data): | ||
terminal_api.set_window_size(data["rows"], data["cols"]) | ||
|
||
@usocket.on("connect", namespace="/pty") | ||
async def connect(sid,environ): | ||
"""new client connected""" | ||
terminal_api.spawn(usocket_config["cmd"]) | ||
usocket.start_background_task(target=read_and_forward_pty_output) | ||
|
||
def run_new_term(command:str = "python3", host:str="127.0.0.1", port:int=9990, command_args:str=""): | ||
usocket_config["cmd"] = uterm.TermUtils.get_split_command(command, command_args) | ||
web.run_app(app, port = port, host = host) | ||
|
||
app.router.add_static('/static', STATIC_PATH) | ||
app.router.add_get('/', index) | ||
|
||
def main(): | ||
import argparse | ||
|
||
parser=argparse.ArgumentParser(description="Pyuxterm - A powerful cross platform Terminal emulator") | ||
|
||
parser.add_argument('-cmd', | ||
'--command', | ||
help="Enter the bin to run", | ||
default="bash", | ||
type=str) | ||
|
||
parser.add_argument('-ip', | ||
'--host', | ||
help="Enter the host Bruh", | ||
default="127.0.0.1", | ||
type=str) | ||
|
||
parser.add_argument('-p', | ||
'--port', | ||
help="Enter the port XD", | ||
default=9990, | ||
type = int) | ||
|
||
parser.add_argument('-ba', | ||
'--binargs', | ||
help="Enter args to bin", | ||
default="", | ||
type = str) | ||
|
||
args=parser.parse_args() | ||
|
||
sys.exit(run_new_term(args.command, args.host, args.port, args.binargs)) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# -*- mode: python ; coding: utf-8 -*- | ||
|
||
|
||
block_cipher = None | ||
|
||
hidden_libs = [ | ||
|
||
"src.uterm", | ||
"src.urequirements", | ||
"src.static_files", | ||
"pyuterm", | ||
|
||
"aiohttp", | ||
"aiosignal", | ||
"altgraph", | ||
"async_timeout", | ||
"attrs", | ||
"bidict", | ||
"certifi", | ||
"charset_normalizer", | ||
"click", | ||
"engineio", | ||
"frozenlist", | ||
"idna", | ||
"importlib_metadata", | ||
"multidict", | ||
"socketio", | ||
"requests", | ||
"urllib3", | ||
"yarl", | ||
"zipp", | ||
|
||
"engineio.async_drivers.aiohttp", | ||
"engineio.async_aiohttp" | ||
] | ||
|
||
app_resources = [ | ||
( 'static', 'static' ), | ||
( 'templates', 'templates'), | ||
] | ||
|
||
a = Analysis( | ||
['pyuterm.py'], | ||
pathex=[], | ||
binaries=[], | ||
datas=app_resources, | ||
hiddenimports=hidden_libs, | ||
hookspath=[], | ||
hooksconfig={}, | ||
runtime_hooks=[], | ||
excludes=[], | ||
win_no_prefer_redirects=False, | ||
win_private_assemblies=False, | ||
cipher=block_cipher, | ||
noarchive=False, | ||
) | ||
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) | ||
|
||
exe = EXE( | ||
pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.zipfiles, | ||
a.datas, | ||
[], | ||
name='pyuterm', | ||
debug=False, | ||
bootloader_ignore_signals=False, | ||
strip=False, | ||
upx=True, | ||
upx_exclude=[], | ||
runtime_tmpdir=None, | ||
console=True, | ||
disable_windowed_traceback=False, | ||
argv_emulation=False, | ||
target_arch=None, | ||
codesign_identity=None, | ||
entitlements_file=None, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
import os | ||
from cx_Freeze import setup, Executable | ||
|
||
build_exe_options = { | ||
"packages": [ | ||
|
||
"src.uterm", | ||
"src.urequirements", | ||
"src.static_files", | ||
"pyuterm", | ||
|
||
"aiohttp", | ||
"aiosignal", | ||
"altgraph", | ||
"async_timeout", | ||
"attrs", | ||
"bidict", | ||
"certifi", | ||
"charset_normalizer", | ||
"engineio", | ||
"frozenlist", | ||
"idna", | ||
"importlib_metadata", | ||
"multidict", | ||
"socketio", | ||
"requests", | ||
"urllib3", | ||
"yarl", | ||
"zipp" | ||
], | ||
"excludes": ["static","templates"]} | ||
|
||
base = None | ||
|
||
setup( | ||
name="pyuterm", | ||
version="0.1", | ||
description="Pyuxterm - A powerful cross platform Terminal emulator", | ||
options={"build_exe": build_exe_options}, | ||
executables=[Executable("pyuterm.py", base=base)], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import urequirements | ||
from . import uterm | ||
from . import static_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
HTML = """ | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Uterm</title> | ||
<style> | ||
:root { | ||
--main-bg-color: #212121; | ||
--scrollbar-bg-color:transparent; | ||
--scrollbar-thumb-bg-color:rgba(250, 250, 250, 0.4); | ||
--scrollbar-thumb-hover-bg-color:rgb(250, 250, 250, 0.8) | ||
} | ||
</style> | ||
<link | ||
rel="stylesheet" | ||
href="/static/ustyle.css" | ||
/> | ||
<link | ||
rel="stylesheet" | ||
href="/static/packages/xterm/css/xterm.css" | ||
/> | ||
</head> | ||
<body> | ||
<div id="terminal"></div> | ||
<!-- xterm --> | ||
<script src="/static/packages/xterm/lib/xterm.js"></script> | ||
<script src="/static/packages/xterm-addon-fit/lib/xterm-addon-fit.js"></script> | ||
<script src="/static/packages/xterm-addon-web-links/lib/xterm-addon-web-links.js"></script> | ||
<script src="/static/packages/xterm-addon-search/lib/xterm-addon-search.js"></script> | ||
<script src="/static/packages/ajax/libs/socket.io/socket.io.min.js"></script> | ||
<script> | ||
const term = new Terminal({ | ||
cursorBlink: true, | ||
macOptionIsMeta: true, | ||
scrollback: 1000, | ||
}); | ||
// https://github.com/xtermjs/xterm.js/issues/2941 | ||
const fit = new FitAddon.FitAddon(); | ||
term.loadAddon(fit); | ||
term.loadAddon(new WebLinksAddon.WebLinksAddon()); | ||
term.loadAddon(new SearchAddon.SearchAddon()); | ||
term.open(document.getElementById("terminal")); | ||
fit.fit(); | ||
term.resize(15, 50); | ||
fit.fit(); | ||
term.setOption('theme', { background: '#212121' }); | ||
term.onData((data) => { | ||
console.log("key pressed in browser:", data); | ||
socket.emit("pty-input", { input: data }); | ||
}); | ||
const socket = io.connect("/pty"); | ||
const status = document.getElementById("status"); | ||
socket.on("pty-output", function (data) { | ||
console.log("new output received from server:", data.output); | ||
term.write(data.output); | ||
}); | ||
function fitToscreen() { | ||
fit.fit(); | ||
const dims = { cols: term.cols, rows: term.rows }; | ||
console.log("sending new dimensions to server's pty", dims); | ||
socket.emit("resize", dims); | ||
} | ||
function debounce(func, wait_ms) { | ||
let timeout; | ||
return function (...args) { | ||
const context = this; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => func.apply(context, args), wait_ms); | ||
}; | ||
} | ||
const wait_ms = 50; | ||
window.onresize = debounce(fitToscreen, wait_ms); | ||
</script> | ||
</body> | ||
</html> | ||
""" | ||
|
||
CSS = """ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
border:0; | ||
vertical-align: baseline; | ||
} | ||
html, body { | ||
min-height: 100vh; | ||
height: 100%; | ||
overflow: hidden; | ||
background-color: var(--main-bg-color); | ||
} | ||
#terminal{ | ||
width: 100vw; | ||
min-height: 100vh; | ||
max-height: 101vh; | ||
} | ||
::-webkit-scrollbar { | ||
width: 9px; | ||
height: 9px; | ||
} | ||
::-webkit-scrollbar-track { | ||
background-color: var(--scrollbar-bg-color); | ||
} | ||
::-webkit-scrollbar-thumb { | ||
background-color: var(--scrollbar-thumb-bg-color); | ||
} | ||
::-webkit-scrollbar-thumb:hover { | ||
background-color: var(--scrollbar-thumb-hover-bg-color); | ||
} | ||
""" |
Oops, something went wrong.