Using U+ notation instead of M- for non-printing characters.
This commit is contained in:
parent
c43f8f5b27
commit
868a81b7ad
5 changed files with 18 additions and 24 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
# dcat: Concatenate File(s) to Standard Output
|
||||
|
||||
A **cat** command-line implemenation in [Dart](https://dart.dev/), inspired by the [Write command-line apps sample code](https://dart.dev/tutorials/server/cmdline).
|
||||
A **cat** command-line implementation in [Dart](https://dart.dev/), inspired by the [Write command-line apps sample code](https://dart.dev/tutorials/server/cmdline).
|
||||
|
||||
## Synopsis
|
||||
|
||||
|
@ -30,7 +30,7 @@ With no FILE, or when FILE is -, read standard input.
|
|||
-T, --show-tabs display TAB characters as ^I
|
||||
-s, --squeeze-blank suppress repeated empty output lines
|
||||
--version output version information and exit
|
||||
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
|
||||
-v, --show-nonprinting use ^ and U+ notation, except for LFD and TAB
|
||||
|
||||
Examples:
|
||||
dcat f - g Output f's contents, then standard input, then g's contents.
|
||||
|
@ -51,4 +51,5 @@ dart compile exe bin/dcat.dart
|
|||
## Differences from [GNU cat](https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation)
|
||||
- No binary file support.
|
||||
- A line is considered terminated by either a `CR` (carriage return), a `LF` (line feed), a `CR+LF` sequence (DOS line ending).
|
||||
- The non-printing `M-^?` notation is always used for unicode characters.
|
||||
- A line ending is automatically appended to the last line of any read file.
|
||||
- The `U+` notation is used instead of `M-` for non-printing characters.
|
|
@ -57,7 +57,7 @@ Future<int> main(List<String> arguments) async {
|
|||
parser.addFlag(showNonPrintingFlag,
|
||||
negatable: false,
|
||||
abbr: 'v',
|
||||
help: 'use ^ and M- notation, except for LFD and TAB');
|
||||
help: 'use ^ and U+ notation, except for LFD and TAB');
|
||||
|
||||
final ArgResults argResults;
|
||||
try {
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<p><a href="http://opensource.org/licenses/BSD-3-Clause"><img src="https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square" alt="License (3-Clause BSD)"></a>
|
||||
<a href="https://github.com/ethauvin/dcat/actions/workflows/dart.yml"><img src="https://github.com/ethauvin/dcat/actions/workflows/dart.yml/badge.svg" alt="GitHub CI"></a></p>
|
||||
<h1 id="dcat-concatenate-files-to-standard-output">dcat: Concatenate File(s) to Standard Output</h1>
|
||||
<p>A <strong>cat</strong> command-line implemenation in <a href="https://dart.dev/">Dart</a>, inspired by the <a href="https://dart.dev/tutorials/server/cmdline">Write command-line apps sample code</a>.</p>
|
||||
<p>A <strong>cat</strong> command-line implementation in <a href="https://dart.dev/">Dart</a>, inspired by the <a href="https://dart.dev/tutorials/server/cmdline">Write command-line apps sample code</a>.</p>
|
||||
<h2 id="synopsis">Synopsis</h2>
|
||||
<p><strong>dcat</strong> copies each file, or standard input if none are given, to standard output.</p>
|
||||
<h2 id="command-line-usage">Command-Line Usage</h2>
|
||||
|
@ -68,7 +68,7 @@ With no FILE, or when FILE is -, read standard input.
|
|||
-T, --show-tabs display TAB characters as ^I
|
||||
-s, --squeeze-blank suppress repeated empty output lines
|
||||
--version output version information and exit
|
||||
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
|
||||
-v, --show-nonprinting use ^ and U+ notation, except for LFD and TAB
|
||||
|
||||
Examples:
|
||||
dcat f - g Output f's contents, then standard input, then g's contents.
|
||||
|
@ -85,7 +85,8 @@ Examples:
|
|||
<ul>
|
||||
<li>No binary file support.</li>
|
||||
<li>A line is considered terminated by either a <code>CR</code> (carriage return), a <code>LF</code> (line feed), a <code>CR+LF</code> sequence (DOS line ending).</li>
|
||||
<li>The non-printing <code>M-^?</code> notation is always used for unicode characters.</li>
|
||||
<li>A line ending is automatically appended to the last line of any read file.</li>
|
||||
<li>The <code>U+</code> notation is used instead of <code>M-</code> for non-printing characters.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
|
|
@ -83,18 +83,7 @@ Future<String> _parseNonPrinting(String line, bool showTabs) async {
|
|||
} else if (ch == 127) {
|
||||
sb.write('^?');
|
||||
} else {
|
||||
sb.write('M-');
|
||||
if (ch >= 128 + 32) {
|
||||
if (ch < 128 + 127) {
|
||||
sb.writeCharCode(ch - 128);
|
||||
} else {
|
||||
sb.write('^?');
|
||||
}
|
||||
} else {
|
||||
sb
|
||||
..write('^')
|
||||
..writeCharCode(ch - 128 + 64);
|
||||
}
|
||||
sb.write('U+' + ch.toRadixString(16).padLeft(4, '0').toUpperCase());
|
||||
}
|
||||
} else if (ch == 9 && !showTabs) {
|
||||
sb.write('\t');
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import 'dart:io';
|
||||
// Copyright (c) 2021, Erik C. Thauvin. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
import 'package:dcat/dcat.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
@ -129,13 +131,13 @@ void main() {
|
|||
test('Test cat -A', () async {
|
||||
await cat(['test/test.txt'],
|
||||
log: log, showNonPrinting: true, showEnds: true, showTabs: true);
|
||||
expect(log.last, equals('^I^A^B^C^DM-)^?M-^@M-^?\$'));
|
||||
expect(log.last, equals('^I^A^B^C^DU+00A9^?U+0080U+2713\$'));
|
||||
});
|
||||
|
||||
test('Test cat -t', () async {
|
||||
await cat(['test/test.txt'],
|
||||
log: log, showNonPrinting: true, showTabs: true);
|
||||
expect(log.last, equals('^I^A^B^C^DM-)^?M-^@M-^?'));
|
||||
expect(log.last, equals('^I^A^B^C^DU+00A9^?U+0080U+2713'));
|
||||
});
|
||||
|
||||
test('Test cat-Abs', () async {
|
||||
|
@ -156,8 +158,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -v', () async {
|
||||
await cat(['test/test.txt'],
|
||||
log: log, showNonPrinting: true);
|
||||
await cat(['test/test.txt'], log: log, showNonPrinting: true);
|
||||
var hasTab = false;
|
||||
for (final String line in log) {
|
||||
if (line.contains('\t')) {
|
||||
|
@ -166,6 +167,8 @@ void main() {
|
|||
}
|
||||
}
|
||||
expect(hasTab, true, reason: "has real tab");
|
||||
expect(log.last, equals('\t^A^B^C^DU+00A9^?U+0080U+2713'),
|
||||
reason: 'non-printing');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue