<commit_before>// -------------------------------------------------
// --------------- Terminal Emulator ---------------
// -------------------------------------------------
// http://lxr.free-electrons.com/source/drivers/tty/vt/vt.c

"use strict";

var UTF8 = require('../../lib/utf8');
var message = require('../messagehandler');

var Colors = new Array(
    // standard colors
    "#000000", "#BB0000", "#00BB00", "#BBBB00",
    "#0000BB", "#BB00BB", "#00BBBB", "#BBBBBB",
    // brighter colors
    "#555555", "#FF5555", "#55FF55", "#FFFF55",
    "#5555FF", "#FF55FF", "#55FFFF", "#FFFFFF",
    // dimmed colors
    "#000000", "#770000", "#007700", "#777700",
    "#000077", "#770077", "#007777", "#777777"
);

// constructor
function Terminal(nrows, ncolumns, elemId) {
    this.nrows = nrows;
    this.ncolumns = ncolumns;

    var ele = document.getElementById(elemId);
    if (ele.tagName == "CANVAS") {
        this.canvas = ele;
        this.context = this.canvas.getContext("2d");
        this.context.font = "13px courier,fixed,swiss,monospace,sans-serif";
    } else {
        this.Table = ele;
        this.rowelements = new Array(this.nrows);
        for (var i = 0; i < nrows; i++) {
            var TR = this.Table.insertRow(0);
            var TD = document.createElement("td");
            this.rowelements[i] = TD;
            TR.appendChild(TD);
        }
    }

    this.cursorvisible = false;
    this.escapetype = 0;
    this.escapestring = "";
    this.cursorx = 0;
    this.cursory = 0;
    this.scrolltop = 0;
    this.cursortype = 1;
    this.scrollbottom = this.nrows-1;

    this.attr_color = 0x7;
    this.attr_reverse = false;
    this.attr_italic = false;
    this.attr_intensity = 0x1;

    this.pauseblink = false;
    this.OnCharReceived = function (){};
    if (!this.canvas) this.Table.addEventListener("wheel", this.UpdateScreenForScroll);
    //this.Table.onwheel = function(){};

    this.framerequested = false;
    this.timeout = 30; // the time in ms when the next frame is drawn

    this.updaterow = new Uint8Array(this.nrows);

    this.utf8converter = new UTF8.UTF8StreamToUnicode();

    this.trows = 50;
    this.brows = this.trows - this.nrows;
    this.screen = new Array(this.trows);
    this.color = new Array(this.trows);
    for (var i = 0; i < this.trows; i++) {
        this.updaterow[i] = 1;
        this.screen[i] = new Uint16Array(this.ncolumns);
        this.color[i]  = new Uint16Array(this.ncolumns);

        for (var j = 0; j < this.ncolumns; j++) {
            this.screen[i][j] = 0x20;
            this.color[i][j] = this.attr_color;
        }
    }
    this.UpdateScreen();
    this.Blink();
}

// Stop blinking cursor when the VM is paused
Terminal.prototype.PauseBlink = function(pause) {
    pause = !! pause;
    this.pauseblink = pause;
    if (this.cursortype) {
        this.cursorvisible = ! pause;
    }
    this.PrepareUpdateRow(this.cursory, this.cursorx);
}

Terminal.prototype.GetColor = function() {
    var c = this.attr_color;
    if (this.attr_reverse) {
        c = ((c & 0x7) << 8) | ((c >> 8)) & 0x7;
    }
    if (this.attr_intensity == 2) {
        c = c | 0x8;
    } else
    if (this.attr_intensity == 0) {
        c = c | 0x10;
    }
    return c;
}

Terminal.prototype.Blink = function() {
    this.cursorvisible = !this.cursorvisible;
    if(!this.pauseblink) this.PrepareUpdateRow(this.cursory, this.cursorx);
    window.setTimeout(this.Blink.bind(this), 500); // update every half second
};

Terminal.prototype.DeleteRow = function(row) {
    for(var i = 0;i <= this.brows;i++)
        this.screen[i] = this.screen[i + 1];
    for (var j = 0; j < this.ncolumns; j++) {
        this.screen[this.brows + row][j] = 0x20;
        this.color[this.brows + row][j] = this.attr_color;
    }
    this.PrepareUpdateRow(row);
};

Terminal.prototype.DeleteArea = function(row, column, row2, column2) {
    for (var i = row; i <= row2; i++) {
        for(var k = 0;k <= this.brows;k++)
            this.screen[k] = this.screen[k + 1];
        for (var j = column; j <= column2; j++) {
            this.screen[this.brows + i][j] = 0x20;
            this.color[this.brows + i][j] = this.attr_color;
        }
        this.PrepareUpdateRow(i);
    }
};


Terminal.prototype.UpdateRowCanvas = function(row) {
    var y = row << 4;
    var line = this.screen[this.brows + row];
    var c = this.color[this.brows + row][0]|0;
    var n = 0;

    for (var column = 0; column < this.ncolumns; column++) {

        var cnew = this.color[row][column]|0;

        if (this.cursorvisible)
        if (row == this.cursory)
        if (column == this.cursorx) {
            cnew |= 0x600;
        }

        if (c != cnew) {
            var x = (column - n) << 3;<commit_msg>Fixed some errors in terminal.js<commit_after>// -------------------------------------------------
// --------------- Terminal Emulator ---------------
// -------------------------------------------------
// http://lxr.free-electrons.com/source/drivers/tty/vt/vt.c

"use strict";

var UTF8 = require('../../lib/utf8');
var message = require('../messagehandler');

var Colors = new Array(
    // standard colors
    "#000000", "#BB0000", "#00BB00", "#BBBB00",
    "#0000BB", "#BB00BB", "#00BBBB", "#BBBBBB",
    // brighter colors
    "#555555", "#FF5555", "#55FF55", "#FFFF55",
    "#5555FF", "#FF55FF", "#55FFFF", "#FFFFFF",
    // dimmed colors
    "#000000", "#770000", "#007700", "#777700",
    "#000077", "#770077", "#007777", "#777777"
);

// constructor
function Terminal(nrows, ncolumns, elemId) {
    this.nrows = nrows;
    this.ncolumns = ncolumns;

    var ele = document.getElementById(elemId);
    if (ele.tagName == "CANVAS") {
        this.canvas = ele;
        this.context = this.canvas.getContext("2d");
        this.context.font = "13px courier,fixed,swiss,monospace,sans-serif";
    } else {
        this.Table = ele;
        this.rowelements = new Array(this.nrows);
        for (var i = 0; i < nrows; i++) {
            var TR = this.Table.insertRow(0);
            var TD = document.createElement("td");
            this.rowelements[i] = TD;
            TR.appendChild(TD);
        }
    }

    this.cursorvisible = false;
    this.escapetype = 0;
    this.escapestring = "";
    this.cursorx = 0;
    this.cursory = 0;
    this.scrolltop = 0;
    this.cursortype = 1;
    this.scrollbottom = this.nrows-1;

    this.attr_color = 0x7;
    this.attr_reverse = false;
    this.attr_italic = false;
    this.attr_intensity = 0x1;

    this.pauseblink = false;
    this.OnCharReceived = function (){};
    if (!this.canvas) this.Table.addEventListener("wheel", this.UpdateScreenForScroll);
    //this.Table.onwheel = function(){};

    this.framerequested = false;
    this.timeout = 30; // the time in ms when the next frame is drawn

    this.updaterow = new Uint8Array(this.nrows);

    this.utf8converter = new UTF8.UTF8StreamToUnicode();

    this.trows = 50;
    this.brows = this.trows - this.nrows;
    this.screen = new Array(this.trows);
    this.color = new Array(this.trows);
    for (var i = 0; i < this.trows; i++) {
        this.updaterow[i] = 1;
        this.screen[i] = new Uint16Array(this.ncolumns);
        this.color[i]  = new Uint16Array(this.ncolumns);

        for (var j = 0; j < this.ncolumns; j++) {
            this.screen[i][j] = 0x20;
            this.color[i][j] = this.attr_color;
        }
    }
    this.UpdateScreen();
    this.Blink();
}

// Stop blinking cursor when the VM is paused
Terminal.prototype.PauseBlink = function(pause) {
    pause = !! pause;
    this.pauseblink = pause;
    if (this.cursortype) {
        this.cursorvisible = ! pause;
    }
    this.PrepareUpdateRow(this.cursory, this.cursorx);
}

Terminal.prototype.GetColor = function() {
    var c = this.attr_color;
    if (this.attr_reverse) {
        c = ((c & 0x7) << 8) | ((c >> 8)) & 0x7;
    }
    if (this.attr_intensity == 2) {
        c = c | 0x8;
    } else
    if (this.attr_intensity == 0) {
        c = c | 0x10;
    }
    return c;
}

Terminal.prototype.Blink = function() {
    this.cursorvisible = !this.cursorvisible;
    if(!this.pauseblink) this.PrepareUpdateRow(this.cursory, this.cursorx);
    window.setTimeout(this.Blink.bind(this), 500); // update every half second
};

Terminal.prototype.DeleteRow = function(row) {
    for(var i = 0;i <= this.brows;i++){
        this.screen[i] = this.screen[i + 1];
            this.color[i] = this.color[i + 1];
    }
    for (var j = 0; j < this.ncolumns; j++) {
        this.screen[this.brows + row][j] = 0x20;
        this.color[this.brows + row][j] = this.attr_color;
    }
    this.PrepareUpdateRow(row);
};

Terminal.prototype.DeleteArea = function(row, column, row2, column2) {
    for (var i = row; i <= row2; i++) {
        for(var k = 0;k <= this.brows;k++){
            this.screen[k] = this.screen[k + 1];
            this.color[k] = this.color[k + 1];
        }
        for (var j = column; j <= column2; j++) {
            this.screen[this.brows + i][j] = 0x20;
            this.color[this.brows + i][j] = this.attr_color;
        }
        this.PrepareUpdateRow(i);
    }
};


Terminal.prototype.UpdateRowCanvas = function(row) {
    var y = row << 4;
    var line = this.screen[this.brows + row];
    var c = this.color[this.brows + row][0]|0;
    var n = 0;

    for (var column = 0; column < this.ncolumns; column++) {

        var cnew = this.color[row][column]|0;

        if (this.cursorvisible)
        if (row == this.cursory)
        if (column == this.cursorx) {
            cnew |= 0x600;
        }

        if (c != cnew) {
            var x = (column - n) << 3;
{'fraction_non_alphanumeric': 0.1869479372337109, 'fraction_numerical': 0.03616335861997298, 'mean_word_length': 2.1762376237623764, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 7, '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': '3187744', 'n_tokens_mistral': 3571, 'n_tokens_neox': 3315, 'n_words': 699}