apy icon indicating copy to clipboard operation
apy copied to clipboard

stdout color formatting

Open AdrienLemaire opened this issue 3 years ago • 3 comments

It might be more flexible to rely on external formatting tools to handle coloring the output, and will allow users to customize their colors.

I usually use grc to colorize shell output. And tools like pygmentize are popular to colorize code.

Eg for this grc conf:

# Colorize apy list output
regexp=\w+
colours="\033[38;5;20m"
count=more
=====
regexp=^(\w+:)
colours=red
count=more
=====
regexp=(cid|ease|lapses|due|model): ([\w.%]+)
colours=yellow, blue
count=more
=====

It's a low priority, but it'd be nice if the output of apy list was more readable, especially when using markdown: false. I'm not sure what would be a good way to achieve that.

AdrienLemaire avatar Sep 18 '20 00:09 AdrienLemaire

Actually, @lervag could we only output the content of Basic/Front or Cloze/Text, instead of showing the whole template ?

Currently:

<div id="kard">
<div class="tags">{{Tags}}</div>
{{Front}}
</div>

<script type="text/x-mathjax-config"> MathJax.Hub.processSectionDelay = 0; MathJax.Hub.Config({ messageStyle:"none", showProcessingMessages:false, tex2jax:{ inlineMath: [ ['$','$'], ['\\(','\\)'] ], displayMath: [ ['$$','$$'], ['\\[','\\]'] ], processEscapes:true } }); </script> <script type="text/javascript"> (function() { if (window.MathJax != null) { var card = document.querySelector('.card'); MathJax.Hub.Queue(['Typeset', MathJax.Hub, card]); return; } var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_SVG-full'; document.body.appendChild(script); })(); </script>
<script>
const tags = document.getElementsByClassName("tags")[0].innerHTML.split(" ");

if (tags.indexOf("randomize") !== -1) {
        const elements = document.getElementsByTagName("B");
        let texts = Array.from(elements).map(e => e.innerHTML);
       
        for (let element of elements) {
          element.innerHTML = texts.splice(Math.floor(Math.random() * texts.length), 1);
        }
}
</script>

Wanted output:

{{Front}}

Idem with the answer template.

That would also solve the bug with apy output not showing closing html tags:

- <div id="kard"> <div class="tags">fixme</div> KanjiInContext 
+ <div id="kard"> <div class="tags">fixme KanjiInContext 

AdrienLemaire avatar Sep 18 '20 00:09 AdrienLemaire

It might be more flexible to rely on external formatting tools to handle coloring the output, and will allow users to customize their colors.

Interesting thought. Currently, I have to admit the way I've handled outputting text in apy is suboptimal. I started out just using the click module with explicit styling. With time I gradually landed on more and more standardized markdown output. And today I regret not just relying on more rich backends (pun intended).

The consequence is that what you are asking will require a lot of work, if I'm not wrong. Perhaps it's possible to tell click to not use colors, which would be possible to combine with your usage of grc? That is, you could pipe the output, but it wouldn't work with interactive apy commands.

Actually, @lervag could we only output the content of Basic/Front or Cloze/Text, instead of showing the whole template ?

I'm sorry, I'm not sure what you mean here. Which apy command are you thinking about here?

lervag avatar Sep 20 '20 20:09 lervag

Actually, @lervag could we only output the content of Basic/Front or Cloze/Text, instead of showing the whole template ?

I'm sorry, I'm not sure what you mean here. Which apy command are you thinking about here?

Sorry, I made 2 requests in one issue, that was confusing. As shown in the issue screenshot, I was referring to apy list

Instead of

$ apy list -v tag:fixme
Q: <div id="kard"> <div class="tags">fixme KanjiInContext reading:  観音様の慈悲深い顔   <script type="text/x-mathjax-config"> MathJax.Hub.processSectionDelay = 0; MathJax.Hub.Config({ messageStyle:"none",
A: <div id="kard">     <div class="tags" id='tags'>fixme KanjiInContext     reading:  観音様の慈悲深い顔            <div id='extra'>観音様・かんのんさま・Kannon; Buddhist deity of mercy 慈悲深い・じひ(ぶかい)・me
cid: 1476235043070 ease: 250.0% lapses: 0 due: 866 model: Basic

It'd be more useful to see

$ apy list -v tag:fixme
Q: reading:  観音様の慈悲深い顔
A: 観音様・かんのんさま・Kannon; Buddhist deity of mercy 慈悲深い・じひ(ぶかい)・mercy, charity, compassion, benevolence <img src="img_202009201110464526104076732266784.jpg">
cid: 1476235043070 ease: 250.0% lapses: 0 due: 866 model: Basic

AdrienLemaire avatar Sep 23 '20 00:09 AdrienLemaire

First, I'm sorry for my very long silence on this issue!

I'm curious: is this issue still of interest to you? If so, would it be possible for you to open a new issue where you repeat the description of what you want? It will make it easier for me to pick it up again and to make an attempt at solving it.

Also, I notice you made some personal commits that may address this; were you considering to post a PR? I would be more than happy to help, if that would be the case.

lervag avatar Jun 03 '23 15:06 lervag