<commit_before>/** 
 * The styling is currently hard-coded. It would be nice to let the user
 * select from some hljs themes eventually.
 */

import React from "react"
import hljs from "highlight.js"

let topLevelStyle = {
    fontFamily: 'monospace',
    whiteSpace: 'pre',
    border: '1px solid rgb(204, 204, 204)',
    borderRadius: '4px',
    padding: '5px 0px 5px 0px',
};

let placeholderStyle = Object.assign({
    textAlign: "center"
}, topLevelStyle);

let noSourceContent;

export default React.createClass({

    render: function() {
        if (this.props.currentContext === null) {
            return this._renderPlaceholderContent(this.props.defaultSourceContent);
        }else{
            return this._renderContent();
        }
    },

    _renderPlaceholderContent: function(content) {
        let rows = content.map(function(line, index, array) {
            return <tr key={"defaultSourceContent-" + index}><td>{line}</td></tr>;
        });

        return (
            <div className="hljs" style={placeholderStyle}>
                <table style={ { width: "100%" } }>
                    <tbody>{rows}</tbody>
                </table>
            </div>
        );
    },

    _renderContent: function() {
        let currentContext = this.props.currentContext;
        let sourceContext = currentContext.threads[currentContext.activeThreadIndex].source;

        if (!sourceContext || !currentContext.sourceMap || !(sourceContext.file in currentContext.sourceMap) ) {
            return this._renderPlaceholderContent(noSourceContent);
        }

        let source = currentContext.sourceMap[sourceContext.file].lines.join("\n");

        let lineStart = currentContext.sourceMap[sourceContext.file].startLineNo;
        let activeLineNo = sourceContext.line;

        let highlightedSourceObj = hljs.highlightAuto(source, [ "C" ]);

        let numberedSourceRows = highlightedSourceObj.value.split("\n").map(function(line, index, array) {
            let currentLineNo = index + lineStart;

            let markedUpLine;
            let markedUpLineNo;
            if (activeLineNo == currentLineNo) {
                markedUpLine = '<td style="background-color: rgb(10,81,99); width: 100%;">' +
                    line +
                        '</td>';
                
                markedUpLineNo = ' ' + currentLineNo + ' >';
            }else{
                markedUpLine = '<td style="width: 100%;">' + line + '</td>';
                markedUpLineNo = ' ' + currentLineNo + '  ';
            }

            let lineNoCell = '<td style="' + 
                        'background-color: rgb(7,54,66);' + 
                        'border:1px solid rgb(7,54,66);' +
                        'color: rgb(131, 148, 150);' +
                   '">'
                   + markedUpLineNo + '</td>';
                   
            return '<tr>' + lineNoCell + markedUpLine + "</tr>";
        }).join("");

        return (
            <div className="hljs" style={topLevelStyle}>
                <table style={ { width: "100%" } }>
                    <tbody dangerouslySetInnerHTML={ { __html: numberedSourceRows } }/>
                </table>
            </div>
        );
    }
});

noSourceContent = [
        " ",
        "udidb - UDI debugger",
        " ",
        " ",
        " ",
        " ",
        "No source information available",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
];
<commit_msg>Remove line pointer in line number column<commit_after>/** 
 * The styling is currently hard-coded. It would be nice to let the user
 * select from some hljs themes eventually.
 */

import React from "react"
import hljs from "highlight.js"

let topLevelStyle = {
    fontFamily: 'monospace',
    whiteSpace: 'pre',
    border: '1px solid rgb(204, 204, 204)',
    borderRadius: '4px',
    padding: '5px 0px 5px 0px',
};

let placeholderStyle = Object.assign({
    textAlign: "center"
}, topLevelStyle);

let noSourceContent;

export default React.createClass({

    render: function() {
        if (this.props.currentContext === null) {
            return this._renderPlaceholderContent(this.props.defaultSourceContent);
        }else{
            return this._renderContent();
        }
    },

    _renderPlaceholderContent: function(content) {
        let rows = content.map(function(line, index, array) {
            return <tr key={"defaultSourceContent-" + index}><td>{line}</td></tr>;
        });

        return (
            <div className="hljs" style={placeholderStyle}>
                <table style={ { width: "100%" } }>
                    <tbody>{rows}</tbody>
                </table>
            </div>
        );
    },

    _renderContent: function() {
        let currentContext = this.props.currentContext;
        let sourceContext = currentContext.threads[currentContext.activeThreadIndex].source;

        if (!sourceContext || !currentContext.sourceMap || !(sourceContext.file in currentContext.sourceMap) ) {
            return this._renderPlaceholderContent(noSourceContent);
        }

        let source = currentContext.sourceMap[sourceContext.file].lines.join("\n");

        let lineStart = currentContext.sourceMap[sourceContext.file].startLineNo;
        let activeLineNo = sourceContext.line;

        let highlightedSourceObj = hljs.highlightAuto(source, [ "C" ]);

        let numberedSourceRows = highlightedSourceObj.value.split("\n").map(function(line, index, array) {
            let currentLineNo = index + lineStart;

            let markedUpLine;
            if (activeLineNo == currentLineNo) {
                markedUpLine = '<td style="background-color: rgb(10,81,99); width: 100%;">' +
                    line +
                        '</td>';
            }else{
                markedUpLine = '<td style="width: 100%;">' + line + '</td>';
            }

            let lineNoCell = '<td style="' + 
                        'background-color: rgb(7,54,66);' + 
                        'border:1px solid rgb(7,54,66);' +
                        'color: rgb(131, 148, 150);' +
                        'padding-left: 5px;' +
                        'padding-right: 5px;' +
                   '">'
                   + currentLineNo + '</td>';
                   
            return '<tr>' + lineNoCell + markedUpLine + "</tr>";
        }).join("");

        return (
            <div className="hljs" style={topLevelStyle}>
                <table style={ { width: "100%" } }>
                    <tbody dangerouslySetInnerHTML={ { __html: numberedSourceRows } }/>
                </table>
            </div>
        );
    }
});

noSourceContent = [
        " ",
        "udidb - UDI debugger",
        " ",
        " ",
        " ",
        " ",
        "No source information available",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
        " ",
];

{'fraction_non_alphanumeric': 0.13804857264593098, 'fraction_numerical': 0.01533873029399233, 'mean_word_length': 1.719969100038625, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623665', 'n_tokens_mistral': 2055, 'n_tokens_neox': 1881, 'n_words': 398}