-
-
Notifications
You must be signed in to change notification settings - Fork 975
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
Use sys.stdout.flush()
in skip
and success
#2529
Comments
The bug is still exists with Git-Bash without enabled For example, download With |
What's the output of What you are describing here and have been in other issues sounds like Python doesn't recognize your terminal as a regular TTY and does not enable line buffering by default, among other things. $ python -c "import sys; print(f'{sys.stdout.line_buffering = }\n{sys.stdout.isatty() = }')"
sys.stdout.line_buffering = True
sys.stdout.isatty() = True |
With the default Git-Bash settings (so without echo "MSYS=disable_pcon" > /etc/git-bash.config
sys.stdout.line_buffering = False
sys.stdout.isatty() = False In this case With Git-Bash uses MinTTY. |
All writes to stdout now get explicitly flushed (eeef9cc) This would not be necessary if Python would properly detect Git-Bash/MinTTY with its default settings and enable Not the end of the world, but I would've liked to find a solution that calls |
Something like Strategy pattern const isFlushRequired = // ...
function getStdWrite() {
if (isFlushRequired) {
return text => {
process.stdout.write(text);
process.stdout.flush();
};
}
return text => {
process.stdout.write(text);
};
} Or just function stdWrite(text) {
process.stdout.write(text);
if (isFlushRequired) {
process.stdout.flush();
}
} |
|
Turns out, all you need to fix the color output in PowerShell is to just include these two lines in
Found that out from here: https://stackoverflow.com/a/64222858 |
@mikf In addition to the change above, could you add an output setting that would allow for My proposal is output.prepend and it's set to this by default: |
Apparently OSes other than Windows uses a checkmark for success, so maybe this instead: If success/skip is set to a string, it prepends that instead, unless color mode is active and force is set to its default of false. If success/skip is set to false, then it wouldn't prepend anything even if color mode is active. If force is set to true, then prepends would function in color mode. |
work in progress the same output as produced by "mode": "color" can be achieved with "output": { "mode": { "start" : "{}", "success": "\r\u001b[1;32m{}\u001b[0m\n", "skip" : "\u001b[2m{}\u001b[0m\n", "progress" : "\r{0:>7}B {1:>7}B/s ", "progress-total": "\r{3:>3}% {0:>7}B {1:>7}B/s " } } to make 'output.shorten' work correctly, it is necessary to manually specify the number of extra characters: "start" : [12, "Downloading {}"]
@ImportTaste instead of implementing all sort of extra options, 7990fe8 adds a way to more or less completely customize the standard output and download progress bar. No explicit documentation for now, since I'm not sure if I want to leave it like this (suggestions welcome), but the commit message example is hopefully good enough to get the general idea across. For the download progress format strings:
|
The problem is that with This is not the default because it produces wrong results if the appropriate fonts aren't available and all/some characters are displayed as |
Hm, it works. I thought I already used monospaced font. For example, I usually use "—" as a separator for keys. In the screenshots above it is not long. Ah, wait, yeah, the hieroglyphs take 2 chars width. On the first line there are 10 hieroglyphs so 10 chars were moved to the second line. |
nb. this has nothing to do with monospaced fonts. Monospace here means simply the glyphs all have the same horizontal width, this applies only to display/rendering, it's not related to the "technical" width of a character (or a string) of 1 (as in one byte), that is the encoding, not displaying. |
On Windows with colored output text enabled (
"output": {"mode": "color"}
) the buffering is abnormally aggressive.In some cases I can see the output in the console only after the program end (when all downloads are skipped).
The simple fix is using of
in
skip
(and insuccess
, just in case) methods of ColorOutput class.gallery-dl/gallery_dl/output.py
Lines 318 to 323 in d85e66b
Most likely because of this also Ctrl+C works very bad.
There are no problems without colored text enabled, btw. (When it uses "
#
" prefix for the skipped downloads instead of gray coloring.)The text was updated successfully, but these errors were encountered: