Closed jwbensley closed 3 years ago
I will look into these failures and update the pull request.
@jwbensley i think this is due to doctest + line endings, however, it requires a bit more investigation. Your help would be very much appreciated!
Hi @kroitor,
After looking into this issue a bit more the problem relates to the way the colour codes are always used in my pull request.
I tried to implement the colouring in the Python version in the same way it is implemented in the JS version to keep the to files aligned. When no colour is specified in the JS version it prints the chart with no colour symbols:
function colored (char, color) {
// do not color it if color is not specified
return (color === undefined) ? char : (color + char + exports.reset)
}
In the python version I was defaulting to the reset
colour which is effectively no colour but it stll prints a colour symbol:
reset = "\033[0m"
...
colors = cfg.get('colors', [reset])
It can't be seen in any diff
output for example (f1
is the current master branch and f2
is my original pull request):
$diff ./f1 ../asciichart2/f2
1,4c1,4
< 4.00 ┤ ╭╴╶╮
< 3.00 ┤ ╭╯ ╰╮
< 2.00 ┤╭╯ ╰╮
< 1.00 ┼╯ ╰
---
> 4.00 ┤ ╭╴╶╮
> 3.00 ┤ ╭╯ ╰╮
> 2.00 ┤╭╯ ╰╮
> 1.00 ┼╯ ╰
But it can be seen with hexdump
:
hexdump -C f1
00000000 20 20 20 20 34 2e 30 30 20 20 e2 94 a4 20 20 e2 | 4.00 ... .|
00000010 95 ad e2 95 b4 e2 95 b6 e2 95 ae 0a 20 20 20 20 |............ |
00000020 33 2e 30 30 20 20 e2 94 a4 20 e2 95 ad e2 95 af |3.00 ... ......|
00000030 20 20 e2 95 b0 e2 95 ae 0a 20 20 20 20 32 2e 30 | ....... 2.0|
00000040 30 20 20 e2 94 a4 e2 95 ad e2 95 af 20 20 20 20 |0 ......... |
00000050 e2 95 b0 e2 95 ae 0a 20 20 20 20 31 2e 30 30 20 |....... 1.00 |
00000060 20 e2 94 bc e2 95 af 20 20 20 20 20 20 e2 95 b0 | ...... ...|
00000070 0a |.|
00000071
$hexdump -C ../asciichart2/f2
00000000 20 20 20 20 34 2e 30 30 20 20 e2 94 a4 20 20 1b | 4.00 ... .|
00000010 5b 30 6d e2 95 ad 1b 5b 30 6d 1b 5b 30 6d e2 95 |[0m....[0m.[0m..|
00000020 b4 1b 5b 30 6d 1b 5b 30 6d e2 95 b6 1b 5b 30 6d |..[0m.[0m....[0m|
00000030 1b 5b 30 6d e2 95 ae 1b 5b 30 6d 0a 20 20 20 20 |.[0m....[0m. |
00000040 33 2e 30 30 20 20 e2 94 a4 20 1b 5b 30 6d e2 95 |3.00 ... .[0m..|
00000050 ad 1b 5b 30 6d 1b 5b 30 6d e2 95 af 1b 5b 30 6d |..[0m.[0m....[0m|
00000060 20 20 1b 5b 30 6d e2 95 b0 1b 5b 30 6d 1b 5b 30 | .[0m....[0m.[0|
00000070 6d e2 95 ae 1b 5b 30 6d 0a 20 20 20 20 32 2e 30 |m....[0m. 2.0|
00000080 30 20 20 e2 94 a4 1b 5b 30 6d e2 95 ad 1b 5b 30 |0 ....[0m....[0|
00000090 6d 1b 5b 30 6d e2 95 af 1b 5b 30 6d 20 20 20 20 |m.[0m....[0m |
000000a0 1b 5b 30 6d e2 95 b0 1b 5b 30 6d 1b 5b 30 6d e2 |.[0m....[0m.[0m.|
000000b0 95 ae 1b 5b 30 6d 0a 20 20 20 20 31 2e 30 30 20 |...[0m. 1.00 |
000000c0 20 e2 94 bc 1b 5b 30 6d e2 95 af 1b 5b 30 6d 20 | ....[0m....[0m |
000000d0 20 20 20 20 20 1b 5b 30 6d e2 95 b0 1b 5b 30 6d | .[0m....[0m|
000000e0 0a |.|
000000e1
I've adjusted my commit to match the JS version of asciichart, no colour symbols are printed when no colours are specified rather than defaulting to a "blank" colour. This is from my updated pull request:
$hexdump -C ../asciichart2/f2
00000000 20 20 20 20 34 2e 30 30 20 20 e2 94 a4 20 20 e2 | 4.00 ... .|
00000010 95 ad e2 95 b4 e2 95 b6 e2 95 ae 0a 20 20 20 20 |............ |
00000020 33 2e 30 30 20 20 e2 94 a4 20 e2 95 ad e2 95 af |3.00 ... ......|
00000030 20 20 e2 95 b0 e2 95 ae 0a 20 20 20 20 32 2e 30 | ....... 2.0|
00000040 30 20 20 e2 94 a4 e2 95 ad e2 95 af 20 20 20 20 |0 ......... |
00000050 e2 95 b0 e2 95 ae 0a 20 20 20 20 31 2e 30 30 20 |....... 1.00 |
00000060 20 e2 94 bc e2 95 af 20 20 20 20 20 20 e2 95 b0 | ...... ...|
00000070 0a |.|
00000071
Bump
Thanks!
Hi @kroitor,
Sorry this is so late. I said I'd make a pull request to add colour support to the Python version several weeks ago!
This request just copies the colour code from the JS file to the Python file, implementing colour support in Python exactly the same way it's implemented in JavaScript, to keep the Python version of
asciichart
consistent with the JS version.Below is the script I used to generate a small test with multiple data series (which is why colouring is needed);
Here is a screenshot showing the output: