• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2021 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15/* eslint-env browser */
16
17import {makeStyles, Paper, Box} from '@material-ui/core';
18import * as React from 'react';
19import {default as AnsiUp} from 'ansi_up';
20import * as Parser from 'html-react-parser';
21
22type Props = {
23  lines: string[];
24};
25
26const useStyles = makeStyles(() => ({
27  root: {
28    padding: '8px',
29    'background-color': '#131416',
30    height: '500px',
31    'overflow-y': 'auto',
32    width: '100%',
33    color: 'white',
34  },
35}));
36
37export function Log(props: Props) {
38  const classes = useStyles();
39  const xtermRef = React.useRef(null);
40  const ansiUp = new AnsiUp();
41
42  function row(text: string, index: number) {
43    const textHtml = ansiUp.ansi_to_html(text);
44    return (
45      <Box key={index} sx={{fontFamily: 'Monospace'}}>
46        {Parser.default(textHtml)}
47      </Box>
48    );
49  }
50
51  return <div className={classes.root}>{props.lines.map(row)}</div>;
52}
53