terminal intigration

This commit is contained in:
megamichi 2024-09-16 21:01:46 +02:00
parent 68db073dfe
commit 66f5f97ee3
5 changed files with 119 additions and 0 deletions

20
app.py
View file

@ -1,4 +1,8 @@
<<<<<<< HEAD
#!/usr/bin/python3 #!/usr/bin/python3
=======
#!/usr/bi/python3
>>>>>>> 079d2a0 (terminal intigration)
from flask import * from flask import *
from main import launchserver from main import launchserver
import libtmux import libtmux
@ -34,6 +38,7 @@ def getlpane() -> libtmux.Pane:
@app.route("/term", methods=["GET", "POST"]) @app.route("/term", methods=["GET", "POST"])
def get_terminal_output(): def get_terminal_output():
if request.method == "POST": if request.method == "POST":
<<<<<<< HEAD
data = request.data.decode() data = request.data.decode()
print(data) print(data)
@ -47,6 +52,21 @@ def get_terminal_output():
getlpane().send_keys("exit") getlpane().send_keys("exit")
return ["sucessful"] return ["sucessful"]
=======
data = request.get_json()#json.loads(request.data.decode())
print(data,type(data))
content = data["content"]
if content[0] == "command":
if content[1] == "start" and getlpane().pane_current_command == "bash":
launchserver(getlpane())
elif content[1] == "stop" and getlpane().pane_current_command == "mono":
getlpane().send_keys("\nexit")
elif content[1] == "terminal-command" and getlpane().pane_current_command == "mono":
getlpane().send_keys(content[2])
return ["sucessful"]
>>>>>>> 079d2a0 (terminal intigration)
elif request.method == "GET": elif request.method == "GET":
term = get_term() term = get_term()
if term[1] == "mono": if term[1] == "mono":

View file

@ -1,4 +1,8 @@
<<<<<<< HEAD
#!/usr/bin/python3 #!/usr/bin/python3
=======
#!/usr/bi/python3
>>>>>>> 079d2a0 (terminal intigration)
import libtmux import libtmux
import settings import settings
import libtmux.constants import libtmux.constants

View file

@ -1,4 +1,8 @@
<<<<<<< HEAD
#!/usr/bin/python3 #!/usr/bin/python3
=======
#!/usr/bi/python3
>>>>>>> 079d2a0 (terminal intigration)
from os import path from os import path
path = ( path = (

View file

@ -1,5 +1,9 @@
a { a {
<<<<<<< HEAD
color: rgb(107, 214, 0); color: rgb(107, 214, 0);
=======
color: chartreuse;
>>>>>>> 079d2a0 (terminal intigration)
} }
body { body {
@ -19,7 +23,10 @@ body {
padding: 10px; padding: 10px;
border-radius: 20px; border-radius: 20px;
border-style:hidden; border-style:hidden;
<<<<<<< HEAD
margin-bottom: 10px; margin-bottom: 10px;
=======
>>>>>>> 079d2a0 (terminal intigration)
} }
#buttons { #buttons {
@ -27,11 +34,17 @@ body {
flex-direction: column; flex-direction: column;
padding: 10px; padding: 10px;
} }
<<<<<<< HEAD
.input { .input {
color: chartreuse; color: chartreuse;
background-color: rgb(0, 0, 0); background-color: rgb(0, 0, 0);
=======
input {
color: chartreuse;
background-color: rgba(0, 0, 0, 0.1);
>>>>>>> 079d2a0 (terminal intigration)
border-color: chartreuse; border-color: chartreuse;
padding: 10px; padding: 10px;
border-style: solid; border-style: solid;
@ -39,8 +52,14 @@ body {
border-radius: 20px; border-radius: 20px;
} }
<<<<<<< HEAD
#terminal { #terminal {
background-color: #0001002a; background-color: #0001002a;
=======
#terminal {
background-color: rgba(0, 0, 0, 0.1);
>>>>>>> 079d2a0 (terminal intigration)
color: chartreuse; color: chartreuse;
border-style: solid; border-style: solid;
border-color: chartreuse; border-color: chartreuse;
@ -48,6 +67,7 @@ body {
padding: 15px; padding: 15px;
font-family: 'Courier New', Courier, monospace; font-family: 'Courier New', Courier, monospace;
font-size: 16px; font-size: 16px;
<<<<<<< HEAD
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow-y: auto; overflow-y: auto;
@ -57,4 +77,9 @@ body {
#dash { #dash {
display: flex; display: flex;
height: 100vh; height: 100vh;
=======
height: 100%;
overflow-y: auto;
box-shadow: 0 0 10px rgb(0, 255, 0);
>>>>>>> 079d2a0 (terminal intigration)
} }

View file

@ -3,6 +3,7 @@
<head> <head>
<script> <script>
let termdiv; let termdiv;
<<<<<<< HEAD
function sendcommand(list) { function sendcommand(list) {
fetch("/term",{ fetch("/term",{
@ -12,6 +13,29 @@
}); });
getterm(); getterm();
}; };
=======
let terminput;
let timer;
let timertext;
const COMMAND = "command";
function sendcommand(contentlist) {
fetch("/term",{
method:"POST",
body: JSON.stringify({"content":contentlist}),
headers: {"Content-type":"application/json; charset=UTF-8"}
}).then(getterm());
}
function sendtermcommand() {
sendcommand([COMMAND,
`terminal-command`,
terminput.value]
);
terminput.value = "";
}
>>>>>>> 079d2a0 (terminal intigration)
function getterm() { function getterm() {
let tmpterm = ""; let tmpterm = "";
@ -26,6 +50,7 @@
}) })
.catch(termdiv.innerHTML = 'Fehler beim Abrufen der Daten'); .catch(termdiv.innerHTML = 'Fehler beim Abrufen der Daten');
} }
<<<<<<< HEAD
function initstuff() { function initstuff() {
@ -35,6 +60,26 @@
} }
=======
function getterminterval() {
timer -= 1
timertext.innerHTML = `Reload in ${timer} Seconds`
if (timer == 0) {
getterm()
timer = 5
}
}
function initstuff() {
timer = 5
timertext = document.getElementById("timer")
termdiv = document.getElementById("terminaltext");
terminput = document.getElementById("terminalinput");
getterm();
setInterval(getterminterval,1000)
}
>>>>>>> 079d2a0 (terminal intigration)
window.onload = initstuff; window.onload = initstuff;
</script> </script>
@ -48,10 +93,31 @@
<img src="{{ url_for('static', filename='logo.png') }}" alt="Terra-Dash"> <img src="{{ url_for('static', filename='logo.png') }}" alt="Terra-Dash">
<div id="dash"> <div id="dash">
<div id="buttons"> <div id="buttons">
<<<<<<< HEAD
<button class="button" onclick="sendcommand([`start`])">start</button> <button class="button" onclick="sendcommand([`start`])">start</button>
<button style="background-color: rgb(186, 0, 0);" class="button" onclick="sendcommand([`stop`])">stop</button> <button style="background-color: rgb(186, 0, 0);" class="button" onclick="sendcommand([`stop`])">stop</button>
</div> </div>
<div id="terminal"> <div id="terminal">
=======
<button style="margin-bottom: 10px;"
class="button"
onclick="sendcommand([COMMAND,`start`]);timer=2">start</button>
<button style="margin-bottom: 10px; background-color: rgb(255, 0, 0);"
class="button"
onclick="sendcommand([COMMAND,`stop`]);timer=1">stop</button>
</div>
<div style="width: 100%;height: 100%;">
<p style="font-size: 11px;margin: 0px;margin-left: 15px;" id="timer">Reload in _ Seconds</p>
<div id="terminal">
<div id="terminaltext"></div>
<input id="terminalinput" type="text">
<button
style="margin-top: 15px;"
class="button"
onclick="sendtermcommand();
terminput.value = ``">send</button>
</div>
>>>>>>> 079d2a0 (terminal intigration)
</div> </div>
</div> </div>
</body> </body>