<commit_before>"""
Container for the layout.
(Containers can contain other containers or user interface controls.)
"""
from __future__ import unicode_literals

from abc import ABCMeta, abstractmethod
from functools import partial
from six import with_metaclass, text_type
from six.moves import range

from .controls import UIControl, FormattedTextControl, UIContent, DummyControl
from .dimension import Dimension, sum_layout_dimensions, max_layout_dimensions, to_dimension, is_dimension
from .margins import Margin
from .screen import Point, WritePosition, _CHAR_CACHE
from .utils import explode_text_fragments

from prompt_toolkit.application.current import get_app
from prompt_toolkit.cache import SimpleCache
from prompt_toolkit.filters import to_filter, vi_insert_mode, emacs_insert_mode
from prompt_toolkit.formatted_text import to_formatted_text
from prompt_toolkit.formatted_text.utils import fragment_list_to_text, fragment_list_width
from prompt_toolkit.mouse_events import MouseEvent, MouseEventType
from prompt_toolkit.utils import take_using_weights, get_cwidth, to_int, to_str

__all__ = [
    'Container',
    'HorizontalAlign',
    'VerticalAlign',
    'HSplit',
    'VSplit',
    'FloatContainer',
    'Float',
    'WindowAlign',
    'Window',
    'WindowRenderInfo',
    'ConditionalContainer',
    'ScrollOffsets',
    'ColorColumn',
    'to_container',
    'to_window',
    'is_container',
    'DynamicContainer',
]


class Container(with_metaclass(ABCMeta, object)):
    """
    Base class for user interface layout.
    """
    @abstractmethod
    def reset(self):
        """
        Reset the state of this container and all the children.
        (E.g. reset scroll offsets, etc...)
        """

    @abstractmethod
    def preferred_width(self, max_available_width):
        """
        Return a :class:`~prompt_toolkit.layout.Dimension` that represents the
        desired width for this container.
        """

    @abstractmethod
    def preferred_height(self, width, max_available_height):
        """
        Return a :class:`~prompt_toolkit.layout.Dimension` that represents the
        desired height for this container.
        """

    @abstractmethod
    def write_to_screen(self, screen, mouse_handlers, write_position,
                        parent_style, erase_bg, z_index):
        """
        Write the actual content to the screen.

        :param screen: :class:`~prompt_toolkit.layout.screen.Screen`
        :param mouse_handlers: :class:`~prompt_toolkit.layout.mouse_handlers.MouseHandlers`.
        :param parent_style: Style string to pass to the :class:`.Window`
            object. This will be applied to all content of the windows.
            :class:`.VSplit` and :class:`.HSplit` can use it to pass their
            style down to the windows that they contain.
        :param z_index: Used for propagating z_index from parent to child.
        """

    def is_modal(self):
        """
        When this container is modal, key bindings from parent containers are
        not taken into account if a user control in this container is focused.
        """
        return False

    def get_key_bindings(self):
        """
        Returns a :class:`.KeyBindings` object. These bindings become active when any
        user control in this container has the focus, except if any containers
        between this container and the focused user control is modal.
        """
        return None

    @abstractmethod
    def get_children(self):
        """
        Return the list of child :class:`.Container` objects.
        """
        return []


def _window_too_small():
    " Create a `Window` that displays the 'Window too small' text. "
    return Window(FormattedTextControl(text=
        [('class:window-too-small', ' Window too small... ')]))


class VerticalAlign:
    " Alignment for `HSplit`. "
    TOP = 'TOP'
    CENTER = 'CENTER'
    BOTTOM = 'BOTTOM'
    JUSTIFY = 'JUSTIFY'


class HorizontalAlign:
    " Alignment for `VSplit`. "
    LEFT = 'LEFT'
    CENTER = 'CENTER'
    RIGHT = 'RIGHT'
    JUSTIFY = 'JUSTIFY'


class _Split(Container):
    """
    The common parts of `VSplit` and `HSplit`.
    """
    def __init__(self, children, window_too_small=None,
                 padding=Dimension.exact(0), padding_char=None,
                 padding_style='', width=None, height=None, z_index=None,
                 modal=False, key_bindings=None, style=''):
        assert window_too_small is None or isinstance(window_too_small, Container)
        assert isinstance(children, list)
        assert isinstance(modal, bool)
        assert callable(style) or isinstance(style, text_type)
        assert is_dimension(width)
        assert is_dimension(height)
        assert z_index is None or isinstance(z_index, int)  # `None` means: inherit from parent.
        assert is_dimension(padding)
        assert padding_char is None or isinstance(padding_char, text_type)
        assert isinstance(padding_style, text_type)

        self.children = [to_container(c) for c in children]
        self.window_too_small = window_too_small or _window_too_small()
        self.padding = padding
        self.padding_char = padding_char
        self.padding_style = padding_style
<commit_msg>Accept any collections.abc.Sequence for HSplit/VSplit children.<commit_after>"""
Container for the layout.
(Containers can contain other containers or user interface controls.)
"""
from __future__ import unicode_literals

from abc import ABCMeta, abstractmethod
from functools import partial
from six import with_metaclass, text_type
from six.moves import range

from .controls import UIControl, FormattedTextControl, UIContent, DummyControl
from .dimension import Dimension, sum_layout_dimensions, max_layout_dimensions, to_dimension, is_dimension
from .margins import Margin
from .screen import Point, WritePosition, _CHAR_CACHE
from .utils import explode_text_fragments

from prompt_toolkit.application.current import get_app
from prompt_toolkit.cache import SimpleCache
from prompt_toolkit.filters import to_filter, vi_insert_mode, emacs_insert_mode
from prompt_toolkit.formatted_text import to_formatted_text
from prompt_toolkit.formatted_text.utils import fragment_list_to_text, fragment_list_width
from prompt_toolkit.mouse_events import MouseEvent, MouseEventType
from prompt_toolkit.utils import take_using_weights, get_cwidth, to_int, to_str

try:
    from collections.abc import Sequence
except ImportError:
    from collections import Sequence

__all__ = [
    'Container',
    'HorizontalAlign',
    'VerticalAlign',
    'HSplit',
    'VSplit',
    'FloatContainer',
    'Float',
    'WindowAlign',
    'Window',
    'WindowRenderInfo',
    'ConditionalContainer',
    'ScrollOffsets',
    'ColorColumn',
    'to_container',
    'to_window',
    'is_container',
    'DynamicContainer',
]


class Container(with_metaclass(ABCMeta, object)):
    """
    Base class for user interface layout.
    """
    @abstractmethod
    def reset(self):
        """
        Reset the state of this container and all the children.
        (E.g. reset scroll offsets, etc...)
        """

    @abstractmethod
    def preferred_width(self, max_available_width):
        """
        Return a :class:`~prompt_toolkit.layout.Dimension` that represents the
        desired width for this container.
        """

    @abstractmethod
    def preferred_height(self, width, max_available_height):
        """
        Return a :class:`~prompt_toolkit.layout.Dimension` that represents the
        desired height for this container.
        """

    @abstractmethod
    def write_to_screen(self, screen, mouse_handlers, write_position,
                        parent_style, erase_bg, z_index):
        """
        Write the actual content to the screen.

        :param screen: :class:`~prompt_toolkit.layout.screen.Screen`
        :param mouse_handlers: :class:`~prompt_toolkit.layout.mouse_handlers.MouseHandlers`.
        :param parent_style: Style string to pass to the :class:`.Window`
            object. This will be applied to all content of the windows.
            :class:`.VSplit` and :class:`.HSplit` can use it to pass their
            style down to the windows that they contain.
        :param z_index: Used for propagating z_index from parent to child.
        """

    def is_modal(self):
        """
        When this container is modal, key bindings from parent containers are
        not taken into account if a user control in this container is focused.
        """
        return False

    def get_key_bindings(self):
        """
        Returns a :class:`.KeyBindings` object. These bindings become active when any
        user control in this container has the focus, except if any containers
        between this container and the focused user control is modal.
        """
        return None

    @abstractmethod
    def get_children(self):
        """
        Return the list of child :class:`.Container` objects.
        """
        return []


def _window_too_small():
    " Create a `Window` that displays the 'Window too small' text. "
    return Window(FormattedTextControl(text=
        [('class:window-too-small', ' Window too small... ')]))


class VerticalAlign:
    " Alignment for `HSplit`. "
    TOP = 'TOP'
    CENTER = 'CENTER'
    BOTTOM = 'BOTTOM'
    JUSTIFY = 'JUSTIFY'


class HorizontalAlign:
    " Alignment for `VSplit`. "
    LEFT = 'LEFT'
    CENTER = 'CENTER'
    RIGHT = 'RIGHT'
    JUSTIFY = 'JUSTIFY'


class _Split(Container):
    """
    The common parts of `VSplit` and `HSplit`.
    """
    def __init__(self, children, window_too_small=None,
                 padding=Dimension.exact(0), padding_char=None,
                 padding_style='', width=None, height=None, z_index=None,
                 modal=False, key_bindings=None, style=''):
        assert window_too_small is None or isinstance(window_too_small, Container)
        assert isinstance(children, Sequence)
        assert isinstance(modal, bool)
        assert callable(style) or isinstance(style, text_type)
        assert is_dimension(width)
        assert is_dimension(height)
        assert z_index is None or isinstance(z_index, int)  # `None` means: inherit from parent.
        assert is_dimension(padding)
        assert padding_char is None or isinstance(padding_char, text_type)
        assert isinstance(padding_style, text_type)

        self.children = [to_container(c) for c in children]
        self.window_too_small = window_too_small or _window_too_small()
        self.padding = padding
        self.padding_char = padding_char
        self.padding_style = padding_style

{'fraction_non_alphanumeric': 0.08317669172932331, 'fraction_numerical': 0.00018796992481203009, 'mean_word_length': 3.0879754129850174, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6326705', 'n_tokens_mistral': 2982, 'n_tokens_neox': 2916, 'n_words': 912}