简体   繁体   English

使用python将日志文件的内容打印到curses屏幕

[英]printing contents of log file to curses screen using python

why doesnt this work? 为什么这不起作用? -- full code here... http://pastebin.com/f940nPPg - 这里的完整代码... http://pastebin.com/f940nPPg

....snip
f = open(log, 'r')
y = 3;
x = 3;

while True:
    c = quote_window.getch() 
    if c == ord('r') or c == ord('R'):
        quote_text_window.clear()
        quote_text_window.refresh()
        for line in f:
            quote_text_window.addstr(line)
            y = y + 1
            quote_text_window.move(y, x)

    elif c == ord('q') or c == ('Q'):
        break

    stdscr.noutrefresh()
    quote_window.noutrefresh()
    quote_text_window.noutrefresh()
    curses.doupdate()
f.close()
....snip

i get error 我收到错误

    quote_text_window.addstr(line)
    _curses.error: addwstr() returned ERR

if i pass addstr() a string literal i get 如果我通过addstr()传递一个字符串文字我得到

    quote_text_window.move(y, x)
    _curses.error: wmove() returned ERR

i'm trying to develope a curses interface for reading log files. 我正在尝试开发一个用于读取日志文件的curses界面。 i'd like it to utilize ssh or something so i can read various log files from various computers in one interface. 我希望它利用ssh或其他东西,所以我可以在一个界面中从各种计算机读取各种日志文件。 im' sure there are a ton of great programs that do this kind of thing but i thought it would be a good way to learn. 我确定有很多伟大的程序可以做这种事情,但我认为这将是一个很好的学习方式。 i'm new to programming, python and curses (as you can probably tell) 我是编程,python和curses的新手(你可能会说)

Can you supply the entire code with comments included to explain certain parts you think might cause the problem? 您是否可以提供包含注释的整个代码来解释您认为可能导致问题的某些部分? Anyways, how many lines is your log file? 无论如何,你的日志文件有多少行? Because, if there are too many lines, it just doesn't run, like my terminal is 80 col and 24 lines, so if I had a log file that was 21 lines, the program doesn't work. 因为,如果行太多,它就不会运行,就像我的终端是80 col和24行一样,所以如果我有一个21行的日志文件,程序就不能运行了。

like Cold Diamondz said the text file cant be larger than the window but if you use a pad you can call a large file and tell the pad what dimensions to refresh. 就像Cold Diamondz说的那样,文本文件不能比窗口大,但是如果你使用一个打击垫,你可以调用一个大文件并告诉打击垫要刷新哪些尺寸。 check out pads http://docs.python.org/3.3/howto/curses.html 检查垫http://docs.python.org/3.3/howto/curses.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM