Exemplo n.º 1
0
def test_move_to_row():
    print(repr(Control.move_to_row(10, 20).segment))
    assert Control.move_to_row(10, 20).segment == Segment(
        "\x1b[12G\x1b[20B",
        None,
        [(ControlType.CURSOR_MOVE_TO_ROW, 11), (ControlType.CURSOR_DOWN, 20)],
    )
Exemplo n.º 2
0
def test_control_move():
    assert Control.move(0, 0).segment == Segment("", None, [])
    control = Control.move(3, 4)
    print(repr(control.segment))
    assert control.segment == Segment(
        "\x1b[3C\x1b[4B",
        None,
        [(ControlType.CURSOR_FORWARD, 3), (ControlType.CURSOR_DOWN, 4)],
    )
Exemplo n.º 3
0
 def refresh(self, repaint: bool = True, layout: bool = False) -> None:
     sync_available = os.environ.get("TERM_PROGRAM", "") != "Apple_Terminal"
     if not self._closed:
         console = self.console
         try:
             if sync_available:
                 console.file.write("\x1bP=1s\x1b\\")
             console.print(Screen(Control.home(), self.view, Control.home()))
             if sync_available:
                 console.file.write("\x1bP=2s\x1b\\")
             console.file.flush()
         except Exception:
             self.panic()
Exemplo n.º 4
0
def test_move_to_column():
    print(repr(Control.move_to_column(10, 20).segment))
    assert Control.move_to_column(10, 20).segment == Segment(
        "\x1b[11G\x1b[20B",
        None,
        [(ControlType.CURSOR_MOVE_TO_COLUMN, 10), (ControlType.CURSOR_DOWN, 20)],
    )

    assert Control.move_to_column(10, -20).segment == Segment(
        "\x1b[11G\x1b[20A",
        None,
        [(ControlType.CURSOR_MOVE_TO_COLUMN, 10), (ControlType.CURSOR_UP, 20)],
    )
Exemplo n.º 5
0
def test_title():
    control_segment = Control.title("hello").segment
    assert control_segment == Segment(
        "\x1b]0;hello\x07",
        None,
        [(ControlType.SET_WINDOW_TITLE, "hello")],
    )
Exemplo n.º 6
0
 def __rich_console__(self, console: Console,
                      options: ConsoleOptions) -> RenderResult:
     yield Control.home().segment
     x = self.region.x
     new_line = Segment.line()
     move_to = Control.move_to
     for last, (y, line) in loop_last(enumerate(self.lines, self.region.y)):
         yield move_to(x, y).segment
         yield from line
         if not last:
             yield new_line
Exemplo n.º 7
0
def test_control():
    console = Console(file=io.StringIO(), force_terminal=True, _environ={})
    console.control(Control.clear())
    console.print("BAR")
    assert console.file.getvalue() == "\x1b[2JBAR\n"
Exemplo n.º 8
0
def test_control():
    control = Control(ControlType.BELL)
    assert str(control) == "\x07"
Exemplo n.º 9
0
def test_control_move_to():
    control = Control.move_to(5, 10)
    print(control.segment)
    assert control.segment == Segment("\x1b[11;6H", None,
                                      [(ControlType.CURSOR_MOVE_TO, 5, 10)])