Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the typer output with html format to provide it to termynal #538

Open
7 tasks done
GreNait opened this issue Jan 24, 2023 · 4 comments
Open
7 tasks done

Get the typer output with html format to provide it to termynal #538

GreNait opened this issue Jan 24, 2023 · 4 comments
Labels
question Question or problem

Comments

@GreNait
Copy link

GreNait commented Jan 24, 2023

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

script -q -c "python data_stream_measurement/main.py --help" test.out
cat test.out | ./ansi2html.sh test.html

Description

Within the typer documentation, termynal is used to interactively show the typer features etc. They are also all styled like the typical terminal output. It would be awesome, if I could replicate this for my typer app documentation.

I tried to capture the terminal styling with several approaches:

  • Capture output as html -> didn't work
  • Use script to capture the terminal and afterwards use ansi2html -> still no coloring

Is there a way, to get the typer output saved into a file, with the html styling? So I could copy that to my markdown?

Operating System

Linux

Operating System Details

Ubuntu 20.04

Typer Version

0.7.0

Python Version

3.8.10

Additional Context

No response

@GreNait GreNait added the question Question or problem label Jan 24, 2023
@heiskane
Copy link

This should work

script -q -c "python /tmp/asd.py --help" | ansi2html > asd.html

That being said i guess it would be nice to have something like --color-always option like with the ls-command:

ls -la --color=always | ansi2html > asd.html

@NikosAlexandris
Copy link

That being said i guess it would be nice to have something like --color-always option like with the ls-command:

Colors appear just fine here, after script -q -c "clitool --help" | ansi2html > clitoolhelp.html and viewing the latter file in a browser.

@bckohan
Copy link

bckohan commented Dec 29, 2023

Another approach is to use the rich export functions:

If you're using sphinx-doc with reStructuredText, I wrote a directive extension to do this for you. Unfortunately typer has no official way to access the console object, so a monkey patch is involved.

@NikosAlexandris
Copy link

If you're using sphinx-doc with reStructuredText, I wrote a directive extension to do this for you. Unfortunately typer has no official way to access the console object, so a monkey patch is involved.

Nice work! Pity, I am trying out Material MkDocs :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
Projects
None yet
Development

No branches or pull requests

4 participants