Skip to content

Commit

Permalink
Final fixes before publishing
Browse files Browse the repository at this point in the history
Fixed some aditional issues before publishing and created a separated copy of the README.md file for NuGet.
  • Loading branch information
Leonardo Pessoa committed Aug 23, 2022
1 parent 2a9420c commit 69340c7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Lib/ConsoleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Lmpessoa.Mainframe;

internal sealed class ConsoleWrapper {

private const int CONSOLE_GRAY = (int) ConsoleColor.DarkGray;
private const int MIN_WIDTH = 80;
private const int MIN_HEIGHT = 24;

Expand All @@ -49,7 +50,7 @@ internal ConsoleWrapper(IConsole console) {
_defaultBackground = Console.BackgroundColor;
_highlightBackground = _defaultBackground;
_defaultForeground = Console.ForegroundColor;
_fieldForeground = _defaultForeground + (_defaultForeground > ConsoleColor.Gray ? -8 : 8);
_fieldForeground = _defaultForeground + (_defaultForeground > ConsoleColor.Gray ? -CONSOLE_GRAY : CONSOLE_GRAY);
_highlightForeground = _fieldForeground;
}

Expand Down Expand Up @@ -119,7 +120,7 @@ internal void SaveState(bool enforceSize) {
internal void UseActiveFieldBackground() {
Console.ResetColor();
ConsoleColor bg = _defaultBackground;
bg += (bg > ConsoleColor.Gray ? -8 : 8);
bg += (bg > ConsoleColor.Gray ? -CONSOLE_GRAY : CONSOLE_GRAY);
_activeBackground = bg;
}

Expand Down
2 changes: 1 addition & 1 deletion Lib/Fields/FieldBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal static FieldBase Create(Map parent, int left, int top, string arg) {
case "TXT":
case "PWD":
return args[0] == '['
? new TextField(name, parent, left, top, int.Parse(args[1..^1]), type == "PWD")
? new TextField(name, parent, left, top, int.Parse(args[1..^1], CultureInfo.InvariantCulture), type == "PWD")
: type == "PWD" ? new TextField(name, parent, left, top, args.Length - 2, true)
: new TextField(name, parent, left, top, args[1..^1]);
case "CHK":
Expand Down
3 changes: 2 additions & 1 deletion Lib/Fields/InputFieldBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* SOFTWARE.
*/

using System.Globalization;
using System.Text;

namespace Lmpessoa.Mainframe.Fields;
Expand Down Expand Up @@ -96,7 +97,7 @@ internal override void Redraw(ConsoleWrapper console, bool active) {
}
}
if (Application.PreserveValues != PreserveValuesLevel.Display && !active) {
fvalue = fvalue.ToUpper();
fvalue = fvalue.ToUpper(CultureInfo.CurrentUICulture);
}
console.WriteField(fvalue[0..Math.Min(fvalue.Length, Width)], fstate, fstatus);
IsDirty = false;
Expand Down
17 changes: 12 additions & 5 deletions Lib/Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@
<Nullable>enable</Nullable>
<AssemblyName>Lmpessoa.Mainframe</AssemblyName>
<RootNamespace>Lmpessoa.Mainframe</RootNamespace>
<PackageProjectUrl>https://www.github.com/Lmpessoa/Terminal</PackageProjectUrl>
<RepositoryUrl>https://www.github.com/Lmpessoa/Terminal</RepositoryUrl>
<PackageTags>console;terminal;console-app;terminal-app;</PackageTags>
<PackageReadmeFile></PackageReadmeFile>
<PackageProjectUrl>https://www.github.com/Lmpessoa/Mainframe</PackageProjectUrl>
<RepositoryUrl>https://www.github.com/Lmpessoa/Mainframe</RepositoryUrl>
<PackageTags>console;ui;terminal;console-application;terminal-app;mainframe;mainframe-emulator</PackageTags>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<Copyright>Copyright (c) 2022 Leonardo Pessoa</Copyright>
<Authors>Leonardo Pessoa</Authors>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>Terminal is a simple visual user interface toolkit for developing console .NET applications.</Description>
<Description>Mainframe is a simple visual user interface toolkit for developing mainframe-alike console applications in .NET</Description>
<PackageIcon>Package-Icon.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<GenerateDocumentationFile>False</GenerateDocumentationFile>
<SignAssembly>False</SignAssembly>
<Title>Mainframe</Title>
<PackageReleaseNotes>Initial version</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<None Include="..\NUGET_README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\Resources\Package-Icon.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
Expand Down
4 changes: 3 additions & 1 deletion Lib/MockConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public void SendKeys(string keys) {
}

public void WaitForEmptyKeyBuffer() {
while (_keys.Any()) { }
while (_keys.Any()) {
// Just ignore while has keys
}
}

public MockConsoleInfo ReadScreen(int left, int top, int length)
Expand Down
27 changes: 27 additions & 0 deletions NUGET_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Mainframe is a simple visual user interface toolkit for developing mainframe-alike console applications in .NET

## Why the Console?

Since the raise of the graphical user interface, the development of new console-based applications has been in decline, most often relegated to IT related work. GUI applications are visually more interesting, may provide richer data, be easier to use since you can just click wherever you want/need and be more appealing to users than applications based only on a set of characters laid on a (mostly) black and white (some times green) screen. So why would anyone bother to develop another console applications nowadays?

Anyone who has already developed a modern rich web/desktop/mobile application know the effort one must go through to get the UI right: control placements, in-place validations, screen navigation, colours, images, icons, animations, and even when you don't have to develop the entire set of the visual experience of the application you still have to waste a lot of effort learning how to apply it correctly to get the desired visual results. It takes time, effort, most times a team composed of multiple people for front-end and back-end development due to using different technologies and development and maintenance times can easily go through the roof.

Developing console-based applications weren't easier either, with the developer having to fine control where to "draw" the screen, where (and when) to capture user input, and so forth. But back in 2004 I had an experience with a development tool for mainframe applications called **CSP** that amazed me for the ability it provided to build an entire screen by literally writing how it would look like in plain text. The concept has been in the back of my head since then and I've even given lots of thought it could be interesting to develop applications for common platforms like that but never actually minded to work on anything like it until now.

Thus here is Mainframe, a small framework intended to help creating console based applications that could be used either locally (for testing concepts, business logic, personal utilities and so forth) or remotely (through an SSH connection) to an even larger audience. Developing an application using Mainframe is good because:

1. It is easier and faster to develop applications (especially for developers) when you can see the exact outcome screens of your software, graphical user interfaces are all about this. It takes almost no code at all to get a screen up and running.

2. Because it has fewer capabilities (in terms of visual) than other UI alternatives, you tend to waste less time and effort to build a functional application with a better looking UI than you can achieve using `Console.Write()` only, for example (you may try out [Miguel de Icasa's **gui.cs**](https://github.com/migueldeicaza/gui.cs), it is more visually appealing but more verbose in code and you still only get to see the resulting screen when you run your application).

3. Because code behind the UI is simpler/smaller (DLL is less than 50KB), you need less code to make your applications be usable thus making it easier to identify and handle the security aspects of the application when compared to other applications because there are less points-of-contact to tamper with (but remember: any software is just as secure as you make it; don't go out trying to create the next shell with this and claim I said it would be more secure just because of that).

4. Mainframe applications can use any and all functionality provided by the .NET platform, including third-party libraries and communicate with modern remote REST APIs. The same goes for any resource available on your IDE of choice, like step-by-step debugging. The only "requirement" (it is not really enforced but best practice) is that you don't mess with the `System.Console` class during the lifetime of the application.

5. Also, any application can actually be deployed to production and be used by your users and even replace web-based applications (yes, they can) in any context using only SSH.

6. Retro is in high nowadays and the console is not going away any fast, so why not.

## Usage

Using the Mainframe toolkit is really easy and simple as I outlined. However, I thought it would be best if it was given it's own separate documentation. You can see how to start using it [here](https://github.com/Lmpessoa/Mainframe/wiki).

0 comments on commit 69340c7

Please sign in to comment.