<commit_before>/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2014 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
 */

define([
    "jquery",
    "latest/cockpit",
    "latest/term"
], function($, cockpit, Terminal) {
    "use strict";

    var docker = { };

    function docker_debug() {
        if (window.debugging == "all" || window.debugging == "docker")
            console.debug.apply(console, arguments);
    }

    function DockerTerminal(parent, channel) {
        var self = this;

        var term = new Terminal({
            cols: 80,
            rows: 24,
            screenKeys: true
        });

        var enable_input = true;
        var decoder = cockpit.utf8_decoder();
        var encoder = cockpit.utf8_encoder();

        /* term.js wants the parent element to build its terminal inside of */
        parent.empty();
        term.open(parent[0]);

        $(channel).
            on("close", function(ev, options) {
                self.connected = false;
                var problem = options.problem || "disconnected";
                term.write('\x1b[31m' + problem + '\x1b[m\r\n');
                self.typeable(false);
                $(channel).off("message");
                channel = null;
            });

        self.process = function process(buffer) {
                term.write(decoder.decode(buffer));
        };

        term.on('data', function(data) {
            /* Send typed input back through channel */
            if (enable_input && channel)
                channel.send(encoder.encode(data));
        });

        /* Shows and hides the cursor */
        self.typeable = function typeable(yes) {
            if (yes) {
                term.cursorHidden = false;
                term.showCursor();
            } else {
                /* There's no term.hideCursor() function */
                term.cursorHidden = true;
                term.refresh(term.y, term.y);
            }
            enable_input = yes;
        };<commit_msg>docker: Fix display of HTTP headers in docker terminal<commit_after>/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2014 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
 */

define([
    "jquery",
    "latest/cockpit",
    "latest/term"
], function($, cockpit, Terminal) {
    "use strict";

    var docker = { };

    function docker_debug() {
        if (window.debugging == "all" || window.debugging == "docker")
            console.debug.apply(console, arguments);
    }

    function DockerTerminal(parent, channel) {
        var self = this;

        var term = new Terminal({
            cols: 80,
            rows: 24,
            screenKeys: true
        });

        var enable_input = true;
        var decoder = cockpit.utf8_decoder();
        var encoder = cockpit.utf8_encoder();

        /* term.js wants the parent element to build its terminal inside of */
        parent.empty();
        term.open(parent[0]);

        $(channel).
            on("close", function(ev, options) {
                self.connected = false;
                var problem = options.problem || "disconnected";
                term.write('\x1b[31m' + problem + '\x1b[m\r\n');
                self.typeable(false);
                $(channel).off("message");
                channel = null;
            });

        self.process = function process(buffer) {
            term.write(decoder.decode(buffer));
            return buffer.length;
        };

        term.on('data', function(data) {
            /* Send typed input back through channel */
            if (enable_input && channel)
                channel.send(encoder.encode(data));
        });

        /* Shows and hides the cursor */
        self.typeable = function typeable(yes) {
            if (yes) {
                term.cursorHidden = false;
                term.showCursor();
            } else {
                /* There's no term.hideCursor() function */
                term.cursorHidden = true;
                term.refresh(term.y, term.y);
            }
            enable_input = yes;
        };
{'fraction_non_alphanumeric': 0.10872432636140945, 'fraction_numerical': 0.006406632749199171, 'mean_word_length': 1.8942202835332607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6096242', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1346, 'n_words': 464}