Skip to content

Commit

Permalink
Merge pull request #934 from Textualize/app-title-constructor
Browse files Browse the repository at this point in the history
Some bug fixes in `Input` + add `title` to `App` constructor
  • Loading branch information
willmcgugan authored Oct 17, 2022
2 parents 7c304ad + fc3d1be commit 73e698d
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 401 deletions.
8 changes: 2 additions & 6 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

LayoutDefinition = "dict[str, Any]"


DEFAULT_COLORS = {
"dark": ColorSystem(
primary="#004578",
Expand All @@ -82,7 +81,6 @@
),
}


ComposeResult = Iterable[Widget]
RenderResult = RenderableType

Expand Down Expand Up @@ -178,7 +176,6 @@ def __init__(
)
self.error_console = Console(markup=False, stderr=True)
self.driver_class = driver_class or self.get_driver_class()
self._title = title
self._screen_stack: list[Screen] = []
self._sync_available = False

Expand All @@ -192,9 +189,9 @@ def __init__(
self._animate = self._animator.bind(self)
self.mouse_position = Offset(0, 0)
if title is None:
self._title = f"{self.__class__.__name__}"
self.title = f"{self.__class__.__name__}"
else:
self._title = title
self.title = title

self._logger = Logger(self._log)

Expand Down Expand Up @@ -1024,7 +1021,6 @@ async def run_process_messages():

Reactive._initialize_object(self)

self.title = self._title
self.stylesheet.update(self)
self.refresh()

Expand Down
8 changes: 4 additions & 4 deletions src/textual/widgets/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Input(Widget, can_focus=True):
COMPONENT_CLASSES = {"input--cursor", "input--placeholder"}

cursor_blink = reactive(True)
value = reactive("", layout=True)
value = reactive("", layout=True, init=False)
input_scroll_offset = reactive(0)
cursor_position = reactive(0)
view_position = reactive(0)
Expand All @@ -104,7 +104,7 @@ class Input(Widget, can_focus=True):

def __init__(
self,
value: str = "",
value: str | None = None,
placeholder: str = "",
highlighter: Highlighter | None = None,
password: bool = False,
Expand All @@ -113,7 +113,8 @@ def __init__(
classes: str | None = None,
) -> None:
super().__init__(name=name, id=id, classes=classes)
self.value = value
if value is not None:
self.value = value
self.placeholder = placeholder
self.highlighter = highlighter
self.password = password
Expand Down Expand Up @@ -169,7 +170,6 @@ def cursor_width(self) -> int:
return self._position_to_cell(len(self.value)) + 1

def render(self) -> RenderableType:
self.view_position = self.view_position
if not self.value:
placeholder = Text(self.placeholder)
placeholder.stylize(self.get_component_rich_style("input--placeholder"))
Expand Down
Loading

0 comments on commit 73e698d

Please sign in to comment.