New release with beter decoding.
All checks were successful
Build and test Zhurnal / Test (push) Successful in 1m11s

This commit is contained in:
retoor 2024-12-01 06:14:33 +01:00
parent 14782c06c4
commit a44108901e
4 changed files with 24 additions and 14 deletions

View File

@ -15,7 +15,7 @@ install:
./.venv/bin/python -m pip install -e .
run:
python -m zhurnal "ping -c 1000 google.nl"
./.venv/bin/zhurnal "ping google.nl" "watch -n 1 ps aux"
test:
./.venv/bin/python -m unittest zhurnal.tests

Binary file not shown.

Binary file not shown.

View File

@ -92,10 +92,11 @@ index_html = """
<body>
<div id="messages" class="terminal"></div>
<script>
const maxLines = 2000
const scrollContainer = document.body;
function autoScroll() {
document.body.scrollTop = document.getElementById("messages").clientHeight;
if (scrollContainer.scrollTop + scrollContainer.clientHeight >= scrollContainer.scrollHeight) {
if (scrollContainer.scrollTop + scrollContainer.clientHeight >= scrollContainer.scrollHeight-30) {
scrollContainer.scrollTop = scrollContainer.scrollHeight; // Scroll to the bottom
}
}
@ -124,22 +125,30 @@ index_html = """
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) + 100 &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth) + 100
);
}
function isLastLineVisible() {
let scrollTop = window.scrollY; // Current scroll position
let docHeight = document.documentElement.scrollHeight; // Total content height
let winHeight = window.innerHeight; // Viewport height
let scrollPercentage = (scrollTop + winHeight) / docHeight * 100;
return scrollPercentage > 97
}
function limitLines(){
const messagesDiv = document.getElementById("messages")
if(!messagesDiv.children.length)
return true;
const lastLine = messagesDiv.children[messagesDiv.children.length - 1]
return isElementInView(lastLine)
while(messagesDiv.children.length > maxLines){
messagesDiv.children[0].remove()
}
}
document.addEventListener("DOMContentLoaded", () => {
let url = (window.location.protocol == 'http' ? 'ws://': 'wss://') + window.location.host + "/ws"
let url = (window.location.protocol == 'http:' ? 'ws://': 'wss://') + window.location.host + "/ws"
const ws = new WebSocket(url);
const messagesDiv = document.getElementById("messages");
ws.onmessage = (event) => {
@ -162,7 +171,6 @@ index_html = """
toolTipDiv.innerHTML = "<b>Process: " + obj.name + "</b><br /><i>Elapsed: " + obj.elapsed.toString() +"s</i><br />Command: " + obj.command
lineDiv.appendChild(toolTipDiv)
lineDiv.setAttribute("title", obj.name + " " + obj.command)
console.info(getProcessColor(obj.name))
lineDiv.style.color = getProcessColor(obj.name)
if(obj.name.search("stderr") > 0)
lineDiv.style.fontStyle = "italic";;
@ -171,7 +179,7 @@ index_html = """
messagesDiv.appendChild(lineDiv)
if(scrollDown)
lineDiv.scrollIntoViewIfNeeded()
limitLines()
};
ws.onclose = () => {
@ -245,14 +253,16 @@ class Zhurnal(web.Application):
time_elapsed = round(
time_previous and time_current - time_previous or 0, 4
)
print(line.decode().strip())
decoded_line = line.decode("utf-8", "replace").strip()
print(decoded_line)
decoded_line = "".join(c for c in decoded_line if c.isprintable())
for client in app.clients:
await client.send_str(
json.dumps(
dict(
elapsed=time_elapsed,
timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
line=line.decode().strip(),
line=decoded_line,
name=name,
command=command,
)