-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 762e659
Showing
9 changed files
with
1,176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dart.lineLength": 80, | ||
"[dart]": { | ||
"editor.rulers": [ | ||
80 | ||
], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
### 0.0.1 | ||
- Initial version. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: write this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: package:lints/recommended.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// ignore_for_file: invalid_use_of_protected_member | ||
|
||
import 'dart:convert'; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:barcode/barcode.dart'; | ||
import 'package:barcode/src/barcode_1d.dart'; | ||
import 'package:barcode/src/qrcode.dart'; | ||
import 'package:quiver/iterables.dart'; | ||
|
||
final _parser = ArgParser() | ||
..addFlag( | ||
'help', | ||
abbr: 'h', | ||
negatable: false, | ||
help: 'Shows this help message.', | ||
) | ||
..addFlag( | ||
'version', | ||
abbr: 'v', | ||
negatable: false, | ||
help: 'Shows the current version.', | ||
) | ||
..addOption( | ||
'type', | ||
abbr: 't', | ||
defaultsTo: '128', | ||
help: 'Options: 128, qr.', | ||
) | ||
..addOption( | ||
'height', | ||
abbr: 'y', | ||
defaultsTo: '8', | ||
help: 'Height for 1D barcodes.', | ||
); | ||
|
||
void main(List<String> aargs) { | ||
final args = _parser.parse(aargs); | ||
if (args['help'] as bool) { | ||
print(_parser.usage); | ||
return; | ||
} | ||
if (args['version'] as bool) { | ||
print('barcoder 0.0.1'); | ||
return; | ||
} | ||
final data = args.rest.first; | ||
final type = args['type'] as String; | ||
final height = int.parse(args['height']); | ||
final output = switch (type) { | ||
'128' => _barcode128(data, height: height), | ||
'qr' => _qr(data), | ||
_ => 'Unknown type: $type', | ||
}; | ||
print(output); | ||
} | ||
|
||
String _pixel(bool pixel) => pixel ? '█' : ' '; | ||
|
||
String _barcode128(String data, {int height = 8}) { | ||
final line = | ||
(Barcode.code128() as Barcode1D).convert(data).map(_pixel).join(); | ||
return List.filled(height, line).join('\n'); | ||
} | ||
|
||
String _qr(String data) { | ||
final qr = | ||
(Barcode.qrCode() as BarcodeQR).convert(utf8.encoder.convert(data)); | ||
final rows = partition(qr.pixels, qr.width); | ||
final pixels = [ | ||
for (final row in rows) row.map((e) => e ? '█' : ' ').join(), | ||
]; | ||
return pixels.join('\n'); | ||
} |
Oops, something went wrong.