Skip to main content

Neovim colorschemes for Textual apps, including TextArea syntax highlighting

Project description

textual-nvim-themes

Use Neovim colorschemes in your Textual apps, including full syntax highlighting in TextArea widgets.

Themes are sourced from the Neovim community via Lumis.


Installation

pip install textual-nvim-themes
uv add textual-nvim-themes

Doesn't have syntax highlighting support for TextArea by default as you might not need it and only want this for App themes. See bellow how to add it.

Syntax highlighting support:

pip install "textual-nvim-themes[syntax]"
uv add textual-nvim-themes --extra syntax

You can also add support for it by using textual[syntax] or manually by using TextArea.register_language(name, language, highlight_query) with another source for tree-sitter like tree_sitter_language_pack:

from tree_sitter_language_pack import get_language, get_highlights_query
from textual.widgets import TextArea

LANGUAGES = ["kotlin", "yaml", "ini", "c"]

class MyTextArea(TextArea):
    def on_mount(self):
        for name in LANGUAGES:
            language = get_language(name)
            query = get_highlights_query(name)
            if language and query:
                self.register_language(name, language, query)

Demo

Run the bundled demo to browse all available themes live:

python -m demo

Use the arrow keys or your mouse to cycle through themes


Bundled themes

List all bundled theme names:

python -c "from textual_nvim_themes import available_themes; print('\n'.join(available_themes()))"

Or you can check themes


Quick start

Inherit from ThemedApp to get default theme switching and the command palette integration:

from textual.app import ComposeResult
from textual.widgets import TextArea
from textual_nvim_themes import ThemedApp

class MyApp(ThemedApp):
    THEMES = ["tokyonight_night", "nord", "dracula"] # restrict the themes inside the command palette
    DEFAULT_THEME = "tokyonight_night"

    def compose(self) -> ComposeResult:
        yield TextArea("print('hello')", language="python")
        
if __name__ == "__main__":
    MyApp().run()

Manual setup

If you don't want to inherit ThemedApp e.g. you already have a custom App base class, you can wire things up yourself:

from textual.app import App, ComposeResult
from textual.widgets import TextArea
from textual_nvim_themes import apply_theme, ThemePalette


class MyApp(App):
    def compose(self) -> ComposeResult:
        yield TextArea("print('hello')", language="python")

    def on_mount(self) -> None:
        apply_theme(self, "tokyonight_night")

    # Override so the command palette's "Change theme" command uses our themes
    def search_themes(self) -> None:
        themes = None # themes is the equivalent of ThemedApp.THEMES
        self.push_screen(ThemePalette(themes, "Search themes…"))

if __name__ == "__main__":
    MyApp().run()

Advanced use

You can directly access the textual themes if you want to modify or manually register them:

  • load_nvim_theme load a theme from its name, return a NvimTheme
  • make_app_theme convert a NvimTheme into a textual app Theme
  • make_textarea_theme convert a NvimTheme into a textual app TextAreaTheme

If you choose to register and change themes yourself without using apply_theme then you can use apply_textarea_theme in your app watch_theme method to sync your textarea to your app theme (it also register theme into the textarea just in case):

from textual.app import App, ComposeResult
from textual.widgets import TextArea
from textual_nvim_themes import load_nvim_theme, make_app_theme, make_textarea_theme, apply_textarea_theme, ThemePalette


class MyApp(App):
    def compose(self) -> ComposeResult:
        yield TextArea("print('hello')", language="python")

    def on_mount(self) -> None:
        theme = load_nvim_theme("dracula")
        self.register_theme(make_app_theme(theme))
        self.query_one(TextArea).register_theme(make_textarea_theme(theme))
        self.theme = "dracula"

    # Override so the command palette's "Change theme" command uses our themes
    def search_themes(self) -> None:
        themes = None  # themes is the equivalent of ThemedApp.THEMES
        self.push_screen(ThemePalette(themes, "Search themes…"))

    # Keep TextArea syntax highlighting in sync when the theme changes
    def watch_theme(self, theme: str) -> None:
        apply_textarea_theme(self, theme)


if __name__ == "__main__":
    MyApp().run()

API

See API


License

MIT. See LICENSE

Theme data belongs to the original Neovim colorscheme authors.


Acknowledgements

This project incorporates code adapted from Lumis (notably all the Neovim extraction part) by Leandro Pereira, licensed under the MIT License.

Many thanks for making the project open source.

Also, big thanks to the Neovim community for all the themes !


Contributions

Contributions are welcomed. See CONTRIBUTING

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textual_nvim_themes-0.1.0.tar.gz (133.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textual_nvim_themes-0.1.0-py3-none-any.whl (301.3 kB view details)

Uploaded Python 3

File details

Details for the file textual_nvim_themes-0.1.0.tar.gz.

File metadata

  • Download URL: textual_nvim_themes-0.1.0.tar.gz
  • Upload date:
  • Size: 133.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for textual_nvim_themes-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c088839b1d73a6085bbf0ef0559582dab13674bd8934ec3b28eeb69f2ee387bc
MD5 2597ff338223df2f9518db1c98a49650
BLAKE2b-256 196e6fc0121fd5fe669f1c70bfdf961f127709ad97f540142f8cb48bc8d8248c

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_nvim_themes-0.1.0.tar.gz:

Publisher: publish.yml on Fosox/textual-nvim-themes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file textual_nvim_themes-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for textual_nvim_themes-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50d1e061a4d0aa6d875b2c3484273dc60b1726c5d28baf837350b9b42be9c03e
MD5 51947b03cd86c30f2e72c88c396de2af
BLAKE2b-256 9e2fd8361bf6f344673126e5007682af2709c5262084baa12f5d81e90eca6c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for textual_nvim_themes-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Fosox/textual-nvim-themes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page