feat: switch default font to support nerd fonts

This commit is contained in:
Daylin Morgan 2022-06-15 01:40:03 -05:00
parent bbef8038f8
commit abdbc1da2e
4 changed files with 55 additions and 3 deletions

View file

@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.

View file

@ -111,7 +111,7 @@ See [here](https://github.com/daylinmorgan/yartsu/blob/main/docs/themes.md) a pr
## TODO
- [ ] add unit tests
- [ ] add support for nerd-fonts
- [x] add support for nerd-fonts
- [ ] add optional shadow
- [ ] add more themes

46
yartsu/_export_format.py Normal file
View file

@ -0,0 +1,46 @@
CONSOLE_SVG_FORMAT = """\
<svg class="rich-terminal" viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io -->
<style>
@font-face {{
font-family: "Fira Code";
src: local("FiraCode-Regular"),
url("https://cdn.jsdelivr.net/gh/ryanoasis/nerd-fonts@2.1.0/patched-fonts/FiraCode/Regular/complete/Fira%20Code%20Regular%20Nerd%20Font%20Complete.ttf") format("truetype");
font-style: normal;
font-weight: 400;
}}
@font-face {{
font-family: "Fira Code";
src: local("FiraCode-Bold"),
url("https://cdn.jsdelivr.net/gh/ryanoasis/nerd-fonts@2.1.0/patched-fonts/FiraCode/Regular/complete/Fira%20Code%20Bold%20Nerd%20Font%20Complete.ttf") format("truetype");
font-style: bold;
font-weight: 700;
}}
.{unique_id}-matrix {{
font-family: Fira Code, monospace;
font-size: {char_height}px;
line-height: {line_height}px;
font-variant-east-asian: full-width;
}}
.{unique_id}-title {{
font-size: 18px;
font-weight: bold;
font-family: arial;
}}
{styles}
</style>
<defs>
<clipPath id="{unique_id}-clip-terminal">
<rect x="0" y="0" width="{terminal_width}" height="{terminal_height}" />
</clipPath>
{lines}
</defs>
{chrome}
<g transform="translate({terminal_x}, {terminal_y})" clip-path="url(#{unique_id}-clip-terminal)">
{backgrounds}
<g class="{unique_id}-matrix">
{matrix}
</g>
</g>
</svg>
"""

View file

@ -7,6 +7,7 @@ from pathlib import Path
from rich.console import Console
from rich.text import Text
from ._export_format import CONSOLE_SVG_FORMAT
from ._run_cmd import run_cmd
from ._version import __version__
from .argparse import ArgumentParser
@ -117,6 +118,11 @@ def main() -> None:
console.print(parsed_input)
console.save_svg(args.output, title=title, theme=THEMES[args.theme])
console.save_svg(
args.output,
title=title,
theme=THEMES[args.theme],
code_format=CONSOLE_SVG_FORMAT,
)
term.print(f"\nSaved to {args.output}.")