Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use console library inside own Module #115

Closed
michalss opened this issue Jun 13, 2024 · 2 comments
Closed

Use console library inside own Module #115

michalss opened this issue Jun 13, 2024 · 2 comments
Labels

Comments

@michalss
Copy link

michalss commented Jun 13, 2024

HI @Rohansi , me again :)

Can you please help me out once again. Is there a way to use build in lib ConsoleOutput in my own modules? I would like to monitor long proccess and print out some logs during the process.

Thank you

@Rohansi
Copy link
Owner

Rohansi commented Jun 13, 2024

The print and printLn functions are already available to all Mond modules.

Do you maybe mean you want to call the same functions from your own C# library? There's no way to get one IMondLibrary from another but you can configure your library to use the same TextWriter as the ConsoleOutputLibrary.

state.Libraries.Configure(libs =>
{
    var console = libs.Get<ConsoleOutputLibrary>();
    console.Out = System.Console.Out; // can change to something else

    var otherLibrary = libs.Get<MyCustomLibrary>();
    otherLibrary.Out = console.Out; // pass your library the same output location
});

Then you can use the same TextWriter from your C# library code.

Refer to ConsoleOutputLibrary and the ConsoleOutput module for how to set this configuration up.

@michalss
Copy link
Author

michalss commented Jun 13, 2024

thx i sort this out..

            state.Libraries.Configure(libs =>
            {
                var consoleOutput = libs.Get<ConsoleOutputLibrary>();
                var ioModule = libs.Get<IOMoudule>();

                ioModule.Out = new StringWriter(sb)
                {
                    NewLine = "\n"
                };

                consoleOutput.Out = new StringWriter(sb)
                {
                    NewLine = "\n"
                };
            });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants