From 8529807ef97e03e1e2b85cde853059a37235f0c8 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Sat, 27 Jul 2024 09:45:59 +0100 Subject: [PATCH 1/3] Upgrade and pin Textual to 0.74.0 --- pyproject.toml | 2 +- requirements-dev.lock | 2 +- requirements.lock | 2 +- src/posting/widgets/response/response_area.py | 4 ++++ src/posting/widgets/text_area.py | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 579eb2bb..434c3d6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "pydantic-settings==2.3.4", "python-dotenv==1.0.1", "textual-autocomplete>=3.0.0a9", - "textual[syntax]==0.73.0", + "textual[syntax]==0.74.0", ] readme = "README.md" requires-python = ">= 3.11" diff --git a/requirements-dev.lock b/requirements-dev.lock index f2914dac..fa06f440 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -104,7 +104,7 @@ sniffio==1.3.1 # via httpx syrupy==4.6.1 # via pytest-textual-snapshot -textual==0.73.0 +textual==0.74.0 # via posting # via pytest-textual-snapshot # via textual-autocomplete diff --git a/requirements.lock b/requirements.lock index 0ed8870f..8f3ace48 100644 --- a/requirements.lock +++ b/requirements.lock @@ -63,7 +63,7 @@ rich==13.7.1 sniffio==1.3.1 # via anyio # via httpx -textual==0.73.0 +textual==0.74.0 # via posting # via textual-autocomplete textual-autocomplete==3.0.0a9 diff --git a/src/posting/widgets/response/response_area.py b/src/posting/widgets/response/response_area.py index 0df05b09..28ba6c86 100644 --- a/src/posting/widgets/response/response_area.py +++ b/src/posting/widgets/response/response_area.py @@ -61,6 +61,7 @@ class ResponseArea(Vertical): def on_mount(self) -> None: self.border_title = "Response" self.add_class("section") + self.app.theme_change_signal.subscribe(self, self.on_theme_change) def compose(self) -> ComposeResult: with ResponseTabbedContent(disabled=self.response is None): @@ -77,6 +78,9 @@ def compose(self) -> ComposeResult: with TabPane("Trace", id="response-trace-pane"): yield ResponseTrace() + def on_theme_change(self, _) -> None: + self.refresh() + def watch_response(self, response: httpx.Response | None) -> None: if response is None: return diff --git a/src/posting/widgets/text_area.py b/src/posting/widgets/text_area.py index bbd66ed8..689ae7d3 100644 --- a/src/posting/widgets/text_area.py +++ b/src/posting/widgets/text_area.py @@ -221,6 +221,7 @@ def on_mount(self) -> None: def on_theme_change(self, theme: Theme) -> None: self.theme = theme.syntax self.refresh() + print("self.theme", self.theme) @on(TextArea.Changed) def on_change(self, event: TextArea.Changed) -> None: @@ -569,7 +570,6 @@ def text(self) -> str: GITHUB_LIGHT = TextAreaTheme.get_builtin_theme("github_light") GITHUB_LIGHT_THEME = TextAreaTheme( name="github_light", - base_style=None, syntax_styles={ # "json.error": Style.parse("u #dc2626"), **(GITHUB_LIGHT.syntax_styles if GITHUB_LIGHT else {}), From fd183afc3558a30af33953f6e257b23bdf7a0728 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Sat, 27 Jul 2024 09:55:34 +0100 Subject: [PATCH 2/3] Import cleaning --- src/posting/app.py | 5 +---- src/posting/collection.py | 2 +- src/posting/highlighters.py | 2 -- src/posting/themes.py | 1 - src/posting/variables.py | 1 - src/posting/widgets/key_value.py | 1 - src/posting/widgets/request/query_editor.py | 1 - src/posting/widgets/request/request_auth.py | 1 - src/posting/widgets/text_area.py | 1 - 9 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/posting/app.py b/src/posting/app.py index 4d546a42..568a140a 100644 --- a/src/posting/app.py +++ b/src/posting/app.py @@ -1,14 +1,11 @@ from pathlib import Path -from typing import Any, Literal, Union, cast -import subprocess -import itertools +from typing import Any, Literal, cast import httpx from rich.console import Group from rich.text import Text from textual import on, log, work from textual.command import CommandPalette from textual.css.query import NoMatches -from textual.design import ColorSystem from textual.events import Click from textual.reactive import Reactive, reactive from textual.app import App, ComposeResult diff --git a/src/posting/collection.py b/src/posting/collection.py index 8dd7fe49..7ab336ef 100644 --- a/src/posting/collection.py +++ b/src/posting/collection.py @@ -3,7 +3,7 @@ from string import Template from typing import Any, Literal, get_args import httpx -from pydantic import BaseModel, Field, HttpUrl, SecretStr +from pydantic import BaseModel, Field, HttpUrl import rich import yaml import os diff --git a/src/posting/highlighters.py b/src/posting/highlighters.py index 53aed33f..fcabc229 100644 --- a/src/posting/highlighters.py +++ b/src/posting/highlighters.py @@ -2,13 +2,11 @@ from rich.highlighter import Highlighter from rich.text import Text from textual.widgets import Input -from textual.geometry import clamp from posting.variables import ( find_variable_end, find_variable_start, find_variables, - get_variable_at_cursor, get_variables, is_cursor_within_variable, ) diff --git a/src/posting/themes.py b/src/posting/themes.py index f2fac958..a11c0383 100644 --- a/src/posting/themes.py +++ b/src/posting/themes.py @@ -3,7 +3,6 @@ import yaml from posting.config import SETTINGS -from posting.locations import theme_directory class Theme(BaseModel): diff --git a/src/posting/variables.py b/src/posting/variables.py index 84619025..35d67710 100644 --- a/src/posting/variables.py +++ b/src/posting/variables.py @@ -6,7 +6,6 @@ import os from pathlib import Path from dotenv import dotenv_values -from textual_autocomplete import TargetState _VARIABLES_PATTERN = re.compile( diff --git a/src/posting/widgets/key_value.py b/src/posting/widgets/key_value.py index b89c2593..1469ea6c 100644 --- a/src/posting/widgets/key_value.py +++ b/src/posting/widgets/key_value.py @@ -1,7 +1,6 @@ from dataclasses import dataclass from textual import on from textual.app import ComposeResult -from textual.binding import Binding from textual.containers import Horizontal, Vertical from textual.message import Message from textual.widget import Widget diff --git a/src/posting/widgets/request/query_editor.py b/src/posting/widgets/request/query_editor.py index bd337026..3e79a01b 100644 --- a/src/posting/widgets/request/query_editor.py +++ b/src/posting/widgets/request/query_editor.py @@ -1,7 +1,6 @@ from textual.app import ComposeResult from textual.binding import Binding from textual.containers import Vertical -from textual.widgets.data_table import CellDoesNotExist from posting.collection import QueryParam from posting.widgets.datatable import PostingDataTable diff --git a/src/posting/widgets/request/request_auth.py b/src/posting/widgets/request/request_auth.py index 384331fe..b7beae57 100644 --- a/src/posting/widgets/request/request_auth.py +++ b/src/posting/widgets/request/request_auth.py @@ -1,6 +1,5 @@ from typing import Protocol, runtime_checkable import httpx -from pydantic import SecretStr from textual import on, log from textual.app import ComposeResult from textual.binding import Binding diff --git a/src/posting/widgets/text_area.py b/src/posting/widgets/text_area.py index 689ae7d3..c82620c5 100644 --- a/src/posting/widgets/text_area.py +++ b/src/posting/widgets/text_area.py @@ -8,7 +8,6 @@ from textual.app import ComposeResult from textual.binding import Binding from textual.containers import Horizontal, Vertical -from textual.design import ColorSystem from textual.message import Message from textual.reactive import reactive, Reactive from textual.widgets import TextArea, Label, Select, Checkbox From bece4fffea6933bb3876675830fb76409851df4f Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Sat, 27 Jul 2024 10:21:36 +0100 Subject: [PATCH 3/3] Fixing text area themes updating via command palette --- src/posting/themes.py | 5 ++--- src/posting/widgets/text_area.py | 10 ++++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/posting/themes.py b/src/posting/themes.py index a11c0383..ed8e012e 100644 --- a/src/posting/themes.py +++ b/src/posting/themes.py @@ -4,7 +4,6 @@ from posting.config import SETTINGS - class Theme(BaseModel): name: str = Field(exclude=True) primary: str @@ -113,7 +112,7 @@ def load_user_themes() -> dict[str, Theme]: background="#0F0F1F", # Very Dark Blue, almost black surface="#1E1E3F", # Dark Blue-Purple panel="#2D2B55", # Slightly Lighter Blue-Purple - syntax="posting-dracula", + syntax="dracula", ), "nebula": Theme( name="nebula", @@ -127,7 +126,7 @@ def load_user_themes() -> dict[str, Theme]: background="#0A0A23", # Dark Navy, closer to a night sky surface="#1C1C3C", # Dark Blue-Purple panel="#2E2E5E", # Slightly Lighter Blue-Purple - syntax="posting-dracula", + syntax="dracula", ), "alpine": Theme( name="alpine", diff --git a/src/posting/widgets/text_area.py b/src/posting/widgets/text_area.py index c82620c5..e2ca4360 100644 --- a/src/posting/widgets/text_area.py +++ b/src/posting/widgets/text_area.py @@ -208,6 +208,9 @@ class PostingTextArea(TextArea): def on_mount(self) -> None: self.indent_width = 2 self.cursor_blink = SETTINGS.get().text_input.blinking_cursor + + # Replace the default themes with CSS-aware versions. These themes will + # use their parent containers background color etc. self.register_theme(POSTING_THEME) self.register_theme(MONOKAI_THEME) self.register_theme(GITHUB_LIGHT_THEME) @@ -219,8 +222,7 @@ def on_mount(self) -> None: def on_theme_change(self, theme: Theme) -> None: self.theme = theme.syntax - self.refresh() - print("self.theme", self.theme) + self.call_after_refresh(self.refresh) @on(TextArea.Changed) def on_change(self, event: TextArea.Changed) -> None: @@ -559,7 +561,7 @@ def text(self) -> str: ) MONOKAI = TextAreaTheme.get_builtin_theme("monokai") MONOKAI_THEME = TextAreaTheme( - name="posting-monokai", + name="monokai", syntax_styles={ # "json.error": Style.parse("u #dc2626"), **(MONOKAI.syntax_styles if MONOKAI else {}), @@ -577,7 +579,7 @@ def text(self) -> str: DRACULA = TextAreaTheme.get_builtin_theme("dracula") DRACULA_THEME = TextAreaTheme( - name="posting-dracula", + name="dracula", syntax_styles={ # "json.error": Style.parse("u #dc2626"), **(DRACULA.syntax_styles if DRACULA else {}),