2525import time
2626import yaml
2727
28+ try :
29+ from rich .console import Console
30+ from rich .markdown import Markdown
31+ RICH_AVAILABLE = True
32+ except ImportError :
33+ RICH_AVAILABLE = False
34+
2835# Get installation directory, typically /opt, but configurable elsewhere
2936install_dir = os .path .dirname (os .path .dirname (
3037 os .path .dirname (os .path .dirname (os .path .realpath (__file__ )))))
@@ -1943,6 +1950,7 @@ def display_docs(name):
19431950 """
19441951 Display the contents of a help file with the given name.
19451952 Prefers Markdown (.md) files over text (.txt) files.
1953+ Renders markdown with rich formatting if available, otherwise falls back to plain text.
19461954
19471955 Args:
19481956 name (str): The name of the help file to display.
@@ -1952,19 +1960,26 @@ def display_docs(name):
19521960
19531961 Notes:
19541962 - Prioritizes .md files over .txt files for enhanced formatting
1963+ - Uses rich library for markdown rendering when available
19551964 - Provides fallback to legacy .txt files if .md files don't exist
19561965 - Shows helpful update instructions if no help file is found
19571966 - Guides users to update their project sources for latest documentation
19581967 """
1959- import os
1960-
19611968 # Try .md file first, fallback to .txt
1962- md_file = f'/opt/meza/manual/meza-cmd/ { name } .md'
1963- txt_file = f'/opt/ meza/manual/meza-cmd/{ name } .txt '
1964-
1969+ # Use install_dir to work both in development and production
1970+ md_file = f'{ install_dir } / meza/manual/meza-cmd/{ name } .md '
1971+ txt_file = f' { install_dir } /meza/manual/meza-cmd/ { name } .txt'
19651972 if os .path .exists (md_file ):
19661973 with open (md_file , encoding = 'utf-8' ) as f :
1967- print (f .read ())
1974+ content = f .read ()
1975+ # Use rich markdown rendering if available
1976+ if RICH_AVAILABLE :
1977+ console = Console ()
1978+ markdown = Markdown (content )
1979+ console .print (markdown )
1980+ else :
1981+ # Fallback to plain text display
1982+ print (content )
19681983 elif os .path .exists (txt_file ):
19691984 with open (txt_file , encoding = 'utf-8' ) as f :
19701985 print (f .read ())
0 commit comments