Skip to content

Commit 762e659

Browse files
committed
initial commit
0 parents  commit 762e659

File tree

9 files changed

+1176
-0
lines changed

9 files changed

+1176
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
4+
5+
.DS_Store

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dart.lineLength": 80,
3+
"[dart]": {
4+
"editor.rulers": [
5+
80
6+
],
7+
}
8+
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### 0.0.1
2+
- Initial version.

LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: write this.

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml

bin/barcoder.dart

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// ignore_for_file: invalid_use_of_protected_member
2+
3+
import 'dart:convert';
4+
5+
import 'package:args/args.dart';
6+
import 'package:barcode/barcode.dart';
7+
import 'package:barcode/src/barcode_1d.dart';
8+
import 'package:barcode/src/qrcode.dart';
9+
import 'package:quiver/iterables.dart';
10+
11+
final _parser = ArgParser()
12+
..addFlag(
13+
'help',
14+
abbr: 'h',
15+
negatable: false,
16+
help: 'Shows this help message.',
17+
)
18+
..addFlag(
19+
'version',
20+
abbr: 'v',
21+
negatable: false,
22+
help: 'Shows the current version.',
23+
)
24+
..addOption(
25+
'type',
26+
abbr: 't',
27+
defaultsTo: '128',
28+
help: 'Options: 128, qr.',
29+
)
30+
..addOption(
31+
'height',
32+
abbr: 'y',
33+
defaultsTo: '8',
34+
help: 'Height for 1D barcodes.',
35+
);
36+
37+
void main(List<String> aargs) {
38+
final args = _parser.parse(aargs);
39+
if (args['help'] as bool) {
40+
print(_parser.usage);
41+
return;
42+
}
43+
if (args['version'] as bool) {
44+
print('barcoder 0.0.1');
45+
return;
46+
}
47+
final data = args.rest.first;
48+
final type = args['type'] as String;
49+
final height = int.parse(args['height']);
50+
final output = switch (type) {
51+
'128' => _barcode128(data, height: height),
52+
'qr' => _qr(data),
53+
_ => 'Unknown type: $type',
54+
};
55+
print(output);
56+
}
57+
58+
String _pixel(bool pixel) => pixel ? '█' : ' ';
59+
60+
String _barcode128(String data, {int height = 8}) {
61+
final line =
62+
(Barcode.code128() as Barcode1D).convert(data).map(_pixel).join();
63+
return List.filled(height, line).join('\n');
64+
}
65+
66+
String _qr(String data) {
67+
final qr =
68+
(Barcode.qrCode() as BarcodeQR).convert(utf8.encoder.convert(data));
69+
final rows = partition(qr.pixels, qr.width);
70+
final pixels = [
71+
for (final row in rows) row.map((e) => e ? '█' : ' ').join(),
72+
];
73+
return pixels.join('\n');
74+
}

0 commit comments

Comments
 (0)