From 617a42bcbadc2a5f1282ed090063b41a861074c5 Mon Sep 17 00:00:00 2001 From: CoolSpring8 Date: Wed, 27 May 2020 10:05:14 +0800 Subject: [PATCH] fix: use pyperclip.waitForNewPaste() to avoid repeated operations on the same text --- README.md | 8 ++++---- aftercopy.py | 24 +++++++----------------- setup.py | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 835d5ef..449c524 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ pip install aftercopy aftercopy -v ``` -然后去阅读器中复制文字,再粘贴时得到的已经是处理好(去掉换行、替换标点)的结果了。 +然后去阅读器中复制文字,再粘贴时得到的已经是处理好(去掉换行、替换标点)的结果了。由于无法识别分段,段落之间需要使用者手动分开。 -使用完毕后请记得关闭,避免影响常规的复制粘贴用途。 +使用完毕后请记得关闭,避免影响常规的复制粘贴的使用。 ## 用法 @@ -33,7 +33,7 @@ Options: ## 原理 -每隔 2 秒读一次剪贴板,若发生改变则对新读入的文字作相应的处理,将结果重新写入剪贴板。 +每隔 0.01 秒读一次剪贴板(性能影响可忽略不计),若发生改变则对新读入的文字作相应的处理,将结果重新写入剪贴板。 ## TODO @@ -42,4 +42,4 @@ Options: ## One more thing... -请勿用作抄袭等侵犯他人著作权的用途。 \ No newline at end of file +请勿用于抄袭等侵犯他人著作权的用途。 \ No newline at end of file diff --git a/aftercopy.py b/aftercopy.py index cf11464..c7b0e27 100644 --- a/aftercopy.py +++ b/aftercopy.py @@ -67,27 +67,17 @@ def main(passive, verbose, lang): if passive: # paste and re-copy - s = "" - for line in sys.stdin: - s += line - click.echo(Text(s, lang=lang).clean) + while True: + s = "".join(sys.stdin.readlines()) + click.echo(Text(s, lang=lang).clean) else: # read clipboard and re-copy - # initial - tmpText = Text(pyperclip.paste(), lang=lang) - copy_echo(tmpText.clean, verbose=verbose) - time.sleep(2) - - # loop + clipText = Text(pyperclip.waitForPaste(), lang=lang) + copy_echo(clipText.clean, verbose=verbose) while True: - newText = Text(pyperclip.paste(), lang=lang) - if newText.raw == tmpText.raw or newText.raw == tmpText.clean: - continue - copy_echo(newText.clean, verbose=verbose) - - tmpText = newText - time.sleep(2) + clipText = Text(pyperclip.waitForNewPaste(), lang=lang) + copy_echo(clipText.clean, verbose=verbose) if __name__ == "__main__": diff --git a/setup.py b/setup.py index f088ba1..e9a341d 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name="aftercopy", - version="0.1.0", + version="0.1.1", description="A helper tool that processes text copied from PDF, removing newlines, replacing punctuation and more.", long_description=long_description, long_description_content_type="text/markdown",