File: test_input_terminal_cursor.py

package info (click to toggle)
textual 2.1.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,080 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (30 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from textual.app import App, ComposeResult
from textual.geometry import Offset
from textual.widgets import Input


class InputApp(App):
    # Apply padding to ensure gutter accounted for.
    CSS = "Input { padding: 4 8 }"

    def compose(self) -> ComposeResult:
        # We don't want to select the text on focus, as selected text
        # has different interactions with the cursor_left action.
        yield Input("こんにちは!", select_on_focus=False)


async def test_initial_terminal_cursor_position():
    app = InputApp()
    async with app.run_test():
        # The input is focused so the terminal cursor position should update.
        assert app.cursor_position == Offset(21, 5)


async def test_terminal_cursor_position_update_on_cursor_move():
    app = InputApp()
    async with app.run_test():
        input_widget = app.query_one(Input)
        input_widget.action_cursor_left()
        input_widget.action_cursor_left()
        # We went left over two double-width characters
        assert app.cursor_position == Offset(17, 5)