@tomneutens/serial_monitor
Version:
A web based serial monitor for communicating with serial devices (like Arduino). The library is based on native web components and uses the WebSerial API to communicate with the external device.
73 lines (64 loc) • 1.84 kB
text/typescript
/**
* @author Tom Neutens <tomneutens@gmail.com>
*/
import { LitElement, css, html, CSSResult, CSSResultGroup } from "lit";
import {customElement, property, state} from 'lit/decorators.js';
import { msg } from '@lit/localize';
("monitor-output")
class MonitorOutput extends LitElement {
static styles?: CSSResultGroup = css`
:host {
display: flex;
flex-direction: column-reverse;
align-items: stretch;
overflow-x: hidden;
overflow-y: scroll;
background-color: inherit;
color: inherit;
box-sizing: border-box;
padding: 5px;
margin-bottom: auto;
scrollbar-color: var(--component-foreground-color) var(--component-background-color);
scrollbar-width: thin;
}
:host::-webkit-scrollbar {
width: 10px;
}
:host::-webkit-scrollbar-track {
background: var(--component-background-color);
}
:host::-webkit-scrollbar-thumb {
background-color: var(--component-foreground-color) ;
border-radius: 6px;
border: 3px solid var(--scrollbarBG);
}
:host > div {
width: 100%;
background-color: inherit;
color: inherit;
box-sizing: border-box;
padding: 0 5px;
font-size: var(--component-base-font-size);
}
`
({
type: Array<string>
})
lines:Array<string>;
constructor(){
super();
}
protected render() {
return html`
${this.lines?.reverse().map((line => {
return html`<div>${line}</div>`
}))}
`
}
}
declare global {
interface HTMLElementTagNameMap {
"monitor-output": MonitorOutput;
}
}
export default MonitorOutput;