-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
27 changed files
with
708 additions
and
62 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,96 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
import 'package:rfw_txt/src/rfw2txt.dart'; | ||
|
||
ArgParser buildParser() { | ||
return ArgParser() | ||
..addFlag( | ||
'help', | ||
abbr: 'h', | ||
negatable: false, | ||
help: 'Print this usage information.', | ||
) | ||
..addFlag( | ||
'verbose', | ||
negatable: false, | ||
help: 'Show additional command output.', | ||
) | ||
..addFlag( | ||
'version', | ||
abbr: 'v', | ||
negatable: false, | ||
help: 'Print the tool version.', | ||
) | ||
..addOption('output', abbr: 'o', help: 'Output path.'); | ||
} | ||
|
||
void printUsage(ArgParser argParser) { | ||
print('Usage: rfw2txt <flags> [arguments]'); | ||
print(argParser.usage); | ||
} | ||
|
||
void main(List<String> arguments) { | ||
final ArgParser argParser = buildParser(); | ||
try { | ||
final ArgResults results = argParser.parse(arguments); | ||
bool verbose = false; | ||
|
||
// Process the parsed arguments. | ||
if (results.wasParsed('help')) { | ||
printUsage(argParser); | ||
return; | ||
} | ||
if (results.wasParsed('version')) { | ||
String version = '0.0.1'; | ||
try { | ||
File pubspecFile = File('pubspec.yaml'); | ||
version = loadYaml(pubspecFile.readAsStringSync())['version']; | ||
} catch (e) { | ||
print(e); | ||
} | ||
|
||
print('rfw2txt version: $version'); | ||
return; | ||
} | ||
if (results.wasParsed('verbose')) { | ||
verbose = true; | ||
} | ||
|
||
if (verbose) { | ||
print('[VERBOSE] All arguments: ${results.arguments}'); | ||
} | ||
|
||
String outputPath = ''; | ||
if (results.wasParsed('output')) { | ||
outputPath = results['output'] as String; | ||
} | ||
|
||
if (results.arguments.isEmpty) { | ||
print('No rfw path provided.'); | ||
printUsage(argParser); | ||
return; | ||
} | ||
|
||
// check if file exists | ||
String rfwPath = results.arguments[0]; | ||
File rfwFile = File(rfwPath); | ||
if (!rfwFile.existsSync()) { | ||
print('File not found: $rfwPath'); | ||
return; | ||
} | ||
|
||
if (outputPath.isEmpty) { | ||
outputPath = '${basenameWithoutExtension(rfwPath)}.rfwtxt'; | ||
} | ||
File outputFile = File(outputPath); | ||
outputFile.writeAsStringSync(rfw2txt(rfwFile.readAsBytesSync())); | ||
} on FormatException catch (e) { | ||
// Print usage information if an invalid argument was provided. | ||
print(e.message); | ||
printUsage(argParser); | ||
} | ||
} |
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
Binary file not shown.
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,14 @@ | ||
import core.widgets; | ||
import core.material; | ||
|
||
widget hello = Scaffold( | ||
appBar: AppBar(title: Text(text: "Hello Demo")), | ||
body: Container( | ||
height: 100, | ||
color: 0xFF00FF00, | ||
child: Center( | ||
child: Text(text: ["Hello, ", data.greet.name, '!'], textDirection: "ltr", style: { | ||
color: 0xFFFF0000 | ||
}), | ||
), | ||
)); |
Binary file not shown.
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,61 @@ | ||
import core.widgets; | ||
import core.material; | ||
|
||
widget Empty = Container(); | ||
|
||
widget Counter = Container( | ||
color: 0xFF66AACC, | ||
child: Center( | ||
child: Button( | ||
child: Padding( | ||
padding: [ 20.0 ], | ||
child: Text(text: data.counter, style: { | ||
fontSize: 56.0, | ||
color: 0xFF000000, | ||
}), | ||
), | ||
onPressed: event "increment" { }, | ||
), | ||
), | ||
); | ||
|
||
widget Button { down: false } = GestureDetector( | ||
onTap: args.onPressed, | ||
onTapDown: set state.down = true, | ||
onTapUp: set state.down = false, | ||
onTapCancel: set state.down = false, | ||
child: Container( | ||
duration: 50, | ||
margin: switch state.down { | ||
false: [ 0.0, 0.0, 2.0, 2.0 ], | ||
true: [ 2.0, 2.0, 0.0, 0.0 ], | ||
}, | ||
padding: [ 12.0, 8.0 ], | ||
decoration: { | ||
type: "shape", | ||
shape: { | ||
type: "stadium", | ||
side: { width: 1.0 }, | ||
}, | ||
gradient: { | ||
type: "linear", | ||
begin: { x: -0.5, y: -0.25 }, | ||
end: { x: 0.0, y: 0.5 }, | ||
colors: [ 0xFFFFFF99, 0xFFEEDD00 ], | ||
stops: [ 0.0, 1.0 ], | ||
tileMode: "mirror", | ||
}, | ||
shadows: switch state.down { | ||
false: [ { blurRadius: 4.0, spreadRadius: 0.5, offset: { x: 1.0, y: 1.0, } } ], | ||
default: [], | ||
}, | ||
}, | ||
child: DefaultTextStyle( | ||
style: { | ||
color: 0xFF000000, | ||
fontSize: 32.0, | ||
}, | ||
child: args.child, | ||
), | ||
), | ||
); |
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,3 @@ | ||
library rfw_txt; | ||
|
||
export 'src/txt2rfw.dart'; |
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,25 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:rfw/formats.dart'; | ||
|
||
import 'rwl2json.dart'; | ||
import 'rwl2txt.dart'; | ||
|
||
// Parse .rfw to .rfwtxt | ||
String rfw2txt(Uint8List bytes) { | ||
RemoteWidgetLibrary rwl = decodeLibraryBlob(bytes); | ||
String output = rwl2txt(rwl); | ||
if (ListEquality() | ||
.equals(bytes, encodeLibraryBlob(parseLibraryFile(output))) == | ||
false) { | ||
throw Exception('rfw2txt failed'); | ||
} | ||
return output; | ||
} | ||
|
||
// Parse .rfw to json | ||
Map<String, dynamic> rfw2json(Uint8List bytes) { | ||
RemoteWidgetLibrary rwl = decodeLibraryBlob(bytes); | ||
return rwl2json(rwl); | ||
} |
Oops, something went wrong.