语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -7,7 +7,7 @@
<p>与 UNIX 中的大多数命令一样tput 命令既可以用在 shell 命令行中也可以用在 shell 脚本中。为让您更好地理解 tput本文首先从命令行讲起然后紧接着讲述 shell 脚本示例。</p>
<p><strong>光标属性</strong></p>
<p>在 UNIX shell 脚本中或在命令行中,移动光标或更改光标属性可能是非常有用的。有些情况下,您可能需要输入敏感信息(如密码),或在屏幕上两个不同的区域输入信息。在此类情况下,使用 tput 可能会对您有所帮助。</p>
<pre><code>tput clear # 清屏
<pre><code class="language-bash">tput clear # 清屏
tput sc # 保存当前光标位置
tput cup 10 13 # 将光标移动到 row col
tput civis # 光标不可见
@@ -19,15 +19,15 @@ exit 0</code></pre>
<p>要在设备上将光标移动到第 5 列 (X) 的第 1 行 (Y),只需执行 tput cup 5 1。另一个示例是 tput cup 23 45此命令将使光标移动到第 23 列上的第 45 行。</p>
<p><strong>移动光标并显示信息</strong></p>
<p>另一种有用的光标定位技巧是移动光标,执行用于显示信息的命令,然后返回到前一光标位置:</p>
<pre><code>(tput sc ; tput cup 23 45 ; echo “Input from tput/echo at 23/45” ; tput rc)</code></pre>
<pre><code class="language-bash">(tput sc ; tput cup 23 45 ; echo “Input from tput/echo at 23/45” ; tput rc)</code></pre>
<p>下面我们分析一下 subshell 命令:</p>
<pre><code>tput sc</code></pre>
<pre><code class="language-bash">tput sc</code></pre>
<p>必须首先保存当前的光标位置。要保存当前的光标位置,请包括 sc 选项或“save cursor position”。</p>
<pre><code>tput cup 23 45</code></pre>
<pre><code class="language-bash">tput cup 23 45</code></pre>
<p>在保存了光标位置后,光标坐标将移动到 (23,45)。</p>
<pre><code>echo “Input from tput/echo at 23/45”</code></pre>
<pre><code class="language-bash">echo “Input from tput/echo at 23/45”</code></pre>
<p>将信息显示到 stdout 中。</p>
<pre><code>tput rc</code></pre>
<pre><code class="language-bash">tput rc</code></pre>
<p>在显示了这些信息之后,光标必须返回到使用 tput sc 保存的原始位置。要使光标返回到其上次保存的位置,请包括 rc 选项或“restore cursor position”。</p>
<p>注意:由于本文首先详细介绍了通过命令行执行 tput因此您可能会觉得在自己的 subshell 中执行命令要比单独执行每条命令然后在每条命令执行之前显示提示更简洁。</p>
<p><strong>更改光标的属性</strong></p>
@@ -46,13 +46,13 @@ exit 0</code></pre>
<li>7白色</li>
</ul>
<p>执行以下示例命令可以将背景颜色更改为黄色,将前景颜色更改为红色:</p>
<pre><code>tput setb 6 tput setf 4</code></pre>
<pre><code class="language-bash">tput setb 6 tput setf 4</code></pre>
<p>要反显当前的颜色方案,只需执行<code>tput rev</code></p>
<p>有时,仅为文本着色还不够,也就是说,您想要通过另一种方式引起用户的注意。可以通过两种方式达到这一目的:一是将文本设置为粗体,二是为文本添加下划线。</p>
<p>要将文本更改为粗体,请使用 bold 选项。要开始添加下划线,请使用 smul 选项。在完成显示带下划线的文本后,请使用 rmul 选项。</p>
<h3 id="实例">实例</h3>
<p>使输出的字符串有颜色,底色,加粗:</p>
<pre><code>#!/bin/bash
<pre><code class="language-bash">#!/bin/bash
printf $(tput setaf 2; tput bold)&#39;color show\n\n&#39;$(tput sgr0)
for((i=0; i&lt;=7; i++)); do
@@ -67,7 +67,7 @@ done
exit 0</code></pre>
<p>输出格式控制函数:</p>
<pre><code>#!/bin/bash
<pre><code class="language-bash">#!/bin/bash
# $1 str print string
# $2 color 0-7 设置颜色
@@ -116,7 +116,7 @@ format_output &quot;Yesterday Once more&quot; 2 5 1 1
exit 0</code></pre>
<p>光标属性例子:</p>
<pre><code>#!/bin/bash
<pre><code class="language-bash">#!/bin/bash
# clear the screen
tput clear
# Move cursor to screen location X,Y (top left is 0,0)