drewnoakes / figgle

ASCII banner generation for .NET
Apache License 2.0
412 stars 42 forks source link

Figgle Generator not creating strings. #19

Closed HowardShank closed 5 months ago

HowardShank commented 5 months ago

Hello, I'm trying to use the generator.

Visual Studio 2022 v17.8.4 .Net 8 Project type: library Pacakge: Figgle.Generator v0.5.1

My class code:

Filename: StartupBanners.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Figgle;

namespace MyProject.Lib.Common
{
    [GenerateFiggleTextAttribute("DevelopmentString", "standard", "Development")]
    public partial class StartupBanners
    {
    }
}

When I compile the app I see no partial class code generation. I've tried the following.

Without a StartupBanners.partial`1.cs file

With a StartupBanners.partial`1.cs file

Am I missing something?

Thank you, Howard Shank

drewnoakes commented 5 months ago

Does your StartupBanners class include a Development property?

To see generated files you need to set the EmitCompilerGeneratedFiles property in your project:

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

This will write a file to a location such as obj/Debug/net8.0/generated/MyProject.Lib.Common.

Note that source generators don't write this file by default for performance reasons. The disk IO is avoidable.

HowardShank commented 5 months ago

Thanks for the quick response.

I do not have that in setting configured. I'll test that tomorrow.

So if the string is generated there, how is it usable as a reference in my source elsewhere? Or is the string just something that you go copy and put in your code where you need it?

drewnoakes commented 5 months ago

With the source generator, the output string is computed at compile time, rather than at run time, so it's faster when your program runs (nothing to compute) and you don't need to ship Figgle binaries (which include large font files, embedded).

So your program could resemble this:

[GenerateFiggleTextAttribute("DevelopmentString", "standard", "Development")]
public partial class StartupBanners
{
}

public static class Greeter
{
    public static void PrintDevelopment() => Console.WriteLine(StartupBanners.DevelopmentString);
}
HowardShank commented 5 months ago

Thank you for your help with this. I appreciate it.

How difficult is it to remove all the fonts except one from the runtime package?

drewnoakes commented 5 months ago

It would require some refactoring of the packages I think. You can easily parse a single figlet file using the APIs, but today the core fonts are embedded for convenience.

See #12.

HowardShank commented 5 months ago

Do you mind if I pull the source and give it a shot?

drewnoakes commented 5 months ago

You're welcome to play with it! But if you're hoping to land a change in this repo, I recommend sharing a proposal as to how that might work before submitting a PR. That could save you a bunch of time.

Let's continue the discussion in #12. Looks like the original issue here has been addressed so I'll close this.