diff --git a/BuildCommand.cs b/BuildCommand.cs
index 85c7315..b0a258e 100644
--- a/BuildCommand.cs
+++ b/BuildCommand.cs
@@ -9,6 +9,12 @@ public class BuildCommand : ICommand
[CommandOption("dry", 'd', Description = "Dry run.")]
public bool DryRun { get; set; }
+ [CommandOption("sample", 's', Description = "Generate ASCII sample.")]
+ public bool Sample { get; set; }
+
+ [CommandOption("byte", 'b', Description = "Convert source to byte code.")]
+ public bool ByteCode { get; set; }
+
[CommandOption("verbose", 'v', Description = "Enable verbose output.")]
public bool Verbose { get; set; }
@@ -29,30 +35,40 @@ public class BuildCommand : ICommand
var lines = await File.ReadAllLinesAsync(path);
var source = lines.JoinLines();
+ if (ByteCode)
+ source = source.ToBase64();
+
if (Verbose)
{
await console.Output.WriteLineAsync($"Compiling: {path}");
}
- var counter = source.ExceedsLengthLimit(1259);
-
- if (counter.IsOverLimit)
- await console.Output.WriteAsync(counter.WarningMessage);
+ if (source.ExceedsLengthLimit(1259))
+ await console.Output.WriteAsync($"Warning: source code exceeds {1259:n} characters.");
var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode(source, QRCodeGenerator.ECCLevel.H);
var qrCode = new SvgQRCode(qrCodeData);
+ var asciiCode = new AsciiQRCode(qrCodeData);
+ var qrCodeAsASCII = asciiCode.GetGraphicSmall();
var qrCodeAsSvg = qrCode.GetGraphic(57);
- if (string.IsNullOrEmpty(qrCodeAsSvg))
+ if (string.IsNullOrEmpty(qrCodeAsSvg)
+ || string.IsNullOrEmpty(qrCodeAsASCII))
+ {
+ await console.Output.WriteLineAsync("There was an issue in the rendering process.");
return;
+ }
- await console.Output.WriteLineAsync("Rendered successfully.");
+ if (Sample)
+ await console.Output.WriteLineAsync(qrCodeAsASCII);
if (DryRun)
return;
+ await console.Output.WriteLineAsync("Rendered successfully.");
+
var srcName = Path.GetFileNameWithoutExtension(fileInfo.Name);
File.WriteAllText(Path.Combine(dir, $"{srcName}.svg"), qrCodeAsSvg);
}
diff --git a/RunCommand.cs b/RunCommand.cs
index 45e359b..fc03700 100644
--- a/RunCommand.cs
+++ b/RunCommand.cs
@@ -18,10 +18,14 @@ public class RunCommand : ICommand
public async ValueTask ExecuteAsync(IConsole console)
{
var lines = new string[] { };
+ var fileInfo = new FileInfo(FilePath);
+ var file = fileInfo.FullName;
+ var dir = Path.GetDirectoryName(FilePath);
+ var path = Path.Combine(dir, file);
- if (!System.IO.File.Exists(FilePath))
+ if (!System.IO.File.Exists(path))
{
- await console.Error.WriteLineAsync($"Error: File not found: {FilePath}");
+ await console.Error.WriteLineAsync($"Error: File not found: {file}");
return;
}
@@ -32,7 +36,7 @@ public class RunCommand : ICommand
return;
}
- lines = await System.IO.File.ReadAllLinesAsync(FilePath);
+ lines = await System.IO.File.ReadAllLinesAsync(path);
var source = lines.JoinLines();
if (!string.IsNullOrEmpty(InputPath))
@@ -44,11 +48,11 @@ public class RunCommand : ICommand
if (Verbose)
{
- await console.Output.WriteLineAsync($"Executing: {FilePath}");
- }
+ await console.Output.WriteLineAsync($"Executing: {path}");
- if (source.Length >= 1187)
- await console.Output.WriteAsync("Warning over 1,187 characters.");
+ if (source.ExceedsLengthLimit(1259))
+ await console.Output.WriteAsync($"Warning: source code exceeds {1259:n} characters.");
+ }
Runner.Interpret(lines);
}
diff --git a/StringExtensions.cs b/StringExtensions.cs
index 7a947dd..884c162 100644
--- a/StringExtensions.cs
+++ b/StringExtensions.cs
@@ -29,7 +29,7 @@ public static class StringExtensions
///
/// Array of strings to join.
/// A single string composed of all input lines, separated by newlines.
- public static string JoinLines(this string[] lines)
+ public static string JoinLines(this IEnumerable lines)
{
if (lines is null)
throw new ArgumentNullException(nameof(lines));
@@ -38,15 +38,12 @@ public static class StringExtensions
}
///
- /// Checks if the string exceeds the specified character limit and returns a warning if it does.
+ /// Determines whether the string exceeds the specified character length limit.
///
- /// The text to check.
- /// The maximum allowed character length.
- ///
- /// A tuple containing a boolean flag and an optional warning message.
- /// The flag is true if the limit is exceeded, and false otherwise.
- ///
- public static (bool IsOverLimit, string WarningMessage) ExceedsLengthLimit(this string text, int limit)
+ /// The input string to evaluate.
+ /// The maximum number of allowed characters.
+ /// true if the string's length is greater than or equal to ; otherwise, false.
+ public static bool ExceedsLengthLimit(this string text, int limit)
{
if (text is null)
throw new ArgumentNullException(nameof(text));
@@ -54,8 +51,6 @@ public static class StringExtensions
if (limit < 0)
throw new ArgumentOutOfRangeException(nameof(limit), "Limit must be non-negative.");
- return text.Length >= limit
- ? (true, $"Warning: text is over {limit:n0} characters")
- : (false, string.Empty);
+ return text.Length >= limit;
}
}
diff --git a/sample.svg b/sample.svg
index 04b1ade..0440f02 100644
--- a/sample.svg
+++ b/sample.svg
@@ -1,241 +1,705 @@
-