mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
421 lines
No EOL
29 KiB
HTML
421 lines
No EOL
29 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="style.css" type="text/css">
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="Start" href="index.html">
|
|
<link rel="previous" href="CCMap.html">
|
|
<link rel="next" href="CCIO.html">
|
|
<link rel="Up" href="index.html">
|
|
<link title="Index of types" rel=Appendix href="index_types.html">
|
|
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
|
|
<link title="Index of values" rel=Appendix href="index_values.html">
|
|
<link title="Index of class methods" rel=Appendix href="index_methods.html">
|
|
<link title="Index of class types" rel=Appendix href="index_class_types.html">
|
|
<link title="Index of modules" rel=Appendix href="index_modules.html">
|
|
<link title="Index of module types" rel=Appendix href="index_module_types.html">
|
|
<link title="CCVector" rel="Chapter" href="CCVector.html">
|
|
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
|
|
<link title="CCList" rel="Chapter" href="CCList.html">
|
|
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
|
|
<link title="CCPair" rel="Chapter" href="CCPair.html">
|
|
<link title="CCFun" rel="Chapter" href="CCFun.html">
|
|
<link title="CCHash" rel="Chapter" href="CCHash.html">
|
|
<link title="CCInt" rel="Chapter" href="CCInt.html">
|
|
<link title="CCBool" rel="Chapter" href="CCBool.html">
|
|
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
|
|
<link title="CCArray" rel="Chapter" href="CCArray.html">
|
|
<link title="CCRef" rel="Chapter" href="CCRef.html">
|
|
<link title="CCSet" rel="Chapter" href="CCSet.html">
|
|
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
|
|
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
|
|
<link title="CCString" rel="Chapter" href="CCString.html">
|
|
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
|
|
<link title="CCMap" rel="Chapter" href="CCMap.html">
|
|
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
|
|
<link title="CCIO" rel="Chapter" href="CCIO.html">
|
|
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
|
|
<link title="CCChar" rel="Chapter" href="CCChar.html">
|
|
<link title="CCResult" rel="Chapter" href="CCResult.html">
|
|
<link title="CCParse" rel="Chapter" href="CCParse.html">
|
|
<link title="CCArray_slice" rel="Chapter" href="CCArray_slice.html">
|
|
<link title="CCListLabels" rel="Chapter" href="CCListLabels.html">
|
|
<link title="CCArrayLabels" rel="Chapter" href="CCArrayLabels.html">
|
|
<link title="CCEqual" rel="Chapter" href="CCEqual.html">
|
|
<link title="Containers" rel="Chapter" href="Containers.html">
|
|
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
|
|
<link title="CCKList" rel="Chapter" href="CCKList.html">
|
|
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
|
|
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
|
|
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
|
|
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
|
|
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
|
|
<link title="CCCache" rel="Chapter" href="CCCache.html">
|
|
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
|
|
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
|
|
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
|
|
<link title="CCBV" rel="Chapter" href="CCBV.html">
|
|
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
|
|
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
|
|
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
|
|
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
|
|
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
|
|
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
|
|
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
|
|
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
|
|
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
|
|
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
|
|
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
|
|
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
|
|
<link title="CCSimple_queue" rel="Chapter" href="CCSimple_queue.html">
|
|
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
|
|
<link title="CCHet" rel="Chapter" href="CCHet.html">
|
|
<link title="CCZipper" rel="Chapter" href="CCZipper.html">
|
|
<link title="CCPool" rel="Chapter" href="CCPool.html">
|
|
<link title="CCLock" rel="Chapter" href="CCLock.html">
|
|
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
|
|
<link title="CCThread" rel="Chapter" href="CCThread.html">
|
|
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
|
|
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
|
|
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
|
|
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
|
|
<link title="CCSexp_lex" rel="Chapter" href="CCSexp_lex.html"><link title="Combinators" rel="Section" href="#2_Combinators">
|
|
<link title="ANSI codes" rel="Section" href="#2_ANSIcodes">
|
|
<link title="IO" rel="Section" href="#2_IO">
|
|
<link title="Dump" rel="Section" href="#2_Dump">
|
|
<title>Containers doc : CCFormat</title>
|
|
</head>
|
|
<body>
|
|
<div class="navbar"><a class="pre" href="CCMap.html" title="CCMap">Previous</a>
|
|
<a class="up" href="index.html" title="Index">Up</a>
|
|
<a class="post" href="CCIO.html" title="CCIO">Next</a>
|
|
</div>
|
|
<h1>Module <a href="type_CCFormat.html">CCFormat</a></h1>
|
|
|
|
<pre><span class="keyword">module</span> CCFormat: <code class="code"><span class="keyword">sig</span></code> <a href="CCFormat.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
|
|
<h1 id="1_HelpersforFormat">Helpers for Format</h1><br>
|
|
<b>Since</b> 0.8<br>
|
|
</div>
|
|
<hr width="100%">
|
|
|
|
<pre><span id="TYPEsequence"><span class="keyword">type</span> <code class="type">'a</code> sequence</span> = <code class="type">('a -> unit) -> unit</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type"></code>t</span> = <code class="type">Format.formatter</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEprinter"><span class="keyword">type</span> <code class="type">'a</code> printer</span> = <code class="type"><a href="CCFormat.html#TYPEt">t</a> -> 'a -> unit</code> </pre>
|
|
|
|
<br>
|
|
<h2 id="2_Combinators">Combinators</h2><br>
|
|
|
|
<pre><span id="VALsilent"><span class="keyword">val</span> silent</span> : <code class="type">'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Prints nothing<br>
|
|
</div>
|
|
|
|
<pre><span id="VALunit"><span class="keyword">val</span> unit</span> : <code class="type">unit <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Prints "()"<br>
|
|
</div>
|
|
|
|
<pre><span id="VALint"><span class="keyword">val</span> int</span> : <code class="type">int <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALstring"><span class="keyword">val</span> string</span> : <code class="type">string <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALbool"><span class="keyword">val</span> bool</span> : <code class="type">bool <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALfloat3"><span class="keyword">val</span> float3</span> : <code class="type">float <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALfloat"><span class="keyword">val</span> float</span> : <code class="type">float <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALnewline"><span class="keyword">val</span> newline</span> : <code class="type">unit <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Force newline (see <code class="code"><span class="constructor">Format</span>.pp_force_newline</code>)<br>
|
|
<b>Since</b> 1.2<br>
|
|
</div>
|
|
|
|
<pre><span id="VALsubstring"><span class="keyword">val</span> substring</span> : <code class="type">(string * int * int) <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Print the substring <code class="code">(s,i,len)</code>, where <code class="code">i</code> is the offset
|
|
in <code class="code">s</code> and <code class="code">len</code> the number of bytes in the substring.<br>
|
|
<b>Since</b> 1.2<br>
|
|
<b>Raises</b> <code>Invalid_argument</code> if the triple <code class="code">(s,i,len)</code> does not
|
|
describe a proper substring.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALtext"><span class="keyword">val</span> text</span> : <code class="type">string <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Print string, but replacing spaces with breaks and newlines
|
|
with <a href="CCFormat.html#VALnewline"><code class="code"><span class="constructor">CCFormat</span>.newline</code></a>.
|
|
See <code class="code">pp_print_text</code> on recent versions of OCaml.<br>
|
|
<b>Since</b> 1.2<br>
|
|
</div>
|
|
|
|
<pre><span id="VALchar"><span class="keyword">val</span> char</span> : <code class="type">char <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALint32"><span class="keyword">val</span> int32</span> : <code class="type">int32 <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALint64"><span class="keyword">val</span> int64</span> : <code class="type">int64 <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALnativeint"><span class="keyword">val</span> nativeint</span> : <code class="type">nativeint <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALflush"><span class="keyword">val</span> flush</span> : <code class="type">unit <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Alias to <code class="code"><span class="constructor">Format</span>.pp_print_flush</code>.<br>
|
|
<b>Since</b> 1.2<br>
|
|
</div>
|
|
|
|
<pre><span id="VALstring_quoted"><span class="keyword">val</span> string_quoted</span> : <code class="type">string <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Similar to <code class="code"><span class="constructor">CCString</span>.print</code>.<br>
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALlist"><span class="keyword">val</span> list</span> : <code class="type">?sep:unit <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a list <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALarray"><span class="keyword">val</span> array</span> : <code class="type">?sep:unit <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a array <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALarrayi"><span class="keyword">val</span> arrayi</span> : <code class="type">?sep:unit <a href="CCFormat.html#TYPEprinter">printer</a> -><br> (int * 'a) <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a array <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALseq"><span class="keyword">val</span> seq</span> : <code class="type">?sep:unit <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEsequence">sequence</a> <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALopt"><span class="keyword">val</span> opt</span> : <code class="type">'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a option <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<code class="code">opt pp</code> prints options as follows:
|
|
<code class="code"><span class="constructor">Some</span> x</code> will become "some foo" if <code class="code">pp x ---> <span class="string">"foo"</span></code>
|
|
<code class="code"><span class="constructor">None</span></code> will become "none"<br>
|
|
</div>
|
|
<br>
|
|
In the tuple printers, the <code class="code">sep</code> argument is only available<br>
|
|
|
|
<pre><span id="VALpair"><span class="keyword">val</span> pair</span> : <code class="type">?sep:unit <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'b <a href="CCFormat.html#TYPEprinter">printer</a> -> ('a * 'b) <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALtriple"><span class="keyword">val</span> triple</span> : <code class="type">?sep:unit <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'b <a href="CCFormat.html#TYPEprinter">printer</a> -> 'c <a href="CCFormat.html#TYPEprinter">printer</a> -> ('a * 'b * 'c) <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALquad"><span class="keyword">val</span> quad</span> : <code class="type">?sep:unit <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'b <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'c <a href="CCFormat.html#TYPEprinter">printer</a> -><br> 'd <a href="CCFormat.html#TYPEprinter">printer</a> -> ('a * 'b * 'c * 'd) <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALwithin"><span class="keyword">val</span> within</span> : <code class="type">string -> string -> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<code class="code">within a b p</code> wraps <code class="code">p</code> inside the strings <code class="code">a</code> and <code class="code">b</code>. Convenient,
|
|
for instances, for brackets, parenthesis, quotes, etc.<br>
|
|
<b>Since</b> 0.17<br>
|
|
</div>
|
|
|
|
<pre><span id="VALmap"><span class="keyword">val</span> map</span> : <code class="type">('a -> 'b) -> 'b <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre>
|
|
<pre><span id="VALvbox"><span class="keyword">val</span> vbox</span> : <code class="type">?i:int -> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Wrap the printer in a vertical box<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">i</code> : level of indentation within the box (default 0)</div>
|
|
|
|
<pre><span id="VALhvbox"><span class="keyword">val</span> hvbox</span> : <code class="type">?i:int -> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Wrap the printer in a horizontal/vertical box<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">i</code> : level of indentation within the box (default 0)</div>
|
|
|
|
<pre><span id="VALhovbox"><span class="keyword">val</span> hovbox</span> : <code class="type">?i:int -> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Wrap the printer in a horizontal or vertical box<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">i</code> : level of indentation within the box (default 0)</div>
|
|
|
|
<pre><span id="VALhbox"><span class="keyword">val</span> hbox</span> : <code class="type">'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
Wrap the printer in an horizontal box<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALreturn"><span class="keyword">val</span> return</span> : <code class="type">('a, 'b, 'c, 'a) Pervasives.format4 -> unit <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<code class="code">return <span class="string">"some_format_string"</span></code> takes a argument-less format string
|
|
and returns a printer actionable by <code class="code">()</code>.
|
|
Examples:<ul>
|
|
<li><code class="code">return <span class="string">",@ "</span></code></li>
|
|
<li><code class="code">return <span class="string">"@{<Red>and then@}@,"</span></code></li>
|
|
<li><code class="code">return <span class="string">"@[<v>a@ b@]"</span></code></li>
|
|
</ul>
|
|
<br>
|
|
<b>Since</b> 1.0<br>
|
|
</div>
|
|
|
|
<pre><span id="VALof_to_string"><span class="keyword">val</span> of_to_string</span> : <code class="type">('a -> string) -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<code class="code">of_to_string f</code> converts its input to a string using <code class="code">f</code>,
|
|
then prints the string<br>
|
|
<b>Since</b> 1.0<br>
|
|
</div>
|
|
|
|
<pre><span id="VALconst"><span class="keyword">val</span> const</span> : <code class="type">'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a -> unit <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<code class="code">const pp x</code> is a unit printer that uses <code class="code">pp</code> on <code class="code">x</code><br>
|
|
<b>Since</b> 1.0<br>
|
|
</div>
|
|
|
|
<pre><span id="VALsome"><span class="keyword">val</span> some</span> : <code class="type">'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a option <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<code class="code">some pp</code> will print options as follows:<ul>
|
|
<li><code class="code"><span class="constructor">Some</span> x</code> is printed using <code class="code">pp</code> on <code class="code">x</code></li>
|
|
<li><code class="code"><span class="constructor">None</span></code> is not printed at all</li>
|
|
</ul>
|
|
<br>
|
|
<b>Since</b> 1.0<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_ANSIcodes">ANSI codes</h2>
|
|
<p>
|
|
|
|
Use ANSI escape codes https://en.wikipedia.org/wiki/ANSI_escape_code
|
|
to put some colors on the terminal.
|
|
<p>
|
|
|
|
This uses <b>tags</b> in format strings to specify the style. Current styles
|
|
are the following:
|
|
<p>
|
|
|
|
<ul>
|
|
<li>"reset" resets style</li>
|
|
<li>"black" </li>
|
|
<li>"red" </li>
|
|
<li>"green" </li>
|
|
<li>"yellow" </li>
|
|
<li>"blue" </li>
|
|
<li>"magenta" </li>
|
|
<li>"cyan" </li>
|
|
<li>"white" </li>
|
|
<li>"bold" bold font</li>
|
|
<li>"Black" bold black</li>
|
|
<li>"Red" bold red </li>
|
|
<li>"Green" bold green </li>
|
|
<li>"Yellow" bold yellow </li>
|
|
<li>"Blue" bold blue </li>
|
|
<li>"Magenta" bold magenta </li>
|
|
<li>"Cyan" bold cyan </li>
|
|
<li>"White" bold white </li>
|
|
</ul>
|
|
|
|
<p>
|
|
|
|
Example:
|
|
<p>
|
|
|
|
<pre class="codepre"><code class="code"> set_color_default <span class="keyword">true</span>;;
|
|
|
|
<span class="constructor">Format</span>.printf
|
|
<span class="string">"what is your @{<White>favorite color@}? @{<blue>blue@}! No, @{<red>red@}! Ahhhhhhh@."</span>;;
|
|
</code></pre>
|
|
<p>
|
|
|
|
<b>status: experimental</b><br>
|
|
|
|
<pre><span id="VALset_color_tag_handling"><span class="keyword">val</span> set_color_tag_handling</span> : <code class="type"><a href="CCFormat.html#TYPEt">t</a> -> unit</code></pre><div class="info ">
|
|
adds functions to support color tags to the given formatter.<br>
|
|
<b>Since</b> 0.15<br>
|
|
</div>
|
|
|
|
<pre><span id="VALset_color_default"><span class="keyword">val</span> set_color_default</span> : <code class="type">bool -> unit</code></pre><div class="info ">
|
|
<code class="code">set_color_default b</code> enables color handling on the standard formatters
|
|
(stdout, stderr) if <code class="code">b = <span class="keyword">true</span></code> as well as on <a href="CCFormat.html#VALsprintf"><code class="code"><span class="constructor">CCFormat</span>.sprintf</code></a> formatters;
|
|
it disables the color handling if <code class="code">b = <span class="keyword">false</span></code>.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwith_color"><span class="keyword">val</span> with_color</span> : <code class="type">string -> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a></code></pre><div class="info ">
|
|
<code class="code">with_color <span class="string">"Blue"</span> pp</code> behaves like the printer <code class="code">pp</code>, but with the given
|
|
style.
|
|
<b>status: experimental</b><br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwith_colorf"><span class="keyword">val</span> with_colorf</span> : <code class="type">string -> <a href="CCFormat.html#TYPEt">t</a> -> ('a, <a href="CCFormat.html#TYPEt">t</a>, unit, unit) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
<code class="code">with_colorf <span class="string">"Blue"</span> out <span class="string">"%s %d"</span> <span class="string">"yolo"</span> 42</code> will behave like <code class="code"><span class="constructor">Format</span>.fprintf</code>,
|
|
but wrapping the content with the given style
|
|
<b>status: experimental</b><br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwith_color_sf"><span class="keyword">val</span> with_color_sf</span> : <code class="type">string -> ('a, <a href="CCFormat.html#TYPEt">t</a>, unit, string) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
<code class="code">with_color_sf <span class="string">"Blue"</span> out <span class="string">"%s %d"</span> <span class="string">"yolo"</span> 42</code> will behave like
|
|
<a href="CCFormat.html#VALsprintf"><code class="code"><span class="constructor">CCFormat</span>.sprintf</code></a>, but wrapping the content with the given style
|
|
Example:
|
|
<pre class="codepre"><code class="code"> <span class="constructor">CCFormat</span>.with_color_sf <span class="string">"red"</span> <span class="string">"%a"</span> <span class="constructor">CCFormat</span>.<span class="constructor">Dump</span>.(list int) [1;2;3] |> print_endline;;
|
|
</code></pre>
|
|
<b>status: experimental</b><br>
|
|
<b>Since</b> 0.21<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwith_color_ksf"><span class="keyword">val</span> with_color_ksf</span> : <code class="type">f:(string -> 'b) -><br> string -> ('a, <a href="CCFormat.html#TYPEt">t</a>, unit, 'b) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
<code class="code">with_color_ksf <span class="string">"Blue"</span> ~f <span class="string">"%s %d"</span> <span class="string">"yolo"</span> 42</code> will behave like
|
|
<a href="CCFormat.html#VALksprintf"><code class="code"><span class="constructor">CCFormat</span>.ksprintf</code></a>, but wrapping the content with the given style
|
|
Example:
|
|
the following with raise <code class="code"><span class="constructor">Failure</span></code> with a colored message
|
|
<pre class="codepre"><code class="code"> <span class="constructor">CCFormat</span>.with_color_ksf <span class="string">"red"</span> ~f:failwith <span class="string">"%a"</span> <span class="constructor">CCFormat</span>.<span class="constructor">Dump</span>.(list int) [1;2;3];;
|
|
</code></pre><br>
|
|
<b>Since</b> 1.2<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_IO">IO</h2><br>
|
|
|
|
<pre><span id="VALoutput"><span class="keyword">val</span> output</span> : <code class="type"><a href="CCFormat.html#TYPEt">t</a> -> 'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a -> unit</code></pre>
|
|
<pre><span id="VALto_string"><span class="keyword">val</span> to_string</span> : <code class="type">'a <a href="CCFormat.html#TYPEprinter">printer</a> -> 'a -> string</code></pre>
|
|
<pre><span id="VALof_chan"><span class="keyword">val</span> of_chan</span> : <code class="type">Pervasives.out_channel -> <a href="CCFormat.html#TYPEt">t</a></code></pre><div class="info ">
|
|
Alias to <code class="code"><span class="constructor">Format</span>.formatter_of_out_channel</code><br>
|
|
<b>Since</b> 1.2<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwith_out_chan"><span class="keyword">val</span> with_out_chan</span> : <code class="type">Pervasives.out_channel -> (<a href="CCFormat.html#TYPEt">t</a> -> 'a) -> 'a</code></pre><div class="info ">
|
|
<code class="code">with_out_chan oc f</code> turns <code class="code">oc</code> into a formatter <code class="code">fmt</code>, and call <code class="code">f fmt</code>.
|
|
Behaves like <code class="code">f fmt</code> from then on, but whether the call to <code class="code">f</code> fails
|
|
or returns, <code class="code">fmt</code> is flushed before the call terminates.<br>
|
|
<b>Since</b> 1.2<br>
|
|
</div>
|
|
|
|
<pre><span id="VALstdout"><span class="keyword">val</span> stdout</span> : <code class="type"><a href="CCFormat.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALstderr"><span class="keyword">val</span> stderr</span> : <code class="type"><a href="CCFormat.html#TYPEt">t</a></code></pre>
|
|
<pre><span id="VALtee"><span class="keyword">val</span> tee</span> : <code class="type"><a href="CCFormat.html#TYPEt">t</a> -> <a href="CCFormat.html#TYPEt">t</a> -> <a href="CCFormat.html#TYPEt">t</a></code></pre><div class="info ">
|
|
<code class="code">tee a b</code> makes a new formatter that writes in both <code class="code">a</code> and <code class="code">b</code>.<br>
|
|
<b>Since</b> 1.0<br>
|
|
</div>
|
|
|
|
<pre><span id="VALsprintf"><span class="keyword">val</span> sprintf</span> : <code class="type">('a, <a href="CCFormat.html#TYPEt">t</a>, unit, string) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
Print into a string any format string that would usually be compatible
|
|
with <a href="CCFormat.html#VALfprintf"><code class="code"><span class="constructor">CCFormat</span>.fprintf</code></a>. Similar to <code class="code"><span class="constructor">Format</span>.asprintf</code>.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALsprintf_no_color"><span class="keyword">val</span> sprintf_no_color</span> : <code class="type">('a, <a href="CCFormat.html#TYPEt">t</a>, unit, string) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
Similar to <a href="CCFormat.html#VALsprintf"><code class="code"><span class="constructor">CCFormat</span>.sprintf</code></a> but never prints colors<br>
|
|
<b>Since</b> 0.16<br>
|
|
</div>
|
|
|
|
<pre><span id="VALsprintf_dyn_color"><span class="keyword">val</span> sprintf_dyn_color</span> : <code class="type">colors:bool -> ('a, <a href="CCFormat.html#TYPEt">t</a>, unit, string) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
Similar to <a href="CCFormat.html#VALsprintf"><code class="code"><span class="constructor">CCFormat</span>.sprintf</code></a> but enable/disable colors depending on <code class="code">colors</code>.
|
|
Example:
|
|
<pre class="codepre"><code class="code"> <span class="comment">(* with colors *)</span>
|
|
<span class="constructor">CCFormat</span>.sprintf_dyn_color ~colors:<span class="keyword">true</span> <span class="string">"@{<Red>%a@}"</span>
|
|
<span class="constructor">CCFormat</span>.<span class="constructor">Dump</span>.(list int) [1;2;3] |> print_endline;;
|
|
|
|
<span class="comment">(* without colors *)</span>
|
|
<span class="constructor">CCFormat</span>.sprintf_dyn_color ~colors:<span class="keyword">false</span> <span class="string">"@{<Red>%a@}"</span>
|
|
<span class="constructor">CCFormat</span>.<span class="constructor">Dump</span>.(list int) [1;2;3] |> print_endline;;
|
|
</code></pre><br>
|
|
<b>Since</b> 0.21<br>
|
|
</div>
|
|
|
|
<pre><span id="VALfprintf"><span class="keyword">val</span> fprintf</span> : <code class="type"><a href="CCFormat.html#TYPEt">t</a> -> ('a, <a href="CCFormat.html#TYPEt">t</a>, unit) Pervasives.format -> 'a</code></pre><div class="info ">
|
|
Alias to <code class="code"><span class="constructor">Format</span>.fprintf</code><br>
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALfprintf_dyn_color"><span class="keyword">val</span> fprintf_dyn_color</span> : <code class="type">colors:bool -> <a href="CCFormat.html#TYPEt">t</a> -> ('a, <a href="CCFormat.html#TYPEt">t</a>, unit) Pervasives.format -> 'a</code></pre><div class="info ">
|
|
Similar to <a href="CCFormat.html#VALfprintf"><code class="code"><span class="constructor">CCFormat</span>.fprintf</code></a> but enable/disable colors depending on <code class="code">colors</code><br>
|
|
<b>Since</b> 0.21<br>
|
|
</div>
|
|
|
|
<pre><span id="VALksprintf"><span class="keyword">val</span> ksprintf</span> : <code class="type">f:(string -> 'b) -> ('a, Format.formatter, unit, 'b) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
<code class="code">ksprintf fmt ~f</code> formats using <code class="code">fmt</code>, in a way similar to <a href="CCFormat.html#VALsprintf"><code class="code"><span class="constructor">CCFormat</span>.sprintf</code></a>,
|
|
and then calls <code class="code">f</code> on the resulting string.<br>
|
|
<b>Since</b> 0.14<br>
|
|
</div>
|
|
|
|
<pre><span id="VALto_file"><span class="keyword">val</span> to_file</span> : <code class="type">string -> ('a, <a href="CCFormat.html#TYPEt">t</a>, unit, unit) Pervasives.format4 -> 'a</code></pre><div class="info ">
|
|
Print to the given file<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Dump">Dump</h2>
|
|
<p>
|
|
|
|
Print structures as OCaml values, so that they can be parsed back
|
|
by OCaml (typically, in the toplevel, for debugging).
|
|
<p>
|
|
|
|
Example:
|
|
<pre class="codepre"><code class="code"> <span class="constructor">Format</span>.printf <span class="string">"%a@."</span> <span class="constructor">CCFormat</span>.<span class="constructor">Dump</span>.(list int) <span class="constructor">CCList</span>.(1 -- 200);;
|
|
|
|
<span class="constructor">Format</span>.printf <span class="string">"%a@."</span> <span class="constructor">CCFormat</span>.<span class="constructor">Dump</span>.(array (list (pair int bool)))
|
|
[| [1, <span class="keyword">true</span>; 2, <span class="keyword">false</span>]; []; [42, <span class="keyword">false</span>] |];;
|
|
</code></pre><br>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCFormat.Dump.html">Dump</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCFormat.Dump.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html> |