nanoFramework Console (using the M5Core2)

The nanoFramework comes with a Console class, for the M5Stack this is in the namespace nanoFramework.M5Stack.Console

Before we uses the Console we need to initialize the screen, this essentially creates the screen buffer and assigns a font from the application’s resource. As I’m testing this stuff on the M5Core2, the code looks like this.

M5Core2.InitializeScreen();

Now we can simply use the Console like we would for a Console application on Windows.

// clear the console
Console.Clear();

// output some test
Console.WriteLine("Some Text");

// change the foreground colour
Console.ForegroundColor = Color.Red;
Console.WriteLine("Some Red Text");

// change foreground and background colours
Console.BackgroundColor = Color.Yellow;
Console.ForegroundColor = Color.White;
Console.WriteLine("Some Green Text on Yellow Background");

We can also change the font by supplying a font resource, the default included is consolas_regular_16.tinyfnt. We would add the font as a resource and create the font like this

Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16);

We can move the cursor around using

Console.CursorLeft = 3;
Console.CursorTop = 5;

We can also get the height and width of our window via the Console using

Console.WriteLine($"Height: {Console.WindowHeight}, Width: {Console.WindowWidth}");