1

How do you prefer to format output of your console scripts? I mean output produced during application run (log, stdout).

BG: I have a python script that takes a data, processes it, updates some related data in my database and outputs progress. I can style output in various ways:

************ Starting programm X ************
Fetching 450 lands... Done
540 local lands found
syncronizing [--------                ] 10%
Done

Capitalized output or all letters in lower case? Indentation applied to output or not? What about visual sugar like dashes or hashes? Progress bars like in wget?

I understand that it's kind of design, but in Web we have some basic rules, we have usability, and we have no rules in console output art. What Jacob Nilsen says about output of console scripts?

4

1 回答 1

2

即使在控制台脚本中,可用性也非常重要。特别是对于任何长时间运行的进程,无论 UI 是图形的还是在终端中,显示任务进度的一些指示都会更好地使用。我建议查看Nielsen 的启发式方法 ,其中许多原则直接适用于控制台输出。在谈论可能有用的控制台输出时,特别是有三种启发式方法:

  1. 系统状态的可见性:通过某种进度条在控制台中显示进度,以显示在合理时间内发生的情况。
  2. 一致性和标准:您在问题破折号或散列中提到了这一点。
  3. 美学和极简设计:尝试并输出最少量的相关和有用的信息。

为了标准和一致性,请遵循现有流行命令的约定。两个不错的检查是wgetpv。它们都有非常相似的进度条:

wget

44% [================>                      ] 441,017,992  111MB/s  eta 6s

光伏

 138MB 0:00:01 [ 107MB/s] [=========================================>] 100%  

它们通常看起来相同。他们还坚持最小设计,在一行中以文本和条形形式指示完成百分比、速度、完成的字节数和 eta 或经过的时间。

在合理的时间更新方面。我倾向于每 0.1 秒更新一次控制台中的状态。要使界面感觉响应,您希望它在该范围内。wget 似乎每 0.2 秒更新一次。但是命令手表的默认值是2s,感觉太慢了。我通常最终运行该命令watch -n 0.1 command以获得 0.1 秒的更新间隔。

其中一条评论指出,您的输出应该是可解析和可管道的。如果可能的话,这是一件非常好的事情。我特别喜欢 wget 处理这个问题的方式。如果您在终端中运行 wget,它会使用条形进度指示器,但如果您通过管道传输到文件或其他程序,它会使用点进度指示器。它会自动检测您是否有 tty 或正在通过管道传输命令并选择最合适的格式。您可以在 --progress 参数文档下的手册页上阅读有关此内容的信息。本质上,它有一个更易于人类阅读的输出和另一个更机器可读和日志友好的输出。

一些相关/有用的链接:

于 2013-10-05T06:07:55.197 回答