Skip to content

Commit 4ed1ac5

Browse files
committed
Implement pasting a log from the clipboard
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
1 parent 71a09d9 commit 4ed1ac5

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

app.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const createApp = () => {
8383
const gotoLineButton = document.getElementById('goto-line-btn') as HTMLButtonElement;
8484
const gotoEndButton = document.getElementById('goto-end') as HTMLButtonElement;
8585

86+
const inputText = document.getElementById('input-text') as HTMLTextAreaElement;
87+
const mainContent = document.getElementById('main-content') as HTMLElement;
8688
const logContent = document.getElementById('log-content') as HTMLElement;
8789
const contentLines = document.getElementById('content-lines') as HTMLElement;
8890
const lineNumbers = document.getElementById('line-numbers') as HTMLElement;
@@ -258,6 +260,25 @@ const createApp = () => {
258260
}
259261
};
260262

263+
const loadInputText = async (state: AppState, text: string): Promise<void> => {
264+
let offset = 0;
265+
let idx = 0;
266+
const lines = text.split('\n');
267+
lines.forEach(rawLine => {
268+
const parsedLine: ParsedLine = {
269+
idx: idx,
270+
offset: offset,
271+
raw: rawLine,
272+
insnLine: parseInsn(rawLine),
273+
bpfState: parseBpfState(state, idx, rawLine),
274+
};
275+
state.lines.push(parsedLine);
276+
offset += rawLine.length + 1;
277+
idx++;
278+
});
279+
updateLoadStatus(state);
280+
};
281+
261282
const updateLoadStatus = async (state: AppState): Promise<void> => {
262283
if (state.lines.length === 0)
263284
return;
@@ -337,6 +358,19 @@ const createApp = () => {
337358
updateLineNumbers(state.topLineIdx, state.visibleLines);
338359
formatVisibleLines(state);
339360
updateStatePanel(state);
361+
inputText.value = '';
362+
if (state.lines.length === 0) {
363+
mainContent.style.display = 'none';
364+
inputText.style.display = 'flex';
365+
} else {
366+
mainContent.style.display = 'flex';
367+
inputText.style.display = 'none';
368+
}
369+
};
370+
371+
const handlePaste = async (e: ClipboardEvent) => {
372+
await loadInputText(state, e.clipboardData.getData('text'));
373+
updateView(state);
340374
};
341375

342376
const updateTopLineIdx = (state: AppState, delta: number): void => {
@@ -424,6 +458,7 @@ const createApp = () => {
424458
fileInput.addEventListener('change', handleFileInput);
425459
logContent.addEventListener('wheel', handleScroll);
426460
document.addEventListener('keydown', handleKeyDown);
461+
inputText.addEventListener('paste', handlePaste);
427462

428463
// Navigation panel
429464
gotoLineInput.addEventListener('input', gotoLine);

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
<button id="goto-start">&lt;&lt;</button>
1919
<button id="goto-end">&gt;&gt;</button>
2020
</div>
21-
<div class="main-content">
21+
<textarea id="input-text"
22+
class="log-content"
23+
placeholder="Paste the verifier log here or choose a file">
24+
</textarea>
25+
<div id="main-content" class="main-content">
2226
<div class="text-container">
2327
<div id="line-numbers" class="line-numbers"></div>
2428
<div id="log-content" class="log-content">

0 commit comments

Comments
 (0)