# Path: util.py
# def main_thread(callback, *args, **kwargs):
#     """
#     Sends the callback to the sublime main thread by using the sublime.set_timeout function.
#     Most of the sublime functions need to be called from the main thread
# 
#     :param callback: The callback function
#     :param args: positional args to send to the callback function
#     :param kwargs: keyword args to send to the callback function
#     """
#     # sublime.set_timeout gets used to send things onto the main thread
#     # most sublime.[something] calls need to be on the main thread
#     sublime.set_timeout(functools.partial(callback, *args, **kwargs), 0)


import threading
from util import main_thread



class _FilterArgs(object):
    def __init__(self, filter_file, view):
        """
        :type filter_file: serial_filter.FilterFile
        :type view: sublime.View
        """
        self.filter_file = filter_file
        self.view = view

    def apply(self, text, timestamp=""):
        if self.filter_file.check_filters(text):
            self.write(text, timestamp)

    def write(self, text, timestamp=""):

# Path: util.py
# def main_thread(callback, *args, **kwargs):
#     """
#     Sends the callback to the sublime main thread by using the sublime.set_timeout function.
#     Most of the sublime functions need to be called from the main thread
# 
#     :param callback: The callback function
#     :param args: positional args to send to the callback function
#     :param kwargs: keyword args to send to the callback function
#     """
#     # sublime.set_timeout gets used to send things onto the main thread
#     # most sublime.[something] calls need to be on the main thread
#     sublime.set_timeout(functools.partial(callback, *args, **kwargs), 0)


# Path: filter/manager.py
import threading
from util import main_thread



class _FilterArgs(object):
    def __init__(self, filter_file, view):
        """
        :type filter_file: serial_filter.FilterFile
        :type view: sublime.View
        """
        self.filter_file = filter_file
        self.view = view

    def apply(self, text, timestamp=""):
        if self.filter_file.check_filters(text):
            self.write(text, timestamp)

    def write(self, text, timestamp=""):

        main_thread(self.view.run_command, "serial_monitor_write", {"text": timestamp + text})
