Skip to content

cenfun/monocart-code-viewer

Repository files navigation

monocart-code-viewer

Feature

Install

npm i monocart-code-viewer

Usage

import { createCodeViewer } from 'monocart-code-viewer';

let codeViewer;

const report = {
    content: "your source content",
    coverage: {
        uncoveredLines: {
            '0': 'comment',
            '1': 'blank',
            '8': 'partial',
            '9': 'uncovered'
        },
        uncoveredPieces: {
            '8': [
                {
                    'start': 27,
                    'end': 34
                }
            ]
        },
        decorations: {
            '14': [
                {
                    'column': 4,
                    'value': 'E',
                    'attrs': {
                        'title': 'else path uncovered'
                    }
                }
            ]
        },
        executionCounts: {
            '20': [
                {
                    'column': 22,
                    'count': 10,
                    'value': '10',
                    'end': 916
                }
            ]
        }
    }
};

if (codeViewer) {
    codeViewer.update(report);
} else {
    codeViewer = createCodeViewer($el, report);
    codeViewer.on('cursor', (loc) => {
        // console.log('cursor', loc);
    });

    // codeViewer.setSelection(start, end, options);
    // codeViewer.setCursor(pos, options);
}