Skip to content

Commit

Permalink
net-p2p/py-ed2k-tools: some last minute style and commentary/spelling…
Browse files Browse the repository at this point in the history
… fixes.
  • Loading branch information
Alexey Dokuchaev authored and Alexey Dokuchaev committed May 21, 2023
1 parent 61576df commit 3d36384
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion net-p2p/py-ed2k-tools/files/patch-fix__sofar.py
Expand Up @@ -28,7 +28,7 @@
+ print("If you want to create new .met files with this 'bug' corrected, run this")
+ print("program with the affected .met files as the command line arguments. You")
+ print("will get new .met files titled X.new, where X was the original .part.met")
+ print("file. Copy these over the top of your originals if you're sure thats what")
+ print("file. Copy these over the top of your originals if you're sure that's what")
+ print("you want to do.")
+ print()
+ print("Of course, Overnet will re-break these files on its next exit. You'll")
Expand Down
4 changes: 2 additions & 2 deletions net-p2p/py-ed2k-tools/files/patch-make__met.py
Expand Up @@ -18,7 +18,7 @@
+ print("argument, which represents the ed2k:// link provided as the second arg.")
+ print()
+ print("Useful for adding things to your download list without actually opening")
+ print("Overnet / Donkey.")
+ print("Overnet/eDonkey2000.")
sys.exit( -1 );

temp_dir = sys.argv[ 1 ];
Expand All @@ -40,7 +40,7 @@
# Convert the printed hash into a byte representation.
# Surely there's an easier way to do this.
- new_hash = "";
+ new_hash = b''
+ new_hash = b""
while hash:
part = hash[ 0 : 2 ];
hash = hash[ 2 : ];
Expand Down
13 changes: 8 additions & 5 deletions net-p2p/py-ed2k-tools/files/patch-temp__summary.py
Expand Up @@ -50,7 +50,7 @@

# Set the total downloaded to the file size.
down = size;
@@ -71,19 +66,39 @@ if __name__ == "__main__":
@@ -71,19 +66,42 @@ if __name__ == "__main__":
bar = "#" * ( WIDTH - 2 );
for gap in gaps:
gap_start, gap_end = gaps[ gap ];
Expand All @@ -60,23 +60,26 @@
+ char_gap_end = int(gap_end / bytes_per_char)
bar = bar[ : char_gap_start ] + " " * ( char_gap_end - char_gap_start ) + bar[ char_gap_end : ];
+
+ # Account for CJK characters occupy two terminal spaces
+ # Account for CJK characters occupy two fixed-width spaces.
+ def char_width(c: str) -> int:
+ if not c.isprintable(): return 0
+ return 2 if unicodedata.category(c) == 'Lo' else 1
+
+ def visible_len(s: str) -> int:
+ return sum(char_width(c) for c in s)
+
+ # Truncate string to specified limit. If truncation happens
+ # on double-width character (like it would have to be cut in
+ # half), append an extra space for nicer alignment.
+ def visible_substr_padded(s: str, l: int) -> str:
+ vislen = 0
+ cut_here = 0
+ padding = ''
+ for c in s:
+ vislen += char_width(c)
+ if (vislen <= l): cut_here += 1
+ if (vislen == l): break
+ if (vislen > l): padding = ' '; break
+ if vislen <= l: cut_here += 1
+ if vislen == l: break
+ if vislen > l: padding = ' '; break
+ return s[:cut_here] + padding

# Print out our summary. Limit the filenames.
Expand Down

0 comments on commit 3d36384

Please sign in to comment.