prompt_toolkit的prompt()函数初始显示长文本被截断的解决方法咨询
prompt_toolkit的prompt()函数初始显示长文本被截断的解决方法咨询
我最近在做一个功能:读取PDF文件的文本内容,然后在命令行里把这段文本显示为可编辑的字符串。我选用了pdf_plumber来读取PDF,prompt_toolkit的prompt()函数来实现命令行的可编辑输入,不过遇到了个问题,想请教大家。
先给大家看一下我的测试PDF内容和代码:
sample.pdf 内容
Section 1 This is a sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. Section 2 This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. Section 3 This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. Section 4 This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. Section 5 This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.
test.py 代码
import pdfplumber from prompt_toolkit import prompt doc = pdfplumber.open("sample.pdf") content_list = [] for num in range(0, len(doc.pages)): content_list.append(doc.pages[num].extract_text()) string = content_list[0] for num in range(1, len(content_list)): string += content_list[num] string = "".join(content_list) retrieve_input = prompt("Display the string:\n\n", default=string) print(retrieve_input)
遇到的问题
运行代码后,命令行里显示的可编辑字符串是被截断的,只能看到部分内容;但如果按上箭头键,就能滚动看到完整的文本。之前用prompt()的时候是能直接显示全部文本的,不知道是不是开发过程中不小心改了什么系统设置,我已经卸载重装过prompt_toolkit了,问题还是没解决。
想问问大家,有没有办法让prompt()函数在初始显示的时候就展示完整的长文本,而不是截断呢?麻烦大家帮忙支个招,谢谢啦!
备注:内容来源于stack exchange,提问作者Viv
相关产品推荐
相关产品推荐

