How to use the pypsrp.complex_objects.Size function in pypsrp

To help you get started, we’ve selected a few pypsrp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_create_host_info(self):
        serializer = Serializer()

        foreground_color = Color(value=Color.CYAN)
        background_color = Color(value=Color.RED)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        cursor_size = 10
        buffer_size = Size(height=10, width=20)
        window_size = Size(height=30, width=40)
        max_window_size = Size(height=50, width=60)
        max_physical_window_size = Size(height=70, width=80)
        window_title = "Random Window Title"

        ps_raw_ui = PSHostRawUserInterface(
            window_title, cursor_size, foreground_color, background_color,
            cursor_position, window_position, buffer_size,
            max_physical_window_size, max_window_size, window_size
        )
        ps_ui = PSHostUserInterface(raw_ui=ps_raw_ui)
        ps_host = PSHost(None, None, False, None, None, ps_ui, None)

        host_info = HostInfo(host=ps_host)
        expected_xml = normalise_xml(self.HOST_XML)

        actual = serializer.serialize(host_info)
github jborean93 / pypsrp / tests / test_host.py View on Github external
set_window_size = MagicMock(return_value=None)
        set_window_title = MagicMock(return_value=None)
        read_key = MagicMock(return_value=key_info)
        flush_input = MagicMock(return_value=None)
        set_buffer1 = MagicMock(return_value=None)
        set_buffer2 = MagicMock(return_value=None)
        scroll_buffer = MagicMock(return_value=None)

        window_title = "pypsrp window"
        cursor_size = 50
        foreground_color = Color(value=Color.WHITE)
        background_color = Color(value=Color.BLUE)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        buffer_size = Size(width=80, height=80)
        max_physical_window_size = Size(width=80, height=80)
        max_window_size = Size(width=80, height=80)
        window_size = Size(width=80, height=80)

        host_raw_ui = PSHostRawUserInterface(window_title, cursor_size,
                                             foreground_color,
                                             background_color, cursor_position,
                                             window_position, buffer_size,
                                             max_physical_window_size,
                                             max_window_size, window_size)
        host_raw_ui.SetForegroundColor = set_foreground_color
        host_raw_ui.SetBackgroundColor = set_background_color
        host_raw_ui.SetCursorPosition = set_cursor_position
        host_raw_ui.SetWindowPosition = set_window_position
        host_raw_ui.SetCursorSize = set_cursor_size
        host_raw_ui.SetBufferSize = set_buffer_size
        host_raw_ui.SetWindowSize = set_window_size
github jborean93 / pypsrp / tests / test_host.py View on Github external
set_buffer_size = MagicMock(return_value=None)
        set_window_size = MagicMock(return_value=None)
        set_window_title = MagicMock(return_value=None)
        read_key = MagicMock(return_value=key_info)
        flush_input = MagicMock(return_value=None)
        set_buffer1 = MagicMock(return_value=None)
        set_buffer2 = MagicMock(return_value=None)
        scroll_buffer = MagicMock(return_value=None)

        window_title = "pypsrp window"
        cursor_size = 50
        foreground_color = Color(value=Color.WHITE)
        background_color = Color(value=Color.BLUE)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        buffer_size = Size(width=80, height=80)
        max_physical_window_size = Size(width=80, height=80)
        max_window_size = Size(width=80, height=80)
        window_size = Size(width=80, height=80)

        host_raw_ui = PSHostRawUserInterface(window_title, cursor_size,
                                             foreground_color,
                                             background_color, cursor_position,
                                             window_position, buffer_size,
                                             max_physical_window_size,
                                             max_window_size, window_size)
        host_raw_ui.SetForegroundColor = set_foreground_color
        host_raw_ui.SetBackgroundColor = set_background_color
        host_raw_ui.SetCursorPosition = set_cursor_position
        host_raw_ui.SetWindowPosition = set_window_position
        host_raw_ui.SetCursorSize = set_cursor_size
        host_raw_ui.SetBufferSize = set_buffer_size
github jborean93 / pypsrp / tests / test_host.py View on Github external
def test_ps_host_raw_ui_method(self):
        window_title = "pypsrp window"
        cursor_size = 50
        foreground_color = Color(value=Color.WHITE)
        background_color = Color(value=Color.BLUE)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        buffer_size = Size(width=80, height=80)
        max_physical_window_size = Size(width=80, height=80)
        max_window_size = Size(width=80, height=80)
        window_size = Size(width=80, height=80)

        raw_ui = PSHostRawUserInterface(
            window_title, cursor_size, foreground_color, background_color,
            cursor_position, window_position, buffer_size,
            max_physical_window_size, max_window_size, window_size
        )

        actual_foreground_color = raw_ui.GetForegroundColor(None, None)
        assert actual_foreground_color == foreground_color
        raw_ui.SetForegroundColor(None, None, Color.MAGENTA)
        assert isinstance(raw_ui.foreground_color, Color)
        assert raw_ui.foreground_color.value == Color.MAGENTA

        actual_background_color = raw_ui.GetBackgroundColor(None, None)
github jborean93 / pypsrp / tests / test_host.py View on Github external
read_key = MagicMock(return_value=key_info)
        flush_input = MagicMock(return_value=None)
        set_buffer1 = MagicMock(return_value=None)
        set_buffer2 = MagicMock(return_value=None)
        scroll_buffer = MagicMock(return_value=None)

        window_title = "pypsrp window"
        cursor_size = 50
        foreground_color = Color(value=Color.WHITE)
        background_color = Color(value=Color.BLUE)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        buffer_size = Size(width=80, height=80)
        max_physical_window_size = Size(width=80, height=80)
        max_window_size = Size(width=80, height=80)
        window_size = Size(width=80, height=80)

        host_raw_ui = PSHostRawUserInterface(window_title, cursor_size,
                                             foreground_color,
                                             background_color, cursor_position,
                                             window_position, buffer_size,
                                             max_physical_window_size,
                                             max_window_size, window_size)
        host_raw_ui.SetForegroundColor = set_foreground_color
        host_raw_ui.SetBackgroundColor = set_background_color
        host_raw_ui.SetCursorPosition = set_cursor_position
        host_raw_ui.SetWindowPosition = set_window_position
        host_raw_ui.SetCursorSize = set_cursor_size
        host_raw_ui.SetBufferSize = set_buffer_size
        host_raw_ui.SetWindowSize = set_window_size
        host_raw_ui.SetWindowTitle = set_window_title
        host_raw_ui.ReadKey = read_key
github jborean93 / pypsrp / tests / test_host.py View on Github external
def test_ps_host_raw_ui_method(self):
        window_title = "pypsrp window"
        cursor_size = 50
        foreground_color = Color(value=Color.WHITE)
        background_color = Color(value=Color.BLUE)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        buffer_size = Size(width=80, height=80)
        max_physical_window_size = Size(width=80, height=80)
        max_window_size = Size(width=80, height=80)
        window_size = Size(width=80, height=80)

        raw_ui = PSHostRawUserInterface(
            window_title, cursor_size, foreground_color, background_color,
            cursor_position, window_position, buffer_size,
            max_physical_window_size, max_window_size, window_size
        )

        actual_foreground_color = raw_ui.GetForegroundColor(None, None)
        assert actual_foreground_color == foreground_color
        raw_ui.SetForegroundColor(None, None, Color.MAGENTA)
        assert isinstance(raw_ui.foreground_color, Color)
        assert raw_ui.foreground_color.value == Color.MAGENTA
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_create_host_info(self):
        serializer = Serializer()

        foreground_color = Color(value=Color.CYAN)
        background_color = Color(value=Color.RED)
        cursor_position = Coordinates(x=1, y=2)
        window_position = Coordinates(x=3, y=4)
        cursor_size = 10
        buffer_size = Size(height=10, width=20)
        window_size = Size(height=30, width=40)
        max_window_size = Size(height=50, width=60)
        max_physical_window_size = Size(height=70, width=80)
        window_title = "Random Window Title"

        ps_raw_ui = PSHostRawUserInterface(
            window_title, cursor_size, foreground_color, background_color,
            cursor_position, window_position, buffer_size,
            max_physical_window_size, max_window_size, window_size
        )
        ps_ui = PSHostUserInterface(raw_ui=ps_raw_ui)
        ps_host = PSHost(None, None, False, None, None, ps_ui, None)

        host_info = HostInfo(host=ps_host)
        expected_xml = normalise_xml(self.HOST_XML)

        actual = serializer.serialize(host_info)
        actual_xml = normalise_xml(ET.tostring(actual))
github jborean93 / pypsrp / pypsrp / host.py View on Github external
def SetWindowSize(self, runspace, pipeline, size):
        """
        MI: 40
        SHOULD set the view window size based on the size specified.

        :param runspace: The runspace the host call relates to
        :param pipeline: The pipeline (if any) that the call relates to
        :param size: A GenericComplexObject that contains the extended
            properties for the size
        """
        obj = Size(height=size.extended_properties['height'],
                   width=size.extended_properties['width'])
        self.window_size = obj
github jborean93 / pypsrp / pypsrp / serializer.py View on Github external
# not a primitive object, so try and decode the complex object
        if metadata.object is None:
            # TODO: Handle something like
            # System.Collections.Generic.List`1[[System.String, mscorlib,
            # Version=4.0.0.0, Culture=neutral,
            # PublicKeyToken=b77a5c561934e089]]
            structures = {
                "System.Array": ListMeta(),
                "System.Management.Automation.DebugRecord":
                    ObjectMeta("Obj", object=DebugRecord),
                "System.Management.Automation.ErrorRecord":
                    ObjectMeta("Obj", object=ErrorRecord),
                "System.Management.Automation.Host.Coordinates":
                    ObjectMeta("Obj", object=Coordinates),
                "System.Management.Automation.Host.Size":
                    ObjectMeta("Obj", object=Size),
                "System.Management.Automation.InformationalRecord":
                    ObjectMeta("Obj", object=InformationalRecord),
                "System.Management.Automation.InformationRecord":
                    ObjectMeta("Obj", object=InformationRecord),
                "System.Management.Automation.ProgressRecordType":
                    ObjectMeta("Obj", object=ProgressRecordType),
                "System.Management.Automation.PSPrimitiveDictionary":
                    DictionaryMeta(),
                "System.Management.Automation.Remoting.RemoteHostMethodId":
                    ObjectMeta("Obj", object=HostMethodIdentifier),
                "System.Management.Automation.Runspaces.ApartmentState":
                    ObjectMeta("Obj", object=ApartmentState),
                "System.Management.Automation.Runspaces.PipelineResultTypes":
                    ObjectMeta("Obj", object=PipelineResultTypes),
                "System.Management.Automation.Runspaces.PSThreadOptions":
                    ObjectMeta("Obj", object=PSThreadOptions),
github jborean93 / pypsrp / pypsrp / host.py View on Github external
def SetBufferSize(self, runspace, pipeline, size):
        """
        MI: 38
        SHOULD set the size of the screen buffer with the specified size in
        character cells.

        :param runspace: The runspace the host call relates to
        :param pipeline: The pipeline (if any) that the call relates to
        :param size: A GenericComplexObject that contains the extended
            properties for the size
        """
        obj = Size(height=size.extended_properties['height'],
                   width=size.extended_properties['width'])
        self.buffer_size = obj