Use xterm.js to archive a web log viewer #4885
Replies: 4 comments 3 replies
-
@yangguansen This looks a bit like an xy problem to me - are you sure a terminal is the right tool for your log viewer? The problem here - yes you can do that in a terminal, but not with the terminal alone (so no, xterm.js cannot do that itself) - you'd have to write a pager like (I shamelessly assumed, that you want to do everthing in-browser and not on a PTY terminal session, otherwise you can simply just use So maybe you should go 2 steps back and ask yourself, why a terminal is needed here. If you have no strong reason for a terminal, then using a ready-to-go logger view might be much faster to adopt, even writing the logger view from scratch might get you faster to a working solution than trying to bend xterm.js into that specific use case. What are strong reasons to use xterm.js?
--> If none of that is relevant for you - dont use a terminal in the first place. |
Beta Was this translation helpful? Give feedback.
-
I propose to take a look into monaco-editor. It only renders the lines of the buffer that are visible in the viewport of the editor, and it can handle thousands of lines easily. It also supports decorations, custom code highlighting (e.g. for log files) and much more. It also has a very good API so you could introspect the scrolled viewport and load more data as you need. As a starter for a custom log viewer, take a look at this example: |
Beta Was this translation helpful? Give feedback.
-
@mofux Thank u, I will take a look that. |
Beta Was this translation helpful? Give feedback.
-
@yangguansen, @mofux |
Beta Was this translation helpful? Give feedback.
-
I'm using xterm.js to archive a web log viewer.
What are i need to do :
Load latest log data by websocket and render it at bottom position
Page scroll up, load previous log data to render
Add tag to display log tag in each log row head. i used
decoration
like image below:As a web log viewer, when i scroll up, i want to load prev page log data, does xterm.js has any way to prepend data?
So far i adopt re-render all data to load more data.
And when i called reset api to re-render data, decorations will not be cleared, so i was clear decoration DOM manually. Do we have any api can clear decorations? The
dispose
i tried, but it will not clear decoration.Beta Was this translation helpful? Give feedback.
All reactions