# Path: px/px_terminal.py
# KEY_ESC = "\x1b"
# KEY_DELETE = "\x1b[3~"
# KEY_BACKSPACE = "\x7f"
# KEY_UPARROW = "\x1b[A"
# KEY_DOWNARROW = "\x1b[B"
# KEY_ENTER = "\x0d"
# CSI = "\x1b["
# CURSOR_TO_TOP_LEFT = CSI + u"H"
# CURSOR_TO_RIGHT_EDGE = CSI + u"999C"  # Actually "999 steps to the right"
# CLEAR_SCREEN = CSI + u"1J" + CURSOR_TO_TOP_LEFT
# HIDE_CURSOR = CSI + u"?25l"
# SHOW_CURSOR = CSI + u"?25h"
# CLEAR_TO_EOL = CSI + u"0K"
# CLEAR_TO_END_OF_SCREEN = CSI + "J"  # Clear from cursor to end of screen
# SIGWINCH_PIPE = os.pipe()
# SIGWINCH_KEY = u"\x00"
# def disable_color():
# def sigwinch_handler(signum, frame):
#     def __init__(self, string):
#     def __len__(self):
#     def consume(self, to_consume):
# def read_select(
#     fds,  # type: List[int]
#     timeout_seconds=None,  # type: Optional[int]
# ):
# def getch(timeout_seconds=None, fd=None):
#     def __init__(self, message):
# def get_window_size():
# def raw_lines_to_screen_lines(raw_lines, columns):
# def filter_out_unchanged_screen_lines(all_screen_lines, columns):
# def draw_screen_lines(lines, columns):
# def width_specifier(width, right_align=False):
# def format_with_widths(widths, strings):
# def to_screen_lines(
#     procs,  # type: List[px_process.PxProcess]
#     row_to_highlight,  # type: Optional[int]
#     highlight_heading,  # type: Optional[text_type]
#     with_username=True,  # type: bool
# ):
# def inverse_video(string):
# def bold(string):
# def faint(string):
# def underline(string):
# def red(string):
# def yellow(string):
# def green(string):
# def blue(string):
# def get_string_of_length(string, length):
# def _tokenize(string):
# def crop_ansi_string_at_length(string, length):
# def visual_length(string):
# def _enter_fullscreen():
# def _exit_fullscreen():
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
# class ConsumableString(object):
# class TerminalError(Exception):
# class fullscreen_display:
# class normal_display:
# 
# Path: px/px_launchcounter.py
# def render_launch_tuple(launch_tuple):
# def _get_minus_max_score(tuples_list):
# def sort_launchers_list(launchers_list):
#     def __init__(self):
#     def _strip_parentheses(self, s):
#     def _callchain(self, process):
#     def _register_launches(self, new_processes):
#     def _list_new_launches(
#         self,
#         before,  # type: List[px_process.PxProcess]
#         after,  # type: List[px_process.PxProcess]
#     ):
#     def update(self, procs_snapshot):
#     def _to_tuple_list(self, launcher_list, count):
#     def _merge_tuple_lists(
#         self,
#         tl1,  # type: List[Tuple[text_type, int]]
#         tl2,  # type: List[Tuple[text_type, int]]
#     ):
#     def _coalesce_launchers(self):
#     def get_screen_lines(self):
# class Launchcounter(object):


from px import px_terminal
from px import px_launchcounter
from . import testutils


def test_to_tuple_list():
    launchcounter = px_launchcounter.Launchcounter()
    assert launchcounter._to_tuple_list(("a", "b", "c"), 5) == [
        ("a", 0),
        ("b", 0),
        ("c", 5),
    ]

    assert launchcounter._to_tuple_list(("a",), 5) == [("a", 5)]


def test_merge_tuple_lists():
    launchcounter = px_launchcounter.Launchcounter()
    l1 = [(u"a", 0), (u"b", 2), (u"c", 5)]
    l2 = [(u"a", 0), (u"b", 4)]
    l3 = [(u"a", 0), (u"e", 4)]

    assert launchcounter._merge_tuple_lists(l1, l2) == [(u"a", 0), (u"b", 6), (u"c", 5)]

    assert launchcounter._merge_tuple_lists(l1, l3) is None


def test_sort_launchers_lists():
    l1 = [(u"a", 3), (u"b", 4)]
    l2 = [(u"a", 5), (u"e", 0)]

    # List with highest individual number should come first
    assert px_launchcounter.sort_launchers_list([l1, l2]) == [l2, l1]

# Path: px/px_terminal.py
# KEY_ESC = "\x1b"
# KEY_DELETE = "\x1b[3~"
# KEY_BACKSPACE = "\x7f"
# KEY_UPARROW = "\x1b[A"
# KEY_DOWNARROW = "\x1b[B"
# KEY_ENTER = "\x0d"
# CSI = "\x1b["
# CURSOR_TO_TOP_LEFT = CSI + u"H"
# CURSOR_TO_RIGHT_EDGE = CSI + u"999C"  # Actually "999 steps to the right"
# CLEAR_SCREEN = CSI + u"1J" + CURSOR_TO_TOP_LEFT
# HIDE_CURSOR = CSI + u"?25l"
# SHOW_CURSOR = CSI + u"?25h"
# CLEAR_TO_EOL = CSI + u"0K"
# CLEAR_TO_END_OF_SCREEN = CSI + "J"  # Clear from cursor to end of screen
# SIGWINCH_PIPE = os.pipe()
# SIGWINCH_KEY = u"\x00"
# def disable_color():
# def sigwinch_handler(signum, frame):
#     def __init__(self, string):
#     def __len__(self):
#     def consume(self, to_consume):
# def read_select(
#     fds,  # type: List[int]
#     timeout_seconds=None,  # type: Optional[int]
# ):
# def getch(timeout_seconds=None, fd=None):
#     def __init__(self, message):
# def get_window_size():
# def raw_lines_to_screen_lines(raw_lines, columns):
# def filter_out_unchanged_screen_lines(all_screen_lines, columns):
# def draw_screen_lines(lines, columns):
# def width_specifier(width, right_align=False):
# def format_with_widths(widths, strings):
# def to_screen_lines(
#     procs,  # type: List[px_process.PxProcess]
#     row_to_highlight,  # type: Optional[int]
#     highlight_heading,  # type: Optional[text_type]
#     with_username=True,  # type: bool
# ):
# def inverse_video(string):
# def bold(string):
# def faint(string):
# def underline(string):
# def red(string):
# def yellow(string):
# def green(string):
# def blue(string):
# def get_string_of_length(string, length):
# def _tokenize(string):
# def crop_ansi_string_at_length(string, length):
# def visual_length(string):
# def _enter_fullscreen():
# def _exit_fullscreen():
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
# class ConsumableString(object):
# class TerminalError(Exception):
# class fullscreen_display:
# class normal_display:
# 
# Path: px/px_launchcounter.py
# def render_launch_tuple(launch_tuple):
# def _get_minus_max_score(tuples_list):
# def sort_launchers_list(launchers_list):
#     def __init__(self):
#     def _strip_parentheses(self, s):
#     def _callchain(self, process):
#     def _register_launches(self, new_processes):
#     def _list_new_launches(
#         self,
#         before,  # type: List[px_process.PxProcess]
#         after,  # type: List[px_process.PxProcess]
#     ):
#     def update(self, procs_snapshot):
#     def _to_tuple_list(self, launcher_list, count):
#     def _merge_tuple_lists(
#         self,
#         tl1,  # type: List[Tuple[text_type, int]]
#         tl2,  # type: List[Tuple[text_type, int]]
#     ):
#     def _coalesce_launchers(self):
#     def get_screen_lines(self):
# class Launchcounter(object):


# Path: tests/px_launchcounter_test.py
from px import px_terminal
from px import px_launchcounter
from . import testutils



def test_to_tuple_list():
    launchcounter = px_launchcounter.Launchcounter()
    assert launchcounter._to_tuple_list(("a", "b", "c"), 5) == [
        ("a", 0),
        ("b", 0),
        ("c", 5),
    ]

    assert launchcounter._to_tuple_list(("a",), 5) == [("a", 5)]


def test_merge_tuple_lists():
    launchcounter = px_launchcounter.Launchcounter()
    l1 = [(u"a", 0), (u"b", 2), (u"c", 5)]
    l2 = [(u"a", 0), (u"b", 4)]
    l3 = [(u"a", 0), (u"e", 4)]

    assert launchcounter._merge_tuple_lists(l1, l2) == [(u"a", 0), (u"b", 6), (u"c", 5)]

    assert launchcounter._merge_tuple_lists(l1, l3) is None


def test_sort_launchers_lists():
    l1 = [(u"a", 3), (u"b", 4)]
    l2 = [(u"a", 5), (u"e", 0)]

    # List with highest individual number should come first
    assert px_launchcounter.sort_launchers_list([l1, l2]) == [l2, l1]

    assert px_launchcounter.sort_launchers_list([l2, l1]) == [l2, l1]