    def test_inline_colours(self):
        """
        Check inline colours work as expected.
        """
        # Create a dummy screen.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=True)
        scene = Scene([], -1)
        canvas = Canvas(screen, 10, 40, 0, 0)

        # Create the form we want to test.
        form = Frame(canvas, canvas.height, canvas.width, has_border=False, can_scroll=False)
        scene.add_effect(form)
        layout = Layout([100], fill_frame=True)
        form.add_layout(layout)
        text_box = TextBox(3, as_string=False, parser=AsciimaticsParser())
        layout.add_widget(text_box)
        listbox = ListBox(2, [("P", 1), ("${9,2}Q", 2), ("R", 3), ("S", 4)], parser=AsciimaticsParser())
        layout.add_widget(listbox)
        mc_list = MultiColumnListBox(
            Widget.FILL_FRAME,
            [3, "100%"],
            [(["1", "\x1B[32m2"], 1)],
            titles=["A", "\x1B[31mB"],
            parser=AnsiTerminalParser())
        layout.add_widget(mc_list)
        form.fix()
        form.reset()

        # Check that the Asciimatics colour parsing worked.
        text_box.value = ["A${1}B"]
        form.update(0)
        self.assertEqual(canvas.get_from(0, 0), (ord("A"), 7, 1, 6))
        self.assertEqual(canvas.get_from(1, 0), (ord("B"), 1, 0, 6))
        self.assertEqual(canvas.get_from(0, 3), (ord("P"), 3, 2, 4))
        self.assertEqual(canvas.get_from(0, 4), (ord("Q"), 9, 2, 4))

        # Check that using ColouredText preserves colour data
        text_box.value = [ColouredText("B${2}A", AsciimaticsParser())]
        form.update(0)
        self.assertEqual(canvas.get_from(0, 0), (ord("B"), 7, 1, 6))
        self.assertEqual(canvas.get_from(1, 0), (ord("A"), 2, 0, 6))

        # Check that keys work on parsed text.
        self.process_keys(form, [Screen.KEY_END, "\n1", Screen.KEY_UP, Screen.KEY_END, Screen.KEY_DELETE])
        form.update(0)
        self.assertEqual(canvas.get_from(0, 0), (ord("B"), 7, 1, 6))
        self.assertEqual(canvas.get_from(1, 0), (ord("A"), 2, 0, 6))
        self.assertEqual(canvas.get_from(2, 0), (ord("1"), 7, 3, 6))

        # Check that the Ansi terminal colour parsing worked.
        self.assertEqual(canvas.get_from(0, 5), (ord("A"), 7, 1, 4))
        self.assertEqual(canvas.get_from(3, 5), (ord("B"), 1, 1, 4))
        self.assertEqual(canvas.get_from(0, 6), (ord("1"), 3, 2, 4))
        self.assertEqual(canvas.get_from(3, 6), (ord("2"), 2, 2, 4))
Check inline colours work as expected.
tests/test_widgets.py