From 66d4cbc9ec8874e5d8c8daeca01ffb64d0072207 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Wed, 7 May 2025 11:40:52 -0400 Subject: [PATCH] QR Code renderer - Will output QR Code as SVG - Temporarily removed Base64 feature - Changed install.sh to focus on platform - Makefile can now build and package for macOS or Linux separately --- BuildCommand.cs | 50 ++++++++++ CompileCommand.cs | 32 ------ GlobalUsing.cs | 1 + Glyph.csproj | 3 +- Makefile | 4 + Program.cs | 2 +- README.md | 6 +- RunCommand.cs | 4 + ScriptHelper.cs | 7 ++ install.sh | 3 +- sample.glif | 2 + sample.svg | 241 ++++++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 318 insertions(+), 37 deletions(-) create mode 100644 BuildCommand.cs delete mode 100644 CompileCommand.cs create mode 100644 sample.svg diff --git a/BuildCommand.cs b/BuildCommand.cs new file mode 100644 index 0000000..ad752ac --- /dev/null +++ b/BuildCommand.cs @@ -0,0 +1,50 @@ +namespace Glyph; + +[Command("build", Description = "Build Glyph program.")] +public class BuildCommand : ICommand +{ + [CommandParameter(0, Name = "file", Description = "Path to the Glyph source file.")] + public string FilePath { get; set; } + + [CommandOption("dry", 'd', Description = "Dry run.")] + public bool DryRun { get; set; } + + [CommandOption("verbose", 'v', Description = "Enable verbose output.")] + public bool Verbose { get; set; } + + public async ValueTask ExecuteAsync(IConsole console) + { + + var file = new FileInfo(FilePath); + + if (!File.Exists(FilePath)) + { + await console.Error.WriteLineAsync($"Error: File not found: {FilePath}"); + return; + } + + var lines = await File.ReadAllLinesAsync(FilePath); + var source = ScriptHelper.LinesToString(lines); + + if (Verbose) + { + await console.Output.WriteLineAsync($"Compiling: {FilePath}"); + } + + var counter = ScriptHelper.CharacterCounter(1259, source); + + if (counter.checker) + await console.Output.WriteAsync(counter.output); + + if (DryRun) + return; + + var qrGenerator = new QRCodeGenerator(); + var qrCodeData = qrGenerator.CreateQrCode(source, QRCodeGenerator.ECCLevel.H); + var qrCode = new SvgQRCode(qrCodeData); + var qrCodeAsSvg = qrCode.GetGraphic(57); + var path = Path.GetDirectoryName(FilePath); + var srcName = Path.GetFileNameWithoutExtension(file.Name); + File.WriteAllText(Path.Combine(path, $"{srcName}.svg"), qrCodeAsSvg); + } +} diff --git a/CompileCommand.cs b/CompileCommand.cs deleted file mode 100644 index 5952197..0000000 --- a/CompileCommand.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Glyph; - -[Command("build", Description = "Build Glyph program.")] -public class CompileCommand : ICommand -{ - [CommandParameter(0, Name = "file", Description = "Path to the Glyph source file.")] - public string FilePath { get; set; } - - [CommandOption("verbose", 'v', Description = "Enable verbose output.")] - public bool Verbose { get; set; } - - public async ValueTask ExecuteAsync(IConsole console) - { - - if (!System.IO.File.Exists(FilePath)) - { - await console.Error.WriteLineAsync($"Error: File not found: {FilePath}"); - return; - } - - var lines = await System.IO.File.ReadAllLinesAsync(FilePath); - var source = ScriptHelper.LinesToString(lines); - - if (Verbose) - { - await console.Output.WriteLineAsync($"Compiling: {FilePath}"); - } - - var binary = ScriptHelper.EncodeTo64(source); - File.WriteAllText(Path.Combine(Path.GetDirectoryName(FilePath), "output.glyb"), binary); - } -} diff --git a/GlobalUsing.cs b/GlobalUsing.cs index 20fb182..45c2ce0 100644 --- a/GlobalUsing.cs +++ b/GlobalUsing.cs @@ -1,4 +1,5 @@ global using Glyph; +global using QRCoder; global using CliFx; global using CliFx.Attributes; global using CliFx.Infrastructure; diff --git a/Glyph.csproj b/Glyph.csproj index 7881031..fcbcbff 100644 --- a/Glyph.csproj +++ b/Glyph.csproj @@ -6,12 +6,13 @@ enable glyph enable - 0.1.106 + 0.2.100 + diff --git a/Makefile b/Makefile index 5aba551..589bda3 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ APPIMAGE_DIR = ./AppDir all: build-linux build-mac package-linux package-mac +linux: build-linux package-linux + +mac: build-mac package-mac + clean: rm -rf bin obj $(OUTPUT_DIR) diff --git a/Program.cs b/Program.cs index 140f4c6..bb02a60 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,6 @@ await new CliApplicationBuilder() .AddCommand() - .AddCommand() + .AddCommand() .SetExecutableName("Glyph") .Build() .RunAsync(); diff --git a/README.md b/README.md index 20f1256..1ebe761 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ Glyph is a human-readable esoteric programming language that is designed to fit - [ ] Compiler - - [ ] QR Code + - [x] QR Code - - [x] Base64 + - [ ] Base64 ## ๐Ÿงพ Program Structure @@ -48,6 +48,8 @@ verb subject object [modifier] - .NET 8.0 - Dynamic Expresso for interpreter +- CILx for command line +- QRCoder for renderer ## ๐Ÿ—“๏ธ Update Cycle diff --git a/RunCommand.cs b/RunCommand.cs index 509b854..f75567d 100644 --- a/RunCommand.cs +++ b/RunCommand.cs @@ -33,6 +33,7 @@ public class RunCommand : ICommand } lines = await System.IO.File.ReadAllLinesAsync(FilePath); + var source = ScriptHelper.LinesToString(lines); if (!string.IsNullOrEmpty(InputPath)) { @@ -46,6 +47,9 @@ public class RunCommand : ICommand await console.Output.WriteLineAsync($"Executing: {FilePath}"); } + if (source.Length >= 1187) + await console.Output.WriteAsync("Warning over 1,187 characters."); + Runner.Interpret(lines); } } diff --git a/ScriptHelper.cs b/ScriptHelper.cs index 1991583..8c049bc 100644 --- a/ScriptHelper.cs +++ b/ScriptHelper.cs @@ -25,4 +25,11 @@ public static class ScriptHelper /// The resulting string. static public string LinesToString(string[] lines) => string.Join(Environment.NewLine, lines); + static public (bool checker, string output) CharacterCounter(int limit, string text) + { + if (text.Length >= limit) + return (true, $"Warning source is over {limit:n} characters"); + + return (false, string.Empty); + } } diff --git a/install.sh b/install.sh index 0cb36bd..e9b7936 100755 --- a/install.sh +++ b/install.sh @@ -5,7 +5,8 @@ set -e -SOURCE_BIN="$1" +PLATFORM="$1" +SOURCE_BIN="./dist/glyph-$PLATFORM/glyph" INSTALL_DIR="$HOME/.local/bin" TARGET="$INSTALL_DIR/glyph" diff --git a/sample.glif b/sample.glif index 3146d31..fa2f490 100644 --- a/sample.glif +++ b/sample.glif @@ -1,4 +1,6 @@ set x 5 mul x 2 say x +inp y +say y end diff --git a/sample.svg b/sample.svg new file mode 100644 index 0000000..04b1ade --- /dev/null +++ b/sample.svg @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file