Skip to content

Commit

Permalink
fix: use pyperclip.waitForNewPaste() to avoid repeated operations on …
Browse files Browse the repository at this point in the history
…the same text
  • Loading branch information
CoolSpring8 committed May 27, 2020
1 parent f99d297 commit 617a42b
Showing 3 changed files with 12 additions and 22 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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...

请勿用作抄袭等侵犯他人著作权的用途
请勿用于抄袭等侵犯他人著作权的用途
24 changes: 7 additions & 17 deletions aftercopy.py
Original file line number Diff line number Diff line change
@@ -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__":
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit 617a42b

Please sign in to comment.