通过添加标签

时间:2016-03-05 05:51:48

标签: ocaml

我的程序会输出大量信息。为了更好的可读性,一种方法是通过添加不同数量的选项卡将它们组织在不同的级别。例如,可以通过在打印之前始终打印多个标签来实现以下布局,并且可以通过全局参考变量来控制标签的数量。

level_1_begin
... ...
   level_2_begin
   ... ...
     level_3_begin
     ... ...
     level_3_end 
   level_2_end
... ...
   level_2_begin
   level_2_end
... ...
level_1_end   

然而,这种方式存在一个问题:当文本很长并且必须转到另一行时(由于窗口的宽度),它将忽略选项卡并从最左边开始。例如,

level_1_begin
... ...
   level_2_begin
   a very very very very very very very very very very
very very very very long line
   ... ...
   level_2_end

相反,我希望显示如下:

level_1_begin
... ...
   level_2_begin
   a very very very very very very very very very very 
   very very very very long line
   ... ...
   level_2_end

有人知道OCaml是否有任何解决方案可以实现这一目标?

1 个答案:

答案 0 :(得分:2)

使用Format module。方框here上有一个教程。