<commit_before>import React, { Component, PropTypes } from "react";
import Localization from "localization";
import util from "../../utils";
import "../Prompt.less";
import Cookies from 'universal-cookie';
const cookies = new Cookies();
import { formatString } from "../../helpers";

class Input extends Component {

    componentDidUpdate() {
        //This should be replaced by User Personalization API
        const consoleHeight = cookies.get("dnn-prompt-console-height");
        if (consoleHeight) {
            this.configConsole(['config', consoleHeight]);
        }
    }
    setValue(value) {
        this.cmdPromptInput.value = value;
    }
    getValue() {
        return this.cmdPromptInput.value;
    }
    setFocus(focus) {
        if (focus)
            this.cmdPromptInput.focus();
        else
            this.cmdPromptInput.blur();
    }
    toggleInput(show) {
        this.cmdPromptInputDiv.style.display = show ? "block" : "none";
    }
    getTabId() {
        const dnnVariable = JSON.parse(window.parent.document.getElementsByName("__dnnVariable")[0].value);
        return dnnVariable.sf_tabId;
    }
    runCmd() {
        const self = this;
        const { props } = self;
        const { actions } = props;
        let txt = self.getValue().trim();
        if (txt === "" && props.nextPageCommand !== null && props.nextPageCommand != "")
            txt = props.nextPageCommand;
        if (!self.tabId) {
            self.tabId = self.getTabId();
        }

        self.cmdOffset = 0; // reset history index
        self.setValue(""); // clearn input for future commands.

        if (txt === "") {
            return;
        } // don't process if cmd is emtpy
        actions.runLocalCommand("INFO", "\n" + txt + "\n", "cmd");
        if (props.nextPageCommand === null || props.nextPageCommand === "")
            props.updateHistory(txt); // Add cmd to history
        // Client Command
        const tokens = txt.split(" "),
            cmd = tokens[0].toUpperCase();

        if (cmd === "CLS" || cmd === "CLEAR-SCREEN" || cmd === "EXIT" || cmd === "RELOAD") {
            actions.runLocalCommand(cmd, null);
            return;
        }
        if (cmd === "CLH" || cmd === "CLEAR-HISTORY") {
            props.updateHistory("", true);
            actions.runLocalCommand(cmd, Localization.get("SessionHisotryCleared"));
            return;
        }
        if (cmd === "CONFIG") {
            this.configConsole(tokens);
            return;
        }

        if (cmd === "SET-MODE") {
            self.changeUserMode(tokens);
            return;
        }
        // Server Command
        props.busy(true);
        if (cmd === "HELP") {
            if (txt.toUpperCase() === "HELP") {
                actions.getCommandList({ cmdLine: "list-commands", currentPage: self.tabId }, () => {
                    props.busy(false);
                }, (error) => {
                    props.busy(false);
                    actions.runLocalCommand("ERROR", error.responseJSON.Message);
                });
            } else {
                actions.runHelpCommand({ cmdLine: txt, currentPage: self.tabId }, () => {
                props.busy(false);
            }, (error) => {
                props.busy(false);
                    actions.runLocalCommand("ERROR", error.responseJSON.Message);
            });
            }
        } else {
            actions.runCommand(
                { cmdLine: txt, currentPage: self.tabId },
                (data) => {
                    props.busy(false);
                },
                (error) => {
                    props.busy(false);
                    actions.runLocalCommand("ERROR", error.responseJSON.Message);
                });
        }
        this.setFocus(false);
    }

    changeUserMode(tokens) {
        let { props } = this;
        const { actions } = props;
        if (!tokens && tokens.length >= 2) {
            return;
        }
        let mode = null;
        if (this.hasFlag("--mode")) {
            mode = this.getFlag("--mode", tokens);
        } else if (!this.isFlag(tokens[1])) {
            mode = tokens[1];
        }
        if (mode) {
            actions.changeUserMode({ UserMode: mode.toUpperCase() }, () => {
                if (mode.toUpperCase() === "EDIT")
                    util.utilities.closePersonaBar();
                window.parent.document.location.reload(true);
            }, (error) => {
                actions.runLocalCommand("ERROR", error);
            });<commit_msg>DNN-10617 Code review<commit_after>import React, { Component, PropTypes } from "react";
import Localization from "localization";
import util from "../../utils";
import "../Prompt.less";
import Cookies from 'universal-cookie';
const cookies = new Cookies();
import { formatString } from "../../helpers";

class Input extends Component {

    componentDidUpdate() {
        //This should be replaced by User Personalization API
        const consoleHeight = cookies.get("dnn-prompt-console-height");
        if (consoleHeight) {
            this.configConsole(['config', consoleHeight]);
        }
    }
    setValue(value) {
        this.cmdPromptInput.value = value;
    }
    getValue() {
        return this.cmdPromptInput.value;
    }
    setFocus(focus) {
        if (focus)
            this.cmdPromptInput.focus();
        else
            this.cmdPromptInput.blur();
    }
    toggleInput(show) {
        this.cmdPromptInputDiv.style.display = show ? "block" : "none";
    }
    getTabId() {
        const dnnVariable = JSON.parse(window.parent.document.getElementsByName("__dnnVariable")[0].value);
        return dnnVariable.sf_tabId;
    }
    runCmd() {
        const self = this;
        const { props } = self;
        const { actions } = props;
        let txt = self.getValue().trim();
        if (txt === "" && props.nextPageCommand !== null && props.nextPageCommand != "")
            txt = props.nextPageCommand;
        if (!self.tabId) {
            self.tabId = self.getTabId();
        }

        self.cmdOffset = 0; // reset history index
        self.setValue(""); // clearn input for future commands.

        if (txt === "") {
            return;
        } // don't process if cmd is emtpy
        actions.runLocalCommand("INFO", "\n" + txt + "\n", "cmd");
        if (props.nextPageCommand === null || props.nextPageCommand === "")
            props.updateHistory(txt); // Add cmd to history
        // Client Command
        const tokens = txt.split(" "),
            cmd = tokens[0].toUpperCase();

        if (cmd === "CLS" || cmd === "CLEAR-SCREEN" || cmd === "EXIT" || cmd === "RELOAD") {
            actions.runLocalCommand(cmd, null);
            return;
        }
        if (cmd === "CLH" || cmd === "CLEAR-HISTORY") {
            props.updateHistory("", true);
            actions.runLocalCommand(cmd, Localization.get("SessionHisotryCleared"));
            return;
        }
        if (cmd === "CONFIG") {
            this.configConsole(tokens);
            return;
        }

        if (cmd === "SET-MODE") {
            self.changeUserMode(tokens);
            return;
        }
        // Server Command
        props.busy(true);
        if (cmd === "HELP") {
            if (txt.toUpperCase() === "HELP") {
                actions.getCommandList({ cmdLine: "list-commands", currentPage: self.tabId }, () => {
                    props.busy(false);
                }, (error) => {
                    props.busy(false);
                    actions.runLocalCommand("ERROR", error.responseJSON.Message);
                });
            } else {
                actions.runHelpCommand({ cmdLine: txt, currentPage: self.tabId }, () => {
                props.busy(false);
            }, (error) => {
                props.busy(false);
                    actions.runLocalCommand("ERROR", error.responseJSON.Message);
            });
            }
        } else {
            actions.runCommand(
                { cmdLine: txt, currentPage: self.tabId },
                () => {
                    props.busy(false);
                },
                (error) => {
                    props.busy(false);
                    actions.runLocalCommand("ERROR", error.responseJSON.Message);
                });
        }
        this.setFocus(false);
    }

    changeUserMode(tokens) {
        let { props } = this;
        const { actions } = props;
        if (!tokens && tokens.length >= 2) {
            return;
        }
        let mode = null;
        if (this.hasFlag("--mode")) {
            mode = this.getFlag("--mode", tokens);
        } else if (!this.isFlag(tokens[1])) {
            mode = tokens[1];
        }
        if (mode) {
            actions.changeUserMode({ UserMode: mode.toUpperCase() }, () => {
                if (mode.toUpperCase() === "EDIT")
                    util.utilities.closePersonaBar();
                window.parent.document.location.reload(true);
            }, (error) => {
                actions.runLocalCommand("ERROR", error);
            });
{'fraction_non_alphanumeric': 0.14603139509175325, 'fraction_numerical': 0.0018792836612867565, 'mean_word_length': 1.6391481913652275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5567166', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2436, 'n_words': 499}