mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
updated code browser to use new code highlight
This commit is contained in:
@@ -9,12 +9,13 @@ Run with:
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from rich.syntax import Syntax
|
||||
from rich.traceback import Traceback
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Container, VerticalScroll
|
||||
from textual.highlight import highlight
|
||||
from textual.reactive import reactive, var
|
||||
from textual.widgets import DirectoryTree, Footer, Header, Static
|
||||
|
||||
@@ -68,13 +69,8 @@ class CodeBrowser(App):
|
||||
code_view.update("")
|
||||
return
|
||||
try:
|
||||
syntax = Syntax.from_path(
|
||||
path,
|
||||
line_numbers=True,
|
||||
word_wrap=False,
|
||||
indent_guides=True,
|
||||
theme="github-dark" if self.current_theme.dark else "github-light",
|
||||
)
|
||||
code = Path(path).read_text(encoding="utf-8")
|
||||
syntax = highlight(code, path=path)
|
||||
except Exception:
|
||||
code_view.update(Traceback(theme="github-dark", width=None))
|
||||
self.sub_title = "ERROR"
|
||||
|
||||
@@ -26,4 +26,6 @@ CodeBrowser.-show-tree #tree-view {
|
||||
}
|
||||
#code {
|
||||
width: auto;
|
||||
padding: 0 1;
|
||||
background: $surface;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user