Skip to content

Commit

Permalink
Merge branch 'theme-improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jul 27, 2024
2 parents 4c0ef31 + bece4ff commit c12bed5
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/posting/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/posting/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/posting/highlighters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
6 changes: 2 additions & 4 deletions src/posting/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import yaml
from posting.config import SETTINGS

from posting.locations import theme_directory


class Theme(BaseModel):
name: str = Field(exclude=True)
Expand Down Expand Up @@ -114,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",
Expand All @@ -128,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",
Expand Down
1 change: 0 additions & 1 deletion src/posting/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
from pathlib import Path
from dotenv import dotenv_values
from textual_autocomplete import TargetState


_VARIABLES_PATTERN = re.compile(
Expand Down
1 change: 0 additions & 1 deletion src/posting/widgets/key_value.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/posting/widgets/request/query_editor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/posting/widgets/request/request_auth.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/posting/widgets/response/response_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/posting/widgets/text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -209,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)
Expand All @@ -220,7 +222,7 @@ def on_mount(self) -> None:

def on_theme_change(self, theme: Theme) -> None:
self.theme = theme.syntax
self.refresh()
self.call_after_refresh(self.refresh)

@on(TextArea.Changed)
def on_change(self, event: TextArea.Changed) -> None:
Expand Down Expand Up @@ -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 {}),
Expand All @@ -569,7 +571,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 {}),
Expand All @@ -578,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 {}),
Expand Down

0 comments on commit c12bed5

Please sign in to comment.