{"id":9708,"date":"2022-11-06T21:31:06","date_gmt":"2022-11-06T21:31:06","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9708"},"modified":"2022-11-06T21:31:06","modified_gmt":"2022-11-06T21:31:06","slug":"nanoframework-console-using-the-m5core2","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/nanoframework-console-using-the-m5core2\/","title":{"rendered":"nanoFramework Console (using the M5Core2)"},"content":{"rendered":"<p>The nanoFramework comes with a Console class, for the M5Stack this is in the namespace <em>nanoFramework.M5Stack.Console<\/em><\/p>\n<p>Before we uses the Console we need to initialize the screen, this essentially creates the screen buffer and assigns a font from the application&#8217;s resource. As I&#8217;m testing this stuff on the M5Core2, the code looks like this. <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nM5Core2.InitializeScreen();\r\n<\/pre>\n<p>Now we can simply use the Console like we would for a Console application on Windows.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ clear the console\r\nConsole.Clear();\r\n\r\n\/\/ output some test\r\nConsole.WriteLine(&quot;Some Text&quot;);\r\n\r\n\/\/ change the foreground colour\r\nConsole.ForegroundColor = Color.Red;\r\nConsole.WriteLine(&quot;Some Red Text&quot;);\r\n\r\n\/\/ change foreground and background colours\r\nConsole.BackgroundColor = Color.Yellow;\r\nConsole.ForegroundColor = Color.White;\r\nConsole.WriteLine(&quot;Some Green Text on Yellow Background&quot;);\r\n<\/pre>\n<p>We can also change the font by supplying a font resource, the default included is <em>consolas_regular_16.tinyfnt<\/em>. We would add the font as a resource and create the font like this<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nConsole.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16);\r\n<\/pre>\n<p>We can move the cursor around using<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nConsole.CursorLeft = 3;\r\nConsole.CursorTop = 5;\r\n<\/pre>\n<p>We can also get the height and width of our window via the Console using<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nConsole.WriteLine($&quot;Height: {Console.WindowHeight}, Width: {Console.WindowWidth}&quot;);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s resource. As I&#8217;m testing this stuff on the M5Core2, the code looks like this. M5Core2.InitializeScreen(); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[89,345,341],"tags":[],"class_list":["post-9708","post","type-post","status-publish","format-standard","hentry","category-electronics","category-m5core2","category-nanoframework"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=9708"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9708\/revisions"}],"predecessor-version":[{"id":9711,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9708\/revisions\/9711"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}