【问题标题】:Implementing the "more filter" in C在 C 中实现“更多过滤器”
【发布时间】:2012-04-29 13:58:21
【问题描述】:

我想知道如何实现更多过滤器 - 就像显示文本一样,直到它填满屏幕并用“Enter”移动每一行(就像在 UNIX 中一样)。我知道 ncurses 会很有用,但找不到合适的方法。

谢谢!

【问题讨论】:

  • 看看源代码怎么样?
  • 您可以阅读简单的more 变体的实际来源,例如from busybox。对于more,不需要完整的 ncurses;只获得一个屏幕尺寸(这也是可选的)。

标签: c shell unix


【解决方案1】:

做一个两个缓冲区的实现

这可以是一个大纲:

Read from file into the 1st buffer.

offset = 0

while `offset != total_lines_in_file`
  [1] show `max_lines_in_a_page` number of lines starting from line number `offset`
  [2] when showing the lines if a buffer end is detected, load the other buffer and switch buffer, and print remaining lines.
  [3] if the specific scroll keypress is detected make `offset = offset + x` (x = 1, 2 etc.)

最好看一下more实现的源代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-15
    • 2016-02-06
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    • 2021-08-31
    • 2023-01-17
    • 2019-07-03
    相关资源
    最近更新 更多