<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals

import threading
import sublime
import time

if(int(sublime.version()) < 3000):
    import DeviotTools
else:
    from . import DeviotTools

python_version = DeviotTools.getPythonVersion()

if python_version < 3:
    import Queue as queue
else:
    import queue


class MessageQueue(object):
    """Message Queue

    Print messages in the user console,
    placed in the message queue
    """

    def __init__(self, console=None):
        self.queue = queue.Queue(0)
        self.is_alive = False
        self.console = console

    def put(self, text, *args):
        if text.endswith('\\n'):
            text = text[:-2] + '\n'
        self.queue.put(text)

    def startPrint(self, one_time=False):
        if not self.is_alive:
            self.is_alive = True
            thread = threading.Thread(
                target=lambda: self.printScreen(one_time))
            thread.start()

    def printScreen(self, one_time=False):
        if one_time:
            self.printOnce()
        else:
            while self.is_alive:
                self.printOnce()
                time.sleep(0.01)

    def printOnce(self):
        while not self.queue.empty():
            text = self.queue.get()
            print(text)
            if self.console:
                self.console.printScreen(text)
            else:
                print(text)
            time.sleep(0.01)

    def stopPrint(self):
        while(not self.queue.empty()):
            time.sleep(2)
        self.is_alive = False


class Console:
    """User Console

    Creates the user console to show different messages.
    """

    def __init__(self, window, name='deviot_console'):
        self.name = name
        self.window = window

        if python_version < 3:
            self.panel = self.window.get_output_panel(self.name)
        else:
            self.panel = self.window.create_output_panel(self.name)

        self.panel.set_name(self.name)

    def printScreen(self, text):
        sublime.set_timeout(lambda: self.println(text), 0)

    def println(self, text):
        if(len(text)):
            panel_name = 'output.' + self.name
            self.window.run_command("show_panel", {"panel": panel_name})
            self.panel.set_read_only(False)
            self.panel.run_command("append", {"characters": text})
            self.panel.set_read_only(True)<commit_msg>Added console support with ST2<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals

import threading
import sublime
import time

if(int(sublime.version()) < 3000):
    import DeviotTools
else:
    from . import DeviotTools

python_version = DeviotTools.getPythonVersion()

if python_version < 3:
    import Queue as queue
else:
    import queue


class MessageQueue(object):
    """Message Queue

    Print messages in the user console,
    placed in the message queue
    """

    def __init__(self, console=None):
        self.queue = queue.Queue(0)
        self.is_alive = False
        self.console = console

    def put(self, text, *args):
        if text.endswith('\\n'):
            text = text[:-2] + '\n'
        self.queue.put(text)

    def startPrint(self, one_time=False):
        if not self.is_alive:
            self.is_alive = True
            thread = threading.Thread(
                target=lambda: self.printScreen(one_time))
            thread.start()

    def printScreen(self, one_time=False):
        if one_time:
            self.printOnce()
        else:
            while self.is_alive:
                self.printOnce()
                time.sleep(0.01)

    def printOnce(self):
        while not self.queue.empty():
            text = self.queue.get()
            print(text)
            if self.console:
                self.console.printScreen(text)
            else:
                print(text)
            time.sleep(0.01)

    def stopPrint(self):
        while(not self.queue.empty()):
            time.sleep(2)
        self.is_alive = False


class Console:
    """User Console

    Creates the user console to show different messages.
    """

    def __init__(self, window, name='deviot_console'):
        self.name = name
        self.window = window

        if python_version < 3:
            self.panel = self.window.get_output_panel(self.name)
        else:
            self.panel = self.window.create_output_panel(self.name)

        self.panel.set_name(self.name)

    def printScreen(self, text):
        sublime.set_timeout(lambda: self.println(text), 0)

    def println(self, text):
        if(len(text)):
            panel_name = 'output.' + self.name
            self.window.run_command("show_panel", {"panel": panel_name})
            self.panel.set_read_only(False)
            if(python_version < 3):
                edit = self.panel.begin_edit()
                self.panel.insert(edit, self.panel.size(), text)
                self.panel.end_edit(edit)
            else:
                self.panel.run_command("append", {"characters": text})
            self.panel.set_read_only(True)
{'fraction_non_alphanumeric': 0.10508664058133035, 'fraction_numerical': 0.006707657909446618, 'mean_word_length': 2.070938215102975, 'pattern_counts': {'":': 4, '<': 10, '<?xml version=': 0, '>': 3, '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': '7510945', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1554, 'n_words': 362}