当显示长列表和其他大值时,utop会将它们封装在大约80列上,即使我的终端窗口更宽。如何更改输出宽度?
我发现唯一可能提供解决方案的是UTop.size,它具有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.)]发布于 2017-05-02 10:02:45
有一个叫做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]https://stackoverflow.com/questions/43721446
复制相似问题