Exemple #1
0
def new_view(window: sublime.Window, **kwargs: Any) -> sublime.View:
    """Open a new view in the given `window`, returning the :class:`~sublime.View` object.

    This function takes many optional keyword arguments:

    :argument content: Text to be inserted into the new view. The text will be inserted even
        if the `read_only` option is ``True``.

    :argument encoding: The encoding that the view should use when saving.

    :argument line_endings: The kind of line endings to use.
        The given value will be passed to :class:`LineEnding`.

    :argument name: The name of the view. This will be shown as the title of the view's tab.

    :argument overwrite: If ``True``, the view will be in overwrite mode.

    :argument read_only: If ``True``, the view will be read-only.

    :argument scope: A scope name.
        The view will be assigned a syntax definition that corresponds to the given scope
        (as determined by :func:`~sublime_lib.get_syntax_for_scope`).
        Incompatible with the `syntax` option.

    :argument scratch: If ``True``, the view will be a scratch buffer.
        The user will not be prompted to save the view before closing it.

    :argument settings: A dictionary of names and values
        that will be applied to the new view's Settings object.

    :argument syntax: The resource path of a syntax definition that the view will use.
        Incompatible with the `scope` option.

    :raise ValueError: if both `scope` and `syntax` are specified.
    :raise ValueError: if `encoding` is not a Python encoding name.
    :raise ValueError: if `line_endings` cannot be converted to :class:`LineEnding`.

    ..  versionchanged:: 1.2
        Added the `line_endings` argument.
    """
    validate_view_options(kwargs)

    view = window.new_file()
    set_view_options(view, **kwargs)
    return view
    def __init__(self,
                 window: sublime.Window,
                 name: str,
                 on_close: Callable[[], None] | None = None):

        DebuggerPreConsoleWindowHooks(window).run()
        view = window.new_file(flags=sublime.SEMI_TRANSIENT)
        DebuggerPostConsoleViewHooks(view).run()

        super().__init__(view)

        self.on_close = on_close
        self.window = window
        self.name = name
        self.on_pre_view_closed_handle = core.on_pre_view_closed.add(
            self.view_closed)
        self.view.set_name(name)
        self.write('')