This commit is contained in:
sylvestre
2023-07-18 03:02:32 +00:00
parent d28cff4bca
commit 5ac2c8c7be
4 changed files with 184 additions and 6 deletions
+85 -1
View File
@@ -313,6 +313,48 @@
<a href="#313" id="313">313</a>
<a href="#314" id="314">314</a>
<a href="#315" id="315">315</a>
<a href="#316" id="316">316</a>
<a href="#317" id="317">317</a>
<a href="#318" id="318">318</a>
<a href="#319" id="319">319</a>
<a href="#320" id="320">320</a>
<a href="#321" id="321">321</a>
<a href="#322" id="322">322</a>
<a href="#323" id="323">323</a>
<a href="#324" id="324">324</a>
<a href="#325" id="325">325</a>
<a href="#326" id="326">326</a>
<a href="#327" id="327">327</a>
<a href="#328" id="328">328</a>
<a href="#329" id="329">329</a>
<a href="#330" id="330">330</a>
<a href="#331" id="331">331</a>
<a href="#332" id="332">332</a>
<a href="#333" id="333">333</a>
<a href="#334" id="334">334</a>
<a href="#335" id="335">335</a>
<a href="#336" id="336">336</a>
<a href="#337" id="337">337</a>
<a href="#338" id="338">338</a>
<a href="#339" id="339">339</a>
<a href="#340" id="340">340</a>
<a href="#341" id="341">341</a>
<a href="#342" id="342">342</a>
<a href="#343" id="343">343</a>
<a href="#344" id="344">344</a>
<a href="#345" id="345">345</a>
<a href="#346" id="346">346</a>
<a href="#347" id="347">347</a>
<a href="#348" id="348">348</a>
<a href="#349" id="349">349</a>
<a href="#350" id="350">350</a>
<a href="#351" id="351">351</a>
<a href="#352" id="352">352</a>
<a href="#353" id="353">353</a>
<a href="#354" id="354">354</a>
<a href="#355" id="355">355</a>
<a href="#356" id="356">356</a>
<a href="#357" id="357">357</a>
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
// *
// * For the full copyright and license information, please view the LICENSE file
@@ -322,6 +364,8 @@
// spell-checker:ignore ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixoff ixon iuclc ixany imaxbel iutf
// spell-checker:ignore opost olcuc ocrnl onlcr onocr onlret ofill ofdel nldly crdly tabdly bsdly vtdly ffdly
// spell-checker:ignore isig icanon iexten echoe crterase echok echonl noflsh xcase tostop echoprt prterase echoctl ctlecho echoke crtkill flusho extproc
// spell-checker:ignore lnext rprnt susp swtch vdiscard veof veol verase vintr vkill vlnext vquit vreprint vstart vstop vsusp vswtc vwerase werase
// spell-checker:ignore sigquit sigtstp
</span><span class="kw">use </span><span class="kw">crate</span>::Flag;
@@ -334,7 +378,10 @@
target_os = <span class="string">&quot;openbsd&quot;
</span>)))]
</span><span class="kw">use </span>nix::sys::termios::BaudRate;
<span class="kw">use </span>nix::sys::termios::{ControlFlags <span class="kw">as </span>C, InputFlags <span class="kw">as </span>I, LocalFlags <span class="kw">as </span>L, OutputFlags <span class="kw">as </span>O};
<span class="kw">use </span>nix::sys::termios::{
ControlFlags <span class="kw">as </span>C, InputFlags <span class="kw">as </span>I, LocalFlags <span class="kw">as </span>L, OutputFlags <span class="kw">as </span>O,
SpecialCharacterIndices <span class="kw">as </span>S,
};
<span class="kw">pub const </span>CONTROL_FLAGS: <span class="kw-2">&amp;</span>[Flag&lt;C&gt;] = <span class="kw-2">&amp;</span>[
Flag::new(<span class="string">&quot;parenb&quot;</span>, C::PARENB),
@@ -628,4 +675,41 @@
))]
</span>(<span class="string">&quot;4000000&quot;</span>, BaudRate::B4000000),
];
<span class="doccomment">/// Control characters for the stty command.
///
/// This constant provides a mapping between the names of control characters
/// and their corresponding values in the `S` enum.
</span><span class="kw">pub const </span>CONTROL_CHARS: <span class="kw-2">&amp;</span>[(<span class="kw-2">&amp;</span>str, S)] = <span class="kw-2">&amp;</span>[
<span class="comment">// Sends an interrupt signal (SIGINT).
</span>(<span class="string">&quot;intr&quot;</span>, S::VINTR),
<span class="comment">// Sends a quit signal (SIGQUIT).
</span>(<span class="string">&quot;quit&quot;</span>, S::VQUIT),
<span class="comment">// Deletes the last typed character.
</span>(<span class="string">&quot;erase&quot;</span>, S::VERASE),
<span class="comment">// Deletes the current line.
</span>(<span class="string">&quot;kill&quot;</span>, S::VKILL),
<span class="comment">// Signals the end of input.
</span>(<span class="string">&quot;eof&quot;</span>, S::VEOF),
<span class="comment">// Signals the end of line.
</span>(<span class="string">&quot;eol&quot;</span>, S::VEOL),
<span class="comment">// Alternate end-of-line character.
</span>(<span class="string">&quot;eol2&quot;</span>, S::VEOL2),
<span class="comment">// Switch character (only on Linux).
</span><span class="attr">#[cfg(target_os = <span class="string">&quot;linux&quot;</span>)]
</span>(<span class="string">&quot;swtch&quot;</span>, S::VSWTC),
<span class="comment">// Starts output after it has been stopped.
</span>(<span class="string">&quot;start&quot;</span>, S::VSTART),
<span class="comment">// Stops output.
</span>(<span class="string">&quot;stop&quot;</span>, S::VSTOP),
<span class="comment">// Sends a suspend signal (SIGTSTP).
</span>(<span class="string">&quot;susp&quot;</span>, S::VSUSP),
<span class="comment">// Reprints the current line.
</span>(<span class="string">&quot;rprnt&quot;</span>, S::VREPRINT),
<span class="comment">// Deletes the last word typed.
</span>(<span class="string">&quot;werase&quot;</span>, S::VWERASE),
<span class="comment">// Enters literal mode (next character is taken literally).
</span>(<span class="string">&quot;lnext&quot;</span>, S::VLNEXT),
<span class="comment">// Discards the current line.
</span>(<span class="string">&quot;discard&quot;</span>, S::VDISCARD),
];
</code></pre></div></section></main></body></html>
+97 -3
View File
@@ -464,12 +464,59 @@
<a href="#464" id="464">464</a>
<a href="#465" id="465">465</a>
<a href="#466" id="466">466</a>
<a href="#467" id="467">467</a>
<a href="#468" id="468">468</a>
<a href="#469" id="469">469</a>
<a href="#470" id="470">470</a>
<a href="#471" id="471">471</a>
<a href="#472" id="472">472</a>
<a href="#473" id="473">473</a>
<a href="#474" id="474">474</a>
<a href="#475" id="475">475</a>
<a href="#476" id="476">476</a>
<a href="#477" id="477">477</a>
<a href="#478" id="478">478</a>
<a href="#479" id="479">479</a>
<a href="#480" id="480">480</a>
<a href="#481" id="481">481</a>
<a href="#482" id="482">482</a>
<a href="#483" id="483">483</a>
<a href="#484" id="484">484</a>
<a href="#485" id="485">485</a>
<a href="#486" id="486">486</a>
<a href="#487" id="487">487</a>
<a href="#488" id="488">488</a>
<a href="#489" id="489">489</a>
<a href="#490" id="490">490</a>
<a href="#491" id="491">491</a>
<a href="#492" id="492">492</a>
<a href="#493" id="493">493</a>
<a href="#494" id="494">494</a>
<a href="#495" id="495">495</a>
<a href="#496" id="496">496</a>
<a href="#497" id="497">497</a>
<a href="#498" id="498">498</a>
<a href="#499" id="499">499</a>
<a href="#500" id="500">500</a>
<a href="#501" id="501">501</a>
<a href="#502" id="502">502</a>
<a href="#503" id="503">503</a>
<a href="#504" id="504">504</a>
<a href="#505" id="505">505</a>
<a href="#506" id="506">506</a>
<a href="#507" id="507">507</a>
<a href="#508" id="508">508</a>
<a href="#509" id="509">509</a>
<a href="#510" id="510">510</a>
<a href="#511" id="511">511</a>
<a href="#512" id="512">512</a>
<a href="#513" id="513">513</a>
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
// *
// * For the full copyright and license information, please view the LICENSE file
// * that was distributed with this source code.
// spell-checker:ignore clocal tcgetattr tcsetattr tcsanow tiocgwinsz tiocswinsz cfgetospeed cfsetospeed ushort
// spell-checker:ignore clocal erange tcgetattr tcsetattr tcsanow tiocgwinsz tiocswinsz cfgetospeed cfsetospeed ushort vmin vtime
</span><span class="kw">mod </span>flags;
@@ -477,7 +524,7 @@
<span class="kw">use </span>nix::libc::{c_ushort, O_NONBLOCK, TIOCGWINSZ, TIOCSWINSZ};
<span class="kw">use </span>nix::sys::termios::{
cfgetospeed, cfsetospeed, tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags,
OutputFlags, Termios,
OutputFlags, SpecialCharacterIndices, Termios,
};
<span class="kw">use </span>nix::{ioctl_read_bad, ioctl_write_ptr_bad};
<span class="kw">use </span>std::io::{<span class="self">self</span>, stdout};
@@ -496,7 +543,7 @@
target_os = <span class="string">&quot;openbsd&quot;
</span>)))]
</span><span class="kw">use </span>flags::BAUD_RATES;
<span class="kw">use </span>flags::{CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS};
<span class="kw">use </span>flags::{CONTROL_CHARS, CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS};
<span class="kw">const </span>USAGE: <span class="kw-2">&amp;</span>str = <span class="macro">help_usage!</span>(<span class="string">&quot;stty.md&quot;</span>);
<span class="kw">const </span>SUMMARY: <span class="kw-2">&amp;</span>str = <span class="macro">help_about!</span>(<span class="string">&quot;stty.md&quot;</span>);
@@ -711,6 +758,52 @@
<span class="prelude-val">Ok</span>(())
}
<span class="kw">fn </span>control_char_to_string(cc: nix::libc::cc_t) -&gt; nix::Result&lt;String&gt; {
<span class="kw">if </span>cc == <span class="number">0 </span>{
<span class="kw">return </span><span class="prelude-val">Ok</span>(<span class="string">&quot;&lt;undef&gt;&quot;</span>.to_string());
}
<span class="kw">let </span>(meta_prefix, code) = <span class="kw">if </span>cc &gt;= <span class="number">0x80 </span>{
(<span class="string">&quot;M-&quot;</span>, cc - <span class="number">0x80</span>)
} <span class="kw">else </span>{
(<span class="string">&quot;&quot;</span>, cc)
};
<span class="comment">// Determine the &#39;^&#39;-prefix if applicable and character based on the code
</span><span class="kw">let </span>(ctrl_prefix, character) = <span class="kw">match </span>code {
<span class="comment">// Control characters in ASCII range
</span><span class="number">0</span>..=<span class="number">0x1f </span>=&gt; <span class="prelude-val">Ok</span>((<span class="string">&quot;^&quot;</span>, (<span class="string">b&#39;@&#39; </span>+ code) <span class="kw">as </span>char)),
<span class="comment">// Printable ASCII characters
</span><span class="number">0x20</span>..=<span class="number">0x7e </span>=&gt; <span class="prelude-val">Ok</span>((<span class="string">&quot;&quot;</span>, code <span class="kw">as </span>char)),
<span class="comment">// DEL character
</span><span class="number">0x7f </span>=&gt; <span class="prelude-val">Ok</span>((<span class="string">&quot;^&quot;</span>, <span class="string">&#39;?&#39;</span>)),
<span class="comment">// Out of range (above 8 bits)
</span><span class="kw">_ </span>=&gt; <span class="prelude-val">Err</span>(nix::errno::Errno::ERANGE),
}<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(<span class="macro">format!</span>(<span class="string">&quot;{meta_prefix}{ctrl_prefix}{character}&quot;</span>))
}
<span class="kw">fn </span>print_control_chars(termios: <span class="kw-2">&amp;</span>Termios, opts: <span class="kw-2">&amp;</span>Options) -&gt; nix::Result&lt;()&gt; {
<span class="kw">if </span>!opts.all {
<span class="comment">// TODO: this branch should print values that differ from defaults
</span><span class="kw">return </span><span class="prelude-val">Ok</span>(());
}
<span class="kw">for </span>(text, cc_index) <span class="kw">in </span>CONTROL_CHARS {
<span class="macro">print!</span>(
<span class="string">&quot;{text} = {}; &quot;</span>,
control_char_to_string(termios.control_chars[<span class="kw-2">*</span>cc_index <span class="kw">as </span>usize])<span class="question-mark">?
</span>);
}
<span class="macro">println!</span>(
<span class="string">&quot;min = {}; time = {};&quot;</span>,
termios.control_chars[SpecialCharacterIndices::VMIN <span class="kw">as </span>usize],
termios.control_chars[SpecialCharacterIndices::VTIME <span class="kw">as </span>usize]
);
<span class="prelude-val">Ok</span>(())
}
<span class="kw">fn </span>print_in_save_format(termios: <span class="kw-2">&amp;</span>Termios) {
<span class="macro">print!</span>(
<span class="string">&quot;{:x}:{:x}:{:x}:{:x}&quot;</span>,
@@ -730,6 +823,7 @@
print_in_save_format(termios);
} <span class="kw">else </span>{
print_terminal_size(termios, opts)<span class="question-mark">?</span>;
print_control_chars(termios, opts)<span class="question-mark">?</span>;
print_flags(termios, opts, CONTROL_FLAGS);
print_flags(termios, opts, INPUT_FLAGS);
print_flags(termios, opts, OUTPUT_FLAGS);
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long