David-Rushton / morello.markdown

A .NET library that pretty prints markdown in the console
MIT License
2 stars 0 forks source link

Fails to render properly if font does not support Nerd Fonts #1

Closed David-Rushton closed 2 years ago

David-Rushton commented 2 years ago

Issue

Markdown.Console requires Nerd Fonts.

If your font has not been patched fallback characters are used, These are less than ideal and lead to a messy output. The aim of this project is to deliver beautiful rendering of markdown in the console. Messy fallbacks undermine this.

Here are few ways we could address this. I've not given this a lot of thought. So there may well be other/better ways of addressing.

Ideas

1) Only use Nerd Fonts if available Detecting font support in the terminal may be impossible. Using a whitelist of font names is also problematic.

2) Make Nerd Fonts configurable This is probably the easiest option. But in many case you may not know at design time what will be available at runtime.

Example

Win 11 Cascadia Code without Nerd Fonts

image

Win 11 Cascadia Code with Nerd Fonts

image

David-Rushton commented 2 years ago

There are various ways you can determine which font the console is using. However these differ between Windows and Linux (and not all distros follow the same pattern).

I would prefer to use Ansi escape codes if possible. Two reasons:

Currently Ansi escape doesn't support querying font capabilities.

David-Rushton commented 2 years ago

I think the best thing to do is:

  1. Make Nerd Font support configurable, with a sensible default
  2. Investigate options
  3. If investigation is successful; use outcome to set NF default value at start-up
David-Rushton commented 2 years ago

Suggestion:

enum NerdFontsSupported
{
  Yes,
  No,
  // Maybe a separate PR added later
  Detect
}

class MarkdownConsole
{
  // New property
  public NerdFontsSupported { get; set; } = NerdFontsSupported.Detect;
}