Skip to content

Commit

Permalink
Revert "gifrenderer encse#1"
Browse files Browse the repository at this point in the history
This reverts commit 38020b0.
  • Loading branch information
encse committed Dec 8, 2019
1 parent fe20884 commit 1600d35
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 190 deletions.
12 changes: 6 additions & 6 deletions 2015/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SplashScreenImpl : AdventOfCode.SplashScreen {

public void Show() {

var color = Console.ForegroundColor;
Write(0xffff66, false, "\n __ ____ _ _ ____ __ _ ____ __ ____ ___ __ ____ ____ \n / _\\ ( \\/ )( ");
Write(0xffff66, false, "\\( __)( ( \\(_ _) / \\( __) / __)/ \\( \\( __) \n/ \\ ) D (\\ \\/ / ) _) / / )( ");
Write(0xffff66, false, " ( O )) _) ( (__( O )) D ( ) _) \n\\_/\\_/(____/ \\__/ (____)\\_)__) (__) \\__/(__) \\");
Expand Down Expand Up @@ -492,14 +493,13 @@ public void Show() {
Write(0xcccccc, false, " | | \n | | ");
Write(0xcccccc, false, " \n _ _ __ ___|___|___ __ _ _ \n ");
Write(0xcccccc, false, " \n");

Terminal.ResetFont();
Console.ForegroundColor = color;
Console.WriteLine();
}

private static void Write(int rgb, bool bold, string text) {
Terminal.SetFont(rgb, bold);
Console.Write(text);
}
private static void Write(int rgb, bool bold, string text){
Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}");
}
}
}
6 changes: 3 additions & 3 deletions 2016/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SplashScreenImpl : AdventOfCode.SplashScreen {

public void Show() {

var color = Console.ForegroundColor;
Write(0xffff66, false, "\n __ ____ _ _ ____ __ _ ____ __ ____ ___ __ ____ ____ \n / _\\ ( \\/ )( ");
Write(0xffff66, false, "\\( __)( ( \\(_ _) / \\( __) / __)/ \\( \\( __) \n/ \\ ) D (\\ \\/ / ) _) / / )( ");
Write(0xffff66, false, " ( O )) _) ( (__( O )) D ( ) _) \n\\_/\\_/(____/ \\__/ (____)\\_)__) (__) \\__/(__) \\");
Expand Down Expand Up @@ -256,13 +257,12 @@ public void Show() {
Write(0x666666, false, " - - - - - - - - \n ==============//|============================== \n ");
Write(0x666666, false, " //| \n \n");

Terminal.ResetFont();
Console.ForegroundColor = color;
Console.WriteLine();
}

private static void Write(int rgb, bool bold, string text){
Terminal.SetFont(rgb, bold);
Console.Write(text);
Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}");
}
}
}
6 changes: 3 additions & 3 deletions 2017/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SplashScreenImpl : AdventOfCode.SplashScreen {

public void Show() {

var color = Console.ForegroundColor;
Write(0xffff66, false, "\n __ ____ _ _ ____ __ _ ____ __ ____ ___ __ ____ ____ \n / _\\ ( \\/ )( ");
Write(0xffff66, false, "\\( __)( ( \\(_ _) / \\( __) / __)/ \\( \\( __) \n/ \\ ) D (\\ \\/ / ) _) / / )( ");
Write(0xffff66, false, " ( O )) _) ( (__( O )) D ( ) _) \n\\_/\\_/(____/ \\__/ (____)\\_)__) (__) \\__/(__) \\");
Expand Down Expand Up @@ -202,13 +203,12 @@ public void Show() {
Write(0xffff66, false, "**\n ");
Write(0xcccccc, false, "'-----------------------------------------------' \n \n");

Terminal.ResetFont();
Console.ForegroundColor = color;
Console.WriteLine();
}

private static void Write(int rgb, bool bold, string text){
Terminal.SetFont(rgb, bold);
Console.Write(text);
Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}");
}
}
}
6 changes: 3 additions & 3 deletions 2018/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SplashScreenImpl : AdventOfCode.SplashScreen {

public void Show() {

var color = Console.ForegroundColor;
Write(0xffff66, false, "\n __ ____ _ _ ____ __ _ ____ __ ____ ___ __ ____ ____ \n / _\\ ( \\/ )( ");
Write(0xffff66, false, "\\( __)( ( \\(_ _) / \\( __) / __)/ \\( \\( __) \n/ \\ ) D (\\ \\/ / ) _) / / )( ");
Write(0xffff66, false, " ( O )) _) ( (__( O )) D ( ) _) \n\\_/\\_/(____/ \\__/ (____)\\_)__) (__) \\__/(__) \\");
Expand Down Expand Up @@ -161,13 +162,12 @@ public void Show() {
Write(0xcccccc, false, "_'~~~~~~~~~~~~~'_________ ___ __ _ _ _ _ 1 ");
Write(0xffff66, false, "**\n \n");

Terminal.ResetFont();
Console.ForegroundColor = color;
Console.WriteLine();
}

private static void Write(int rgb, bool bold, string text){
Terminal.SetFont(rgb, bold);
Console.Write(text);
Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}");
}
}
}
6 changes: 3 additions & 3 deletions 2019/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SplashScreenImpl : AdventOfCode.SplashScreen {

public void Show() {

var color = Console.ForegroundColor;
Write(0xffff66, false, "\n __ ____ _ _ ____ __ _ ____ __ ____ ___ __ ____ ____ \n / _\\ ( \\/ )( ");
Write(0xffff66, false, "\\( __)( ( \\(_ _) / \\( __) / __)/ \\( \\( __) \n/ \\ ) D (\\ \\/ / ) _) / / )( ");
Write(0xffff66, false, " ( O )) _) ( (__( O )) D ( ) _) \n\\_/\\_/(____/ \\__/ (____)\\_)__) (__) \\__/(__) \\");
Expand Down Expand Up @@ -86,13 +87,12 @@ public void Show() {
Write(0xcccccc, false, " 1 ");
Write(0xffff66, false, "**\n \n");

Terminal.ResetFont();
Console.ForegroundColor = color;
Console.WriteLine();
}

private static void Write(int rgb, bool bold, string text){
Terminal.SetFont(rgb, bold);
Console.Write(text);
Console.Write($"\u001b[38;2;{(rgb>>16)&255};{(rgb>>8)&255};{rgb&255}{(bold ? ";1" : "")}m{text}");
}
}
}
138 changes: 18 additions & 120 deletions App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,12 @@
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using SkiaSharp;
using System.IO;
using System.Text;

namespace AdventOfCode {

class RenderToGif : TextWriter {

TextWriter console;

float x;
float y;

SKPaint paint;
SKSurface surface;
string escape = null;
int leftMargin = 3;
public RenderToGif(TextWriter console) {
this.console = console;
surface = SKSurface.Create(new SKImageInfo(1024, 768));

paint = new SKPaint {
TextSize = 12.0f,
IsAntialias = true,
Color = new SKColor(0xbb, 0xbb, 0xbb),
Style = SKPaintStyle.Fill,
Typeface = SKTypeface.FromFamilyName(
"monaco",
SKFontStyleWeight.Normal,
SKFontStyleWidth.Normal,
SKFontStyleSlant.Upright)
};

surface.Canvas.Clear(SKColors.Black);
x = leftMargin;
y = paint.TextSize;
}

public override void Close() {
using var output = File.OpenWrite("x.png");
surface.Snapshot().Encode(SKEncodedImageFormat.Png, 100)
.SaveTo(output);

base.Close();
}

public override void Write(char value) {
if (value == '\u001b') {
escape = "";
return;
}
if (escape != null) {
escape += value;
if (value == 'm') {
Regex regex = new Regex(@"\[38;2;(?<r>\d{1,3});(?<g>\d{1,3});(?<b>\d{1,3})(?<bold>;1)?m");
Match match = regex.Match(escape);
if (match.Success) {
byte r = byte.Parse(match.Groups["r"].Value);
byte g = byte.Parse(match.Groups["g"].Value);
byte b = byte.Parse(match.Groups["b"].Value);

paint.Color = new SKColor(r, g, b);

} else {
Console.Error.WriteLine(escape);
}

escape = null;
}
return;
}

var st = value.ToString();



var qqq = paint.Typeface;
var fontManager = SKFontManager.Default;
paint.Typeface = fontManager.MatchCharacter(paint.Typeface.FamilyName, value);
var text = value.ToString();
surface.Canvas.DrawText(value.ToString(), new SKPoint(x, y), paint);
paint.Typeface = qqq;
x += paint.GetGlyphWidths(text)[0];

if (value == '\n') {
y += paint.FontSpacing;

x = leftMargin;
}

console.Write(value);
}

public override Encoding Encoding {
get { return Encoding.Default; }
}


}
class App {

static void Main(string[] args) {

using var renderToGif = new RenderToGif(Console.Out);
Console.SetOut(renderToGif);

var tsolvers = Assembly.GetEntryAssembly().GetTypes()
.Where(t => t.GetTypeInfo().IsClass && typeof(Solver).IsAssignableFrom(t))
.OrderBy(t => t.FullName)
Expand All @@ -121,26 +21,26 @@ static void Main(string[] args) {
}) ??
Command(args, Args("update", "last"), m => {
var dt = DateTime.Now;
if (dt.Month == 12 && dt.Day >= 1 && dt.Day <= 25) {
if (dt.Month == 12 && dt.Day >=1 && dt.Day <= 25) {
return () => new Updater().Update(dt.Year, dt.Day).Wait();
} else {
throw new Exception("Event is not active. This option works in Dec 1-25 only)");
}
}) ??
Command(args, Args("([0-9]+)/([0-9]+)"), m => {
var year = int.Parse(m[0]);
var day = int.Parse(m[1]);
var tsolversSelected = tsolvers.First(tsolver =>
SolverExtensions.Year(tsolver) == year &&
SolverExtensions.Day(tsolver) == day);
return () => Runner.RunAll(tsolversSelected);
}) ??
var year = int.Parse(m[0]);
var day = int.Parse(m[1]);
var tsolversSelected = tsolvers.First(tsolver =>
SolverExtensions.Year(tsolver) == year &&
SolverExtensions.Day(tsolver) == day);
return () => Runner.RunAll(tsolversSelected);
}) ??
Command(args, Args("[0-9]+"), m => {
var year = int.Parse(m[0]);
var tsolversSelected = tsolvers.Where(tsolver =>
SolverExtensions.Year(tsolver) == year);
return () => Runner.RunAll(tsolversSelected.ToArray());
}) ??
var year = int.Parse(m[0]);
var tsolversSelected = tsolvers.Where(tsolver =>
SolverExtensions.Year(tsolver) == year);
return () => Runner.RunAll(tsolversSelected.ToArray());
}) ??
Command(args, Args("([0-9]+)/last"), m => {
var year = int.Parse(m[0]);
var tsolversSelected = tsolvers.Last(tsolver =>
Expand All @@ -156,7 +56,7 @@ static void Main(string[] args) {
Command(args, Args("all"), m => {
return () => Runner.RunAll(tsolvers);
}) ??
Command(args, Args("last"), m => {
Command(args, Args("last"), m => {
var tsolversSelected = tsolvers.Last();
return () => Runner.RunAll(tsolversSelected);
}) ??
Expand All @@ -165,8 +65,6 @@ static void Main(string[] args) {
});

action();

renderToGif.Close();
}

static Action Command(string[] args, string[] regexes, Func<string[], Action> parse) {
Expand All @@ -178,8 +76,8 @@ static Action Command(string[] args, string[] regexes, Func<string[], Action> pa
return null;
}
try {

return parse(matches.SelectMany(m => m.Groups.Count > 1 ? m.Groups.Cast<Group>().Skip(1).Select(g => g.Value) : new[] { m.Value }).ToArray());
return parse(matches.SelectMany(m => m.Groups.Count > 1 ? m.Groups.Cast<Group>().Skip(1).Select(g => g.Value) : new []{m.Value}).ToArray());
} catch {
return null;
}
Expand All @@ -188,11 +86,11 @@ static Action Command(string[] args, string[] regexes, Func<string[], Action> pa
static string[] Args(params string[] regex) {
return regex;
}

}

public class Usage {
public static string Get() {
public static string Get(){
return $@"
> Usage: dotnet run [arguments]
> Supported arguments:
Expand Down
34 changes: 0 additions & 34 deletions Lib/ConsoleColor.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Lib/Generator/SplashScreenGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public string Generate(Calendar calendar) {
|
| public void Show() {{
|
| var color = Console.ForegroundColor;
| {calendarPrinter.Indent(12)}
| Terminal.ResetFont();
| Console.ForegroundColor = color;
| Console.WriteLine();
| }}
|
| private static void Write(int rgb, bool bold, string text){{
| Terminal.SetFont(rgb, bold);
| Console.Write(text);
| Console.Write($""\u001b[38;2;{{(rgb>>16)&255}};{{(rgb>>8)&255}};{{rgb&255}}{{(bold ? "";1"" : """")}}m{{text}}"");
| }}
| }}
|}}".StripMargin();
Expand Down
Loading

0 comments on commit 1600d35

Please sign in to comment.