-
Notifications
You must be signed in to change notification settings - Fork 0
Shining happy apps (and maps)
For most, the least appealing part of console applications is the lack of colours. Most use the default settings for terminal applications which is gray text over a black background, with very few variations (one of the most common variations would be green text over a black background, the same for old mainframe terminals). Console .NET application allow for the use of colour in applications and so does SSH (not Telnet, please don't use Telnet and it is not for the colours) but not CSP applications.
The Terminal framework has all been worked towards the principle of requiring the least effort from the developer into setting up an interface, either if only for testing purposes or for a production application, thus it mimicked the development strategy of CSP applications. I didn't want all applications to be completely dull in monochrome however I also didn't want developers to be wasting too much time into these details stalling development. This was balanced in the Terminal framework in two ways:
- By restricting some changes to be applicable only on an application scale, such as command highlights and active field colours, and
- By enabling a simple but unmodifiable means to introduce colours in individual maps.
Most customisation of the application is related to its appearance (although some relate to behaviour). To customise the application just call the instance methods provided by an instance of the Application class. The following lists the application configuration methods and their behaviour. Notice these methods can only be called on an application that is not running and will change the behaviour for any maps shown in it, it is not possible to change these settings to affect specific maps only.
-
PreserveGivenFieldValues()
By default, when leaving an input field, mainframe applications convert the value set in the field to uppercase letters. This option will preserve the visual aspect of this behaviour but will retain the values as they were input by the user (password fields always retain input as entered). -
SetConsoleSize(int, int)
*
Specifies a fixed console size for the application. By default, the current size of the window of the console will set the limit size of the application. Calling this method sets a fixed size no matter the size of the console window. -
SetDefaultWindowPosition(int, int)
Any maps shown usingShowWindow()
will be displayed centered on the console window. By setting this option you specify that maps shown in windows must be places in a specific position on the console screen. -
SetMaxIdleTime(uint)
*
Applications can run for an indefinite amount of time. However, for applications hosted on a server (e.g. SSH) it might not be a good idea. By setting this option, the application itself will monitor usage of the application (via user interactions with it) and immediately close the application should the user exceeds the given amount of minutes idle. -
UseActiveFieldBackground()
Input fields are only distinguished for having a slightly different colour from regular map text. By setting this option applications will show also a slightly different background colour on the currently focused field, allowing for it to be easily distinguished by the user. -
UseActiveFieldColors(ConsoleColor, ConsoleColor)
Input fields are only distinguished for having a slightly different colour from regular map text. By setting this option applications will show the currently focused field using distinctive colours as specified, allowing for the field to be easily distinguished by the user. -
UseBulletsInPasswordFields()
Text input fields that use a mask starting with a*
will mask any input character using the same character. By setting this option password fields will use the black circle Unicode character●
to mask its contents.
-
UseCommandColorInBackground(ConsoleColor)
Command highlights use the very same colouring as regular fields. By setting this option applications will render command highlights using the specified colour as background and the default background color as text colour. It is not possible to define both foreground and background colour for command highlights simultaneously. -
UseCommandColorInForeground(ConsoleColor)
Command highlights use the very same colouring as regular fields. By setting this option applications will render command highlights using the specified colour as the text colour using the default color ar background. It is not possible to define both foreground and background colour for command highlights simultaneously. -
UseWindowBorder(WindowBorder)
Any maps shown usingShowWindow()
will be displayed with a border made using regular ASCII characters like+
,-
and|
around it. By setting this option you can specify windows to be drawn with different borders, even with no border at all (maybe you want to create your own).
Colours can still be applied to maps and fields although some restrictions apply, the first being they cannot be modified after the map is instantiated or loaded from an embedded resources. All colour definitions in a map will happen on its .map
file, so let's bring back our book info map example to apply some colour to it.
>
> coolreads ADD A NEW BOOK
: 66666
: 88888888888
>
> TITLE: ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> SORT TITLE: ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> AUTHOR: ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ISBN: ¬999999999999^ ASIN:¬A999999999
> PUBLISHER: ¬XXXXXXXXXXXXXXXXXXXXXXXXXXX
> PUBLISHED YEAR: ¬999 MONTH:¬9
> PAGES: ¬999
> FORMAT: ¬ PAPERBACK ¬ HARDCOVER ¬ E-BOOK
> EDITION: ¬9 ¬XXXXXXXXXXXXXXXXXXXXXXXX
> DESCRIPTION: ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> LANGUAGE: ¬XXXXXXXXXXXXXXXXXXX
>
> ____________________________________________________________________________
> ¬XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> PF1 = HELP PF3 = RETURN PF10 = SAVE
: +++ +++ +++
If you remember well the last time you saw it, you will notice there are three extra lines there (and for the sake of brevity, I also supressed the field definitions), all starting with a colon :
. This is another special marker line for our map indicating this will provide colour information for the previous content line (the one starting with >
). Each content line might have at most 2 colour lines, the first indicates the foreground colour while the second indicates the background colour. Look at lines 2 and 3 how I used this formatting to give some colour to the app logo. Each individual character on a line may have a different colour and each one with a different colour must be specified. The following table shows the possible colour values that can be applied to map formatting.
However, it is possible to use one repeating colour for all maps of your application and have it consistent through all your maps that is using the highlight colour. The highlight colour is identified by the plus sign +
always on the first colour line (it is ignored on the second line as well as any background colour where the highlight mark is found on the first line). On our example map, it has been used to highlight the key to be pressed in order to get the map to perform an action (which is a practice I recommend, no matter which colours you use).
The resulting screen will look something like this (adapted for the colour set you use on your terminal):
There are no means to override the base colours of a map, that mandatorily retain the default colours of the client terminal application (usually gray text on a black background). That does not mean there is no way to but also doesn't mean you should do. It is important to choose wisely when and where to apply colours to a map in order not to distract or confuse the user.