Skip to content

Commit 254f3c9

Browse files
committed
Place version and error output in separate area (always enabled)
Also added line numbers to the user input
1 parent 11b3ace commit 254f3c9

File tree

2 files changed

+78
-22
lines changed

2 files changed

+78
-22
lines changed

addon/doxycommentview/doxycommentview.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,20 @@
2121
import argparse
2222
import signal
2323
import threading
24+
import html
2425

2526
def main():
2627
# Set up argument parser
2728
parser = argparse.ArgumentParser(description="Runs the doxygen comment viewer HTTP server.")
2829
parser.add_argument('--port', type=int, default=8000, help='Port number to run the server on')
2930
parser.add_argument('--doxygen', type=str, default='doxygen', help='Path to doxygen executable')
3031
parser.add_argument('--doxyfile', type=str, default='Doxyfile', help='Path to Doxyfile to use')
31-
parser.add_argument('--debug', action="store_true", help='Display warnings')
32-
parser.add_argument('--version', action="store_true", help='Display doxygen version used')
3332
args = parser.parse_args()
3433

3534
PORT = args.port
3635
DOXYGEN = args.doxygen
3736
DOXYFILE = args.doxyfile
38-
DEBUG = args.debug
39-
VERSION = args.version
40-
41-
if VERSION:
42-
VERSION_STR = subprocess.run([DOXYGEN, '-v'], \
43-
capture_output=True, text=True, encoding="utf-8")
37+
VERSION_STR = subprocess.run([DOXYGEN, '-v'], capture_output=True, text=True, encoding="utf-8").stdout
4438

4539
class RequestHandler(http.server.SimpleHTTPRequestHandler):
4640
def do_POST(self):
@@ -50,22 +44,21 @@ def do_POST(self):
5044
data = json.loads(post_data)
5145
input_text = data['input']
5246

53-
# Run doxygen in single comment mode, reading from stdin and writing to stdout
47+
# Run doxygen in single comment mode, reading from stdin and writing to stdout and stderr
5448
result = subprocess.run([DOXYGEN, '-c', '-', DOXYFILE], \
5549
input=input_text, capture_output=True, text=True, encoding="utf-8")
5650

57-
# Insert CSS link tag into the HTML output
51+
# Prepare the response
52+
response = json.dumps({
53+
'html_output': result.stdout,
54+
'error_output': "<b>Doxygen version "+html.escape(VERSION_STR)+"</b><pre>"+html.escape(result.stderr)+"</pre>"
55+
})
56+
57+
# Send the result to the requesting HTML page
5858
self.send_response(200)
5959
self.send_header('Content-type', 'text/html')
6060
self.end_headers()
61-
if VERSION:
62-
self.wfile.write(VERSION_STR.stdout.encode())
63-
self.wfile.write("<hr>".encode())
64-
self.wfile.write(result.stdout.encode())
65-
if DEBUG:
66-
self.wfile.write("<hr>\n<pre>".encode())
67-
self.wfile.write(result.stderr.replace('&','&amp;').replace("'","&apos;").replace('<','&lt;').replace('>','&gt;').encode())
68-
self.wfile.write("</pre>".encode())
61+
self.wfile.write(response.encode())
6962

7063
httpd = socketserver.TCPServer(("", PORT), RequestHandler)
7164

addon/doxycommentview/index.html

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,90 @@
1212
height: 100vh;
1313
}
1414
.panel {
15+
display: flex;
1516
width: 50%;
1617
padding: 20px;
1718
box-sizing: border-box;
1819
}
20+
.line-numbers {
21+
background: #f0f0f0;
22+
padding: 10px;
23+
margin: 0px;
24+
margin-top: 2px;
25+
text-align: right;
26+
user-select: none;
27+
white-space: pre;
28+
border-right: 1px solid #ccc;
29+
font-family: monospace;
30+
font-size: 14px;
31+
line-height: 1.5;
32+
overflow: hidden;
33+
}
1934
#input {
2035
width: 100%;
2136
height: 100%;
37+
padding: 10px;
38+
margin: 0px;
2239
box-sizing: border-box;
23-
resize: none; /* Prevent resizing */
40+
resize: none;
41+
font-family: monospace;
42+
font-size: 14px;
43+
line-height: 1.5;
2444
}
2545
#output {
2646
border-left: 1px solid #ccc;
47+
display: flex;
48+
flex-direction: column;
49+
overflow: hidden;
50+
}
51+
#output-area {
52+
flex: 1;
2753
overflow: auto;
2854
}
55+
#console-area {
56+
height: 150px; /* Fixed height for the console area */
57+
border-top: 1px solid #ccc;
58+
overflow: auto;
59+
background-color: #f9f9f9; /* Light grey background for console area */
60+
padding: 10px;
61+
box-sizing: border-box;
62+
}
2963
</style>
3064
</head>
3165
<body>
3266
<div class="panel">
33-
<textarea id="input"></textarea>
67+
<div class="line-numbers" id="line-numbers">1</div>
68+
<textarea id="input" oninput="updateLineNumbers()" onscroll="syncScroll()" onkeydown="updateLineNumbers()" onkeyup="updateLineNumbers()"></textarea>
3469
</div>
3570
<div class="panel" id="output">
3671
<!-- Processed output will appear here -->
72+
<div id="output-area">
73+
<!-- Processed output will appear here -->
74+
</div>
75+
<div id="console-area">
76+
<!-- Error messages will appear here -->
77+
</div>
3778
</div>
3879
<script>
80+
function updateLineNumbers() {
81+
const textarea = document.getElementById('input');
82+
const lineNumbers = document.getElementById('line-numbers');
83+
84+
const lines = textarea.value.split('\n').length;
85+
let lineNumberString = '';
86+
for (let i = 1; i <= lines; i++) {
87+
lineNumberString += i + '\n';
88+
}
89+
90+
lineNumbers.textContent = lineNumberString;
91+
}
92+
93+
function syncScroll() {
94+
const textarea = document.getElementById('input');
95+
const lineNumbers = document.getElementById('line-numbers');
96+
lineNumbers.scrollTop = textarea.scrollTop;
97+
}
98+
3999
function processInput() {
40100
const input = document.getElementById('input').value;
41101
sessionStorage.setItem('userInput', input);
@@ -46,9 +106,10 @@
46106
},
47107
body: JSON.stringify({ input: input }),
48108
})
49-
.then(response => response.text())
109+
.then(response => response.json())
50110
.then(result => {
51-
document.getElementById('output').innerHTML = result;
111+
document.getElementById('output-area').innerHTML = result.html_output;
112+
document.getElementById('console-area').innerHTML = result.error_output;
52113
});
53114
}
54115

@@ -63,6 +124,8 @@
63124
document.getElementById('input').value = savedInput;
64125
processInput();
65126
}
127+
// Initial line numbers update
128+
updateLineNumbers();
66129
};
67130
</script>
68131
</body>

0 commit comments

Comments
 (0)