Scott Hanselman

It's 2020 and it is time for text mode with Gui.cs

September 1, '20 Comments [23] Posted in Open Source
Sponsored By

Nearly 16 years ago I complained that Windows is completely missing the TextMode boat. It's 2020 and it's TIME FOR TEXT MODE BABY.

I keep bumping into cool utilities made with Gui.cs. Miguel de Icaza made Midnight Commander (not Norton Commander, but evocative of it) and it's a joy.

Head out to an admin command prompt on your Windows 10 machine now and install it (assuming a recent Windows 10 build, you'll have winget):

winget install GNU.MidnightCommander

You run it with "mc" and even better if you've got Windows Terminal blinged out you'll be able bask in the ASCII COATED GLORY:

Midnight Commander is lovely

It works in WSL as well, since there's a Linux version with "apt install mc" so check that out, too!

Do YOU want to make apps like this? While Midnight Commander wasn't made with Gui.cs, it could have been. I spent YEARS making awesome text mode apps with TurboVision. Now we can make text mode apps with C#! There is even a complete Xterm/Vt100 emulator as well in the form of TerminalView.cs.

Is it hard? Nah! Go "dotnet new console" then "dotnet add package Terminal.Gui" and then copy these lines over the ones that are given you in Program.cs, then "dotnet run". Boom.

using Terminal.Gui;

class Demo {
static int Main ()
{
Application.Init ();

var n = MessageBox.Query (50, 7,
"Question", "Do you like console apps?", "Yes", "No");

return n;
}
}

There you go! You should go read about it now!

Do you like Console Apps?

If you want to see all the cool text controls you can use, check out the Terminal.Gui UI Catalog app and its source code.

Sure, it's not that new-fangled HTML, but let me tell you, you see these apps every day. The airport, the DMV, the mechanic, the doctor's office. Apps like these are FAST. It's useful to know that these kinds of apps exist...you'll never know when you might need to get back in to TEXT MODE!


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Exploring the .NET Core library Coravel for Task Scheduling, Caching, Mailing and more

August 27, '20 Comments [17] Posted in DotNetCore | Open Source
Sponsored By

Coravel claims it is a "Near-zero config .NET Core library that makes Task Scheduling, Caching, Queuing, Mailing, Event Broadcasting (and more) a breeze!" A lovely claim, that is, in fact, true! It's open source and on Github at https://github.com/jamesmh/coravel so give Coravel a star!

Coravel is available on NuGet as a package - as are all things  - or you can also install it's helper CLI with a simple dotnet tool install --global coravel-cli. After this, using coravel easy, early, and often is as simple as:

coravel install

A nice teach that makes it easy, the coravel CLI adds the package reference, restores your project, and reminds you to set it up in ConfigureServices() in Startup.cs. A nice example of a thoughtful library that is trying to make onboarding simpler.

The Coravel CLI is also a nice scaffolder to get you started with item templates:

> coravel
Usage: coravel [options] [command]

Options:
-?|-h|--help Show help information

Commands:
event
install
invocable
mail

But what is it?

CoravelWith a somewhat vague name and a list of cool features that may not seem related, you may find yourself wondering WHAT is this and WHY do I need it?

When you start thinking about layering and responsibilities of real production software, you'll note that there are arguably some gaps in the BCL (Base Class Libraries) that .NET makes available, particularly as you move up into the Application Development space.

Scheduled jobs and tasks, simple emailing with Razor Templates, a lightweight event dispatcher, easily queueable background tasks are just some of the higher level primitives you'll find yourself wanting when creating business apps. Coravel collects those buildable elements and allows you to string them together very quickly.

For example, I'll create an "Invocable." Basically just a method that is more 'job-like.' It has business scope and I need to have it invoked later by some schedule or process within my app.

Here I'll register one in my Startup.cs.

services.AddScoped<SendNightlyReportsEmailJob>();

So I need to send a nightly report. That's an invocable thing, and it's also an IMailer because it mails things. Note the injected IMailer in the constructor. All very natural in ASP.NET Core, using Dependency Injection.

public class SendNightlyReportsEmailJob : IInvocable
{
private IMailer _mailer;
public SendNightlyReportsEmailJob(IMailer mailer)
{
this._mailer = mailer;
}

public async Task Invoke()
{
Console.WriteLine("NightlyReportMailable Started....");
await Task.Delay(10000);

// You could grab multiple users from a DB query ;)
var mailable = new NightlyReportMailable(new UserModel
{
Name = "Coravel is lovely!",
Email = "test@test.com"
});
await this._mailer.SendAsync(mailable);
Console.WriteLine($"NightlyReportMailable was sent at {DateTime.UtcNow}.");
}
}

Then I can have this mailed every evening with the Coravel Scheduler:

scheduler.Schedule<SendNightlyReportsEmailJob>().Daily();

But when, right? Easy:

scheduler
.Schedule<SendNightlyReportsEmailJob>()
.DailyAt(1, 30)
.Zoned(TimeZoneInfo.Local);

What if you have a task that needs to happen, but maybe it's either long-running or happening often. You don't want two tasks going at the same time, so PreventOverlapping! Clever.

scheduler
.Schedule<DoAThingOften>()
.EveryMinute()
.PreventOverlapping("DoAThingOften");

And that's just the scheduler. That mail you have to send? You can use Razor Pages to create reach HTML emails! That makes New User Sign Up, or Completed Order very easy to create. All self-contained in your app. I dig it.

Finally note that there's Pro paid version of Coravel that gives you a very professional UI for Jobs and Invocables, and allows you to visually configure your back-end job schedules. A nice way to support open source - especially when you start using it and really depending on it - is to explore very reasonable Pro licenses like those that Pro Coravel has. Impressive stuff, truly.

*I have no relationship with Coravel the project or the Pro licenses, I'm just a fan.


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Docker 101 and How do containers work?

August 25, '20 Comments [7] Posted in Docker | Open Source
Sponsored By

Everyone is using containers and talking about containers. Except those for whom it hasn't "clicked." Obvious to some and unendingly frustrating to others, containers are changing how we build and deploy software. As part of my ongoing 'Computer Stuff They Didn't Teach You' Series on YouTube, I explain Containers and Docker in about 30 min, with lots of demos and slow, deliberate examples.

Please do check it out and subscribe as I'll be doing Kubernetes next.

I hope you enjoy it! Please subscribe to my YouTube and explore my playlists and recent videos!


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Connect to a device over Serial COM Port on Windows 10 with WSL1 TTY devices with Windows Terminal and minicom

August 18, '20 Comments [7] Posted in Hardware | Win10
Sponsored By

imageI hope that this blog post is found and helps someone. I wasn't sure what to title it. Hope Google Juice got you here!

Read this whole post, there's a lot initially but there's really just two or three small pieces. It'll be worth it because you'll be able to have a nice one click menu and drop directly into a serial port terminal on Windows in the Windows Terminal

Often when you're doing embedded systems development you'll want to monitor or talk to the COM/Serial Port just like you SSH into remote system. Folks ask questions like "How to connect to a serial port as simple as using SSH?"

On Linux you'll use things like "screen /dev/ttyS0" for COM0. With Windows, however, the historical guidance has always been to use Putty. It'll work but it's somewhat old, quirky, and it doesn't integrate well with the Windows Terminal and a more modern workflow.

Say I have a small embedded microcontroller device that talks over a COM Port (usually via a USB->COM bridge) like an Arduino.

Let's assume this device talks to the COM port as if it were a terminal and it's outputting stuff I want to see. I'll use this great little CLI example app for Arduino from Mads Aasvik to simulate such a device.

Here's what it looks like under Arduino's Serial Monitor, for example. This is a Windows app doing serial communication with its own interface wrapping around it. I want to do this at a command line, and bonus points if it's in Windows Terminal.

Serial port monitor in Arduino talking to a Command Line Interface

Setup WSL1

If you have Windows 10 you can the Windows Subsystem for Linux quickly with this command at a Admin prompt:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Then go to the Windows Store and get any small Linux. Ubuntu or Kali will do for our purposes. Run it and set your user and password.  (I tried Alpine but it still has issues with screen and /dev/null/utmp)

NOTE: If you are using WSL2 and have set it as default, run wsl --list -v and ensure that your new distro is using WSL1 as only WSL1 will let us talk to the COM Ports. You can change it to WSL1 with "wsl --set-version DISTRONAME 1" from any command prompt.

To test this out now, run your new distro from any command line prompt like this. Add the "screen" app with sudo apt update" and "sudo app install screen".

You can see here that my Arduino serial device is on COM4. On Linux that device is /dev/ttyS4

Arduino is on COM4

That means that I should be able to talk it from any WSL1 Linux Distro on Windows like "screen /dev/ttyS4 9600" where 9600 is the speed/baud rate.

> wsl --list -v
NAME STATE VERSION
* Ubuntu-18.04 Stopped 2
kali-linux Stopped 1
Ubuntu-20.04 Stopped 2
WLinux Stopped 2

Get Minicom on your WSL1 distro

Screen is somewhat persnickety for Serial Port work so try Minicom. Minicom is a nice little text com program. Install with apt install minicom and run for the first time with "sudo minicom -s" to set your default. Note I've change the default port from /dev/modem to /dev/ttyS4 and the speed, in my case, to 9600.

Setting up Minicom on WSL

Then I hit enter and save settings as the dft (default) in minicom. You can also turn on Local Echo with "Ctrl-A E" and toggle it if needed. Now I can talk to my Arudino with minicom.

Ensure dialout permissions to talk to the COM port

NOTE: If you get "cannon open /dev/ttyS4: Permission denied, you may need to add your user to the dialout group. This way we don't need to sudo and get no prompt when running minicom!

> wsl -d kali-linux minicom
minicom: cannot open /dev/ttyS4: Permission denied
> wsl -d kali-linux
$ groups scott
scott : scott adm cdrom sudo dip plugdev
$ sudo gpasswd --add scott dialout
[sudo] password for scott:
Adding user scott to group dialout

I can now run minicom on my configured COM port 4 (/dev/ttyS4) with wsl -d DISTRONAME minicom without sudo.

Here I'm talking to that Arduino program. This embedded app doesn't need to me hit enter after I type, so remember your own embedded devices will vary.

Serial port shell with WSL and Minicom

Make a nice menu

Bonus points, now I'll add a menu item for Minicom by changing my Windows Terminal settings AND I'll get more points for adding a nice serial port icon!

Cool icon in Windows Terminal for Serial Ports

I hit settings and add a new profile like this at the top under profiles in the "list." Again, your distro name will be different.

{
"guid": "{61c54bbd-a2c6-5271-96e7-009a87fa45cf}",
"name": "Minicom on Serial COM4",
"hidden": false,
"commandline": "wsl -d kali-linux minicom",
"startingDirectory": "%USERPROFILE%",
"icon": "C:/Users/scott/Desktop/serial_port_icon_138204.png"
},

To review:

  • Use a WSL1 distro
  • Install minicom, run with minicom -s once to make settings
    • Make sure you are using the right /dev/ttyS0 device for your situation
    • Ensure your flow control, baud, etc are all correct in minicom
    • Add your user to the dialout group so you don't have to sudo minicom
  • Make a menu item in Windows Terminal
    • or run minicom manually in your WSL1 instance whenever you like

Hope this helps!


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

What is .NET? How does it work? Is it a language or a Platform?

August 13, '20 Comments [6] Posted in DotNetCore
Sponsored By

If you want to learn about .NET, I worked with my friends to make a whole series of videos at https://dot.net/videos that go into lots of details about C# the language, .NET the platform, ASP.NET the Web Platform and all the cool stuff you can make with it. There are a ton of free .NET videos and tutorials for you to explore (like 100, and they are easy, short, and binge worthy!)

But if you just have a few minutes and you're learning about .NET and just want to know WTF is .NET?!? Check out my YouTube. I'll explain the whole thing is a tight 20 min, from C# to F#, NuGet, and more. I'll show code, draw on the screen, and by the end you'll have a good sense of where .NET fits into the world versus things like Java, Node, Rust, Go, and more.

I hope you enjoy it! Please subscribe to my YouTube and explore my playlists and recent videos!


Sponsor: Have you tried developing in Rider yet? This fast and feature-rich cross-platform IDE improves your code for .NET, ASP.NET, .NET Core, Xamarin, and Unity applications on Windows, Mac, and Linux.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.