A CLI tool for downloading from pixiv.net
Revision | 8dbbeef616745b389f9f6d256d1fbe966d3ac1a4 (tree) |
---|---|
Time | 2023-09-27 17:27:55 |
Author | mio <stigma@disr...> |
Commiter | mio |
Pad 'Already downloaded page X' values
Also considering changing the message to 'Already downloaded page x/y'
@@ -18,7 +18,7 @@ dependency "magickd:graphicsmagick_c" \ | ||
18 | 18 | |
19 | 19 | dependency "pixivd" \ |
20 | 20 | repository="git+https://pf.osdn.net/gitroot/n/ne/nemophila/pixivd.git" \ |
21 | - version="1085361d86366542741e8ae5b845fed74c0a8aa5" | |
21 | + version="c9a28e4f8521840f3919c5a38817906e6be1fdef" | |
22 | 22 | |
23 | 23 | ######################################################## |
24 | 24 | # If you are using the "fetch_dependencies.sh" script, # |
@@ -0,0 +1,7 @@ | ||
1 | +{ | |
2 | + "fileVersion": 1, | |
3 | + "versions": { | |
4 | + "magickd": {"version":"dd4985919d78d0cf37ab4b2ab99bb2ecec6aec15","repository":"git+https://repo.or.cz/magickd.git"}, | |
5 | + "pixivd": {"version":"c9a28e4f8521840f3919c5a38817906e6be1fdef","repository":"git+https://pf.osdn.net/gitroot/n/ne/nemophila/pixivd.git"} | |
6 | + } | |
7 | +} |
@@ -48,21 +48,31 @@ import pixivd.client; | ||
48 | 48 | |
49 | 49 | class ProgressMonitor |
50 | 50 | { |
51 | + import std.format : format; | |
52 | + import util : getTerminalColumns; | |
53 | + | |
51 | 54 | size_t currentImage = 1; |
52 | 55 | |
53 | 56 | void alreadyComplete(PageAlreadyDownloadedEvent ev) |
54 | 57 | { |
55 | - import std.format : format; | |
56 | - import util : getTerminalColumns; | |
57 | - | |
58 | - string prompt = "\r Already downloaded page %d.".format(currentImage); | |
59 | - size_t remLength = getTerminalColumns() - prompt.length; | |
60 | - | |
61 | - write(prompt); | |
62 | - for (int i = 0; i < remLength; i++) { | |
63 | - write(' '); | |
58 | + import std.conv : ConvException, to; | |
59 | + | |
60 | + size_t promptLength = 0; | |
61 | + | |
62 | + try { | |
63 | + const numberOfDigits = to!string(ev.totalPages).length; | |
64 | + const modifier = format("%%%dd", numberOfDigits); | |
65 | + const promptWM = format("\r Already downloaded page %s.", | |
66 | + modifier); | |
67 | + writefln(promptWM, currentImage); | |
68 | + } catch (ConvException ce) { | |
69 | + debug(app) | |
70 | + { | |
71 | + stderr.writefln("ERORR converting size_t to string"); | |
72 | + stderr.writefln(" --> %s", ce.msg); | |
73 | + } | |
74 | + writefln("\r Already downloaded page %d.", currentImage); | |
64 | 75 | } |
65 | - write('\n'); | |
66 | 76 | currentImage += 1; |
67 | 77 | } |
68 | 78 |
@@ -84,10 +94,18 @@ class ProgressMonitor | ||
84 | 94 | |
85 | 95 | void complete(DownloadCompleteEvent ev) |
86 | 96 | { |
87 | - write('\n'); | |
88 | 97 | if (ev.forPage) { |
98 | + string prompt = "\r Downloaded page %d.".format(currentImage); | |
99 | + size_t remLength = getTerminalColumns() - prompt.length; | |
100 | + | |
101 | + write(prompt); | |
102 | + for (int i = 0; i < remLength; i++) { | |
103 | + write(' '); | |
104 | + } | |
105 | + | |
89 | 106 | currentImage += 1; |
90 | 107 | } |
108 | + write('\n'); | |
91 | 109 | } |
92 | 110 | } |
93 | 111 |