@@ -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 ) ;
0 commit comments