Skip to content

Commit 0d758db

Browse files
committed
added docs
1 parent 3c3a8ae commit 0d758db

File tree

9 files changed

+199
-5
lines changed

9 files changed

+199
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.vscode
33
mypy_report
4+
docs/build
45

56
# Byte-compiled / optimized / DLL files
67
__pycache__/

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/source/conf.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
21+
import pkg_resources
22+
23+
import sphinx_rtd_theme
24+
25+
html_theme = "sphinx_rtd_theme"
26+
27+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
28+
29+
project = "Rich"
30+
copyright = "2019, Will McGugan"
31+
author = "Will McGugan"
32+
33+
# The full version, including alpha/beta/rc tags
34+
release = pkg_resources.get_distribution("rich").version
35+
36+
37+
# -- General configuration ---------------------------------------------------
38+
39+
# Add any Sphinx extension module names here, as strings. They can be
40+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
41+
# ones.
42+
extensions = [
43+
"sphinx.ext.autodoc",
44+
"sphinx.ext.viewcode",
45+
"sphinx.ext.napoleon",
46+
]
47+
48+
# Add any paths that contain templates here, relative to this directory.
49+
templates_path = ["_templates"]
50+
51+
# List of patterns, relative to source directory, that match files and
52+
# directories to ignore when looking for source files.
53+
# This pattern also affects html_static_path and html_extra_path.
54+
exclude_patterns = []
55+
56+
57+
# -- Options for HTML output -------------------------------------------------
58+
59+
# The theme to use for HTML and HTML Help pages. See the documentation for
60+
# a list of builtin themes.
61+
#
62+
# html_theme = "alabaster"
63+
64+
# Add any paths that contain custom static files (such as style sheets) here,
65+
# relative to this directory. They are copied after the builtin static files,
66+
# so a file named "default.css" will overwrite the builtin "default.css".
67+
html_static_path = ["_static"]
68+

docs/source/index.rst

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. Rich documentation master file, created by
2+
sphinx-quickstart on Thu Dec 26 17:03:20 2019.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to Rich's documentation!
7+
================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
reference.rst
14+
15+
Indices and tables
16+
==================
17+
18+
* :ref:`genindex`
19+
* :ref:`modindex`
20+
* :ref:`search`

docs/source/reference.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Reference
2+
=========
3+
4+
.. toctree::
5+
:maxdepth: 3
6+
7+
reference/console.rst
8+

docs/source/reference/console.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rich.console
2+
============
3+
4+
.. automodule:: rich.console
5+
:members: Console

make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

rich/console.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __init__(
159159
color_system: Optional[
160160
Literal["auto", "standard", "256", "truecolor"]
161161
] = "auto",
162-
styles: Dict[str, Style] = DEFAULT_STYLES,
162+
styles: Dict[str, Style] = None,
163163
file: IO = None,
164164
width: int = None,
165165
height: int = None,
@@ -170,7 +170,7 @@ def __init__(
170170
log_time_format: str = "[%X] ",
171171
):
172172

173-
self._styles = ChainMap(styles)
173+
self._styles = ChainMap(DEFAULT_STYLES if styles is None else styles)
174174
self.file = file or sys.stdout
175175
self._width = width
176176
self._height = height
@@ -249,7 +249,7 @@ def is_terminal(self) -> bool:
249249
250250
Returns:
251251
bool: True if the console writting to a device capable of
252-
understanding terminal codes, otherwise False.
252+
understanding terminal codes, otherwise False.
253253
"""
254254
isatty = getattr(self.file, "isatty", None)
255255
return False if isatty is None else isatty()
@@ -722,7 +722,7 @@ def export_html(
722722
self,
723723
theme: Theme = None,
724724
clear: bool = True,
725-
code_format=CONSOLE_HTML_FORMAT,
725+
code_format: str = None,
726726
inline_styles: bool = False,
727727
) -> str:
728728
"""Generate HTML from console contents (requires record=True argument in constructor).
@@ -747,6 +747,8 @@ def export_html(
747747
_theme = theme or themes.DEFAULT
748748
stylesheet = ""
749749

750+
render_code_format = CONSOLE_HTML_FORMAT if code_format is None else code_format
751+
750752
if inline_styles:
751753
for text, style in Segment.simplify(self._record_buffer):
752754
if style:
@@ -773,7 +775,7 @@ def export_html(
773775
stylesheet_append(f".r{style_number} {{{style_rule}}}")
774776
stylesheet = "\n".join(stylesheet_rules)
775777

776-
rendered_code = code_format.format(
778+
rendered_code = render_code_format.format(
777779
code="".join(fragments),
778780
stylesheet=stylesheet,
779781
foreground=_theme.foreground_color.hex,

0 commit comments

Comments
 (0)