2

当显示长列表和其他大值时,utop 将它们包装在大约 80 列,即使我的终端窗口更宽。如何更改输出宽度?

我发现唯一可能提供解决方案的是UTop.size,它具有 type LTerm_geom.size React.signal,并且似乎正确记录了我的终端窗口的大小。在此示例中,我的终端窗口的尺寸为 164x37:

# #require "react";;
# #require "lambda-term";;
# React.S.value UTop.size;;
- : LTerm_geom.size = {LTerm_geom.rows = 37; cols = 164}

但是, 的值cols似乎不会影响值的显示方式。例如,这是从同一会话中复制的(显示时带有换行符):

# List.hd algs;;
- : (int list * float) list =
[([2; 1; 0], 1.); ([2; 1], 0.54148398267); ([2; 0], 0.677137905076);
 ([2], 0.218621887745); ([1; 0], 0.781378112255); ([1], 0.322862094924);
 ([0], 0.45851601733); ([], 0.)]
4

1 回答 1

2

有一个函数叫做UTop.set_margin_function

μ> #typeof "UTop.set_margin_function";;
val UTop.set_margin_function : (LTerm_geom.size -> int option) -> unit

这是一个简单的示例用法:

μ> UTop.set_margin_function (fun _ -> Some 150);;

此后 utop 将使用大约 150 列来打印结果。

这是一个示例会话(shell + utop):

> utop -version
The universal toplevel for OCaml, version 1.19.3, compiled for OCaml version 4.04.1

> cat ~/.ocamlinit
(* Added by OPAM. *)
let () =
  try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
  with Not_found -> ()
;;

> cat ~/.utoprc
cat: .utoprc: No such file or directory

> utop

utop # gen_nat_list 1 50;;   (* gen_nat_list is some test function *)
- : int list =
[1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22;
23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39; 40; 41;
42; 43; 44; 45; 46; 47; 48; 49; 50]

utop # UTop.set_margin_function (fun _ -> Some 150);;

utop # gen_nat_ist 1 50;;
- : int list =
[1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32; 33; 34; 35; 36; 37; 38; 39;
 40; 41; 42; 43; 44; 45; 46; 47; 48; 49; 50]
于 2017-05-02T10:02:45.460 回答