Skip to content

Commit 617a42b

Browse files
committed
fix: use pyperclip.waitForNewPaste() to avoid repeated operations on the same text
1 parent f99d297 commit 617a42b

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pip install aftercopy
99
aftercopy -v
1010
```
1111

12-
然后去阅读器中复制文字,再粘贴时得到的已经是处理好(去掉换行、替换标点)的结果了。
12+
然后去阅读器中复制文字,再粘贴时得到的已经是处理好(去掉换行、替换标点)的结果了。由于无法识别分段,段落之间需要使用者手动分开。
1313

14-
使用完毕后请记得关闭,避免影响常规的复制粘贴用途
14+
使用完毕后请记得关闭,避免影响常规的复制粘贴的使用
1515

1616
## 用法
1717

@@ -33,7 +33,7 @@ Options:
3333

3434
## 原理
3535

36-
每隔 2 秒读一次剪贴板,若发生改变则对新读入的文字作相应的处理,将结果重新写入剪贴板。
36+
每隔 0.01 秒读一次剪贴板(性能影响可忽略不计),若发生改变则对新读入的文字作相应的处理,将结果重新写入剪贴板。
3737

3838
## TODO
3939

@@ -42,4 +42,4 @@ Options:
4242

4343
## One more thing...
4444

45-
请勿用作抄袭等侵犯他人著作权的用途
45+
请勿用于抄袭等侵犯他人著作权的用途

aftercopy.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,17 @@ def main(passive, verbose, lang):
6767

6868
if passive:
6969
# paste and re-copy
70-
s = ""
71-
for line in sys.stdin:
72-
s += line
73-
click.echo(Text(s, lang=lang).clean)
70+
while True:
71+
s = "".join(sys.stdin.readlines())
72+
click.echo(Text(s, lang=lang).clean)
7473

7574
else:
7675
# read clipboard and re-copy
77-
# initial
78-
tmpText = Text(pyperclip.paste(), lang=lang)
79-
copy_echo(tmpText.clean, verbose=verbose)
80-
time.sleep(2)
81-
82-
# loop
76+
clipText = Text(pyperclip.waitForPaste(), lang=lang)
77+
copy_echo(clipText.clean, verbose=verbose)
8378
while True:
84-
newText = Text(pyperclip.paste(), lang=lang)
85-
if newText.raw == tmpText.raw or newText.raw == tmpText.clean:
86-
continue
87-
copy_echo(newText.clean, verbose=verbose)
88-
89-
tmpText = newText
90-
time.sleep(2)
79+
clipText = Text(pyperclip.waitForNewPaste(), lang=lang)
80+
copy_echo(clipText.clean, verbose=verbose)
9181

9282

9383
if __name__ == "__main__":

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="aftercopy",
11-
version="0.1.0",
11+
version="0.1.1",
1212
description="A helper tool that processes text copied from PDF, removing newlines, replacing punctuation and more.",
1313
long_description=long_description,
1414
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)