uTools-Manuals/docs/php/sapi_windows_vt100_support.html
2019-04-28 19:00:34 +08:00

149 lines
8.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Get or set VT100 support for the specified stream associated to an output buffer of a Windows console.</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.sapi-windows-vt100-support" class="refentry">
<div class="refnamediv">
<h1 class="refname">sapi_windows_vt100_support</h1>
<p class="verinfo">(PHP 7 &gt;= 7.2.0)</p><p class="refpurpose"><span class="refname">sapi_windows_vt100_support</span> &mdash; <span class="dc-title">Get or set VT100 support for the specified stream associated to an output buffer of a Windows console.</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.sapi-windows-vt100-support-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>sapi_windows_vt100_support</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stream</code></span>
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$enable</code></span>
] ) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
If <code class="parameter">enable</code> is omitted, the function returns <strong><code>TRUE</code></strong> if the stream <code class="parameter">stream</code> has VT100 control codes enabled, <strong><code>FALSE</code></strong> otherwise.
</p>
<p class="para">
If <code class="parameter">enable</code> is specified, the function will try to enable or disable the VT100 features of the stream <code class="parameter">stream</code>.
If the feature has been successfully enabled (or disabled), the function will return <strong><code>TRUE</code></strong>, or <strong><code>FALSE</code></strong> otherwise.
</p>
<p class="para">
At startup, PHP tries to enable the VT100 feature of the <strong><code>STDOUT</code></strong>/<strong><code>STDERR</code></strong> streams. By the way, if those streams are redirected to a file, the VT100 features may not be enabled.
</p>
<p class="para">
If VT100 support is enabled, it is possible to use control sequences as they are known from the VT100 terminal.
They allow the modification of the terminal&#039;s output. On Windows these sequences are called Console Virtual Terminal Sequences.
</p>
<div class="warning"><strong class="warning">Warning</strong>
<p class="simpara">
This function uses the <strong><code>ENABLE_VIRTUAL_TERMINAL_PROCESSING</code></strong> flag implemented in the Windows 10 API, so the VT100 feature may not be available on older Windows versions.
</p>
</div>
</div>
<div class="refsect1 parameters" id="refsect1-function.sapi-windows-vt100-support-parameters">
<h3 class="title">参数</h3>
<dl>
<dt>
<code class="parameter">stream</code></dt>
<dd>
<p class="para">
The stream on which the function will operate.
</p>
</dd>
<dt>
<code class="parameter">enable</code></dt>
<dd>
<p class="para">
If specified, the VT100 feature will be enabled (if <strong><code>TRUE</code></strong>) or disabled (if <strong><code>FALSE</code></strong>).
</p>
</dd>
</dl>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.sapi-windows-vt100-support-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
If <code class="parameter">enable</code> is not specified: returns <strong><code>TRUE</code></strong> if the VT100 feature is enabled, <strong><code>FALSE</code></strong> otherwise.
</p>
<p class="para">
If <code class="parameter">enable</code> is specified: 成功时返回 <strong><code>TRUE</code></strong> 或者在失败时返回 <strong><code>FALSE</code></strong>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.sapi-windows-vt100-support-examples">
<h3 class="title">范例</h3>
<div class="example" id="example-4545">
<p><strong>Example #1 <span class="function"><strong>sapi_windows_vt100_support()</strong></span> default state</strong></p>
<div class="example-contents"><p>
By default, <strong><code>STDOUT</code></strong> and <strong><code>STDERR</code></strong> have the VT100 feature enabled.
</p></div>
<div class="example-contents"><div class="shcode"><pre class="shcode">php -r &quot;var_export(sapi_windows_vt100_support(STDOUT));echo &#039; &#039;;var_export(sapi_windows_vt100_support(STDERR));&quot;</pre>
</div></div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
true true
</pre></div>
</div>
<div class="example-contents"><p>
By the way, if a stream is redirected, the VT100 feature will not be enabled:
</p></div>
<div class="example-contents"><div class="shcode"><pre class="shcode">php -r &quot;var_export(sapi_windows_vt100_support(STDOUT));echo &#039; &#039;;var_export(sapi_windows_vt100_support(STDERR));&quot; 2&gt;NUL</pre>
</div></div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen"><br />
true false<br />
</div>
</div>
<div class="example" id="example-4546">
<p><strong>Example #2 <span class="function"><strong>sapi_windows_vt100_support()</strong></span> changing state</strong></p>
<div class="example-contents"><p>
You won&#039;t be able to enable the VT100 feature of <strong><code>STDOUT</code></strong> or <strong><code>STDERR</code></strong> if the stream is redirected.
</p></div>
<div class="example-contents"><div class="shcode"><pre class="shcode">php -r &quot;var_export(sapi_windows_vt100_support(STDOUT, true));echo &#039; &#039;;var_export(sapi_windows_vt100_support(STDERR, true));&quot; 2&gt;NUL</pre>
</div></div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
true false
</pre></div>
</div>
</div>
<div class="example" id="example-4547">
<p><strong>Example #3 Example usage of VT100 support enabled</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$out&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://stdout'</span><span style="color: #007700">,</span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$out</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Just&nbsp;forgot&nbsp;a&nbsp;lettr.'</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;Moves&nbsp;the&nbsp;cursor&nbsp;two&nbsp;characters&nbsp;backwards<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$out</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\033[2D"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;Inserts&nbsp;one&nbsp;blank,&nbsp;shifting&nbsp;existing&nbsp;text&nbsp;to&nbsp;the&nbsp;right&nbsp;-&gt;&nbsp;Just&nbsp;forgot&nbsp;a&nbsp;lett&nbsp;r.<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$out</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\033[1@"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$out</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'e'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Just forgot a letter.
</pre></div>
</div>
</div>
</div>
</div></div></div></body></html>