Aptivi - Deprecated Manuals
ProjectsWebsiteBlog
Nitrocid KS v0.1.0 Beta 3 - Manual
Nitrocid KS v0.1.0 Beta 3 - Manual
  • ๐Ÿ‘‹Welcome!
  • Versions and Compatibility
    • ๐Ÿ”ฑSupported Versions
    • ๐Ÿ•˜EOL Versions
    • ๐Ÿ—ž๏ธVersion Release Notes
      • โœจv0.0.1.x series
      • ๐ŸŒˆv0.0.2.x series
      • ๐Ÿ‘ฅv0.0.3.x series
      • ๐Ÿ› ๏ธv0.0.4.x series
      • ๐Ÿ•”v0.0.5.x series
        • โŒšv0.0.5.0 Beta Versions
      • ๐Ÿ“•v0.0.6.x series
        • ๐Ÿ“„v0.0.6.0 Beta Versions
      • ๐Ÿ”Œv0.0.7.x series
        • โšกv0.0.7.0 Beta Versions
      • ๐ŸŒŒv0.0.8.x series
      • ๐Ÿ’Œv0.0.9.x series
      • ๐Ÿ“œv0.0.10.x series
      • โœ๏ธv0.0.11.x series
      • โš™๏ธv0.0.12.x series
      • ๐ŸŒv0.0.13.x series
      • ๐Ÿƒโ€โ™€๏ธv0.0.14.x series
      • โณv0.0.15.x series
      • โญv0.0.16.x series
      • ๐ŸŒƒv0.0.17.x series
      • ๐Ÿฅv0.0.18.x series
      • ๐Ÿ”งv0.0.19.x series
      • ๐Ÿ€v0.0.20.x series
      • ๐Ÿงฐv0.0.21.x series
      • ๐Ÿ“ฑv0.0.22.x series
      • ๐Ÿ–ฅ๏ธv0.0.23.x series
      • ๐Ÿ‘พv0.0.24.x series
      • ๐Ÿ”ฎv0.1.x.x series
        • โš ๏ธKnown issues for 0.1.0 Beta
    • ๐Ÿ‘Compatibility Notes for KS API Revisions
      • ๐Ÿ”ผUpgrading from API v1.0
      • ๐Ÿ”ผUpgrading from API v1.1
      • ๐Ÿ”ผUpgrading from API v1.2
      • ๐Ÿ”ผUpgrading from API v1.3
      • ๐Ÿ”ผUpgrading from API v2.0
      • ๐Ÿ”ผUpgrading from API v2.1
      • ๐Ÿ”ผUpgrading to API v3.0
        • โฌ†๏ธFrom 0.0.24.x to 0.1.0 Beta 1
        • โฌ†๏ธFrom 0.1.0 Beta 1 to 0.1.0 Beta 2
        • โฌ†๏ธFrom 0.1.0 Beta 2 to 0.1.0 Beta 3
  • Installation and Maintenance
    • ๐Ÿ“€Installing the Kernel
      • ๐Ÿ’ปWindows
      • ๐ŸŽmacOS
      • ๐ŸงLinux
      • ๐Ÿ“ฑAndroid
    • โซUpgrading the Kernel
      • ๐Ÿ’ปWindows
      • ๐ŸŽmacOS
      • ๐ŸงLinux
      • ๐Ÿ“ฑAndroid
    • ๐Ÿ“ฆDependency Information
  • Fundamentals
    • ๐ŸŒฝWhat is the Kernel?
    • ๐Ÿ‘พWhat is Nitrocid KS?
    • โญSimulated Kernel Features
      • ๐ŸŒŸExtra Features
        • ๐ŸŒMore Networking
          • ๐Ÿ—ƒ๏ธFTP Client
          • ๐Ÿ”’SFTP Client
          • ๐Ÿ“ฐRSS Client
          • ๐ŸŒHTTP Client
          • ๐Ÿ“งMail Client
        • ๐ŸŽฎGames and Amusements
          • ๐Ÿ”คHangman
          • ๐Ÿ‡BackRace
          • โ˜„๏ธMeteor
          • ๐ŸŽฐRussian Roulette
          • โ˜„๏ธShipDuet
          • ๐ŸSnaker
          • ๐Ÿ”ขSolver
          • โŒจ๏ธSpeedPress
          • ๐Ÿ” Wordle
        • ๐Ÿ–Š๏ธMore Editors
          • ๐Ÿ–Š๏ธJSON Editor
          • ๐Ÿ—„๏ธSQL Editor
        • ๐ŸงฐCommon Programs
          • ๐Ÿ“ฆArchive
          • โ˜•Caffeine
          • ๐Ÿ—“๏ธCalendar
          • ๐Ÿ”ขCalculator
          • ๐Ÿ‘ฅContacts
          • ๐Ÿ‘ฉโ€๐Ÿ’ปGit Shell
          • ๐ŸŽงMusic Player
          • ๐Ÿ—’๏ธNotes
          • ๐Ÿ”ŒSSH Connection
          • โฐStopwatch and Timer
          • โ˜‘๏ธTo-do List
          • โš–๏ธUnit Converter
          • โ˜€๏ธWeather
        • ๐Ÿช„ChatGPT Client
        • ๐Ÿ–ผ๏ธDocking
        • ๐ŸŒLanguage Studio
        • ๐ŸŽจTheme Studio
      • ๐Ÿ‘คAccounts
        • ๐Ÿ‘ฅGroups
        • ๐Ÿ”“Permissions
      • โœ๏ธEditors
        • ๐Ÿ“Text Editor
        • ๐Ÿ’พHex Editor
      • ๐ŸšShells
        • ๐Ÿ“„Commands List
        • ๐Ÿ“„Addon Commands List
      • ๐Ÿ“‚Files and Folders
      • ๐ŸŒŽNetworking
      • ๐Ÿ‡บ๐Ÿ‡ธLanguages
      • ๐ŸŒŒScreensavers
      • ๐Ÿ’ฟBootable Simulation
  • Advanced and Power Users
    • โš’๏ธBuilding the Kernel
      • ๐ŸชŸBuilding on Windows
      • ๐ŸŽBuilding on macOS
      • ๐ŸงBuilding on Linux
      • ๐Ÿ“ฑBuilding on Android
    • ๐ŸงฐKernel Modifications
      • ๐Ÿ—๏ธBuild your...
        • ๐ŸงชYour Mod
        • ๐Ÿช„Your Splash
      • ๐Ÿ“‰Analyzers for Mods
      • ๐Ÿ“ˆAnalyzer Diagnostics
        • ๐Ÿ“‰Text - NKS0001
        • ๐Ÿ“‰ConsoleBase - NKS0002
        • ๐Ÿ“‰ConsoleBase - NKS0003
        • ๐Ÿ“‰ConsoleBase - NKS0004
        • ๐Ÿ“‰ConsoleBase - NKS0005
        • ๐Ÿ“‰ConsoleBase - NKS0006
        • ๐Ÿ“‰ConsoleBase - NKS0007
        • ๐Ÿ“‰ConsoleBase - NKS0008
        • ๐Ÿ“‰ConsoleBase - NKS0009
        • ๐Ÿ“‰Files - NKS0010
        • ๐Ÿ“‰Files - NKS0011
        • ๐Ÿ“‰Files - NKS0012
        • ๐Ÿ“‰Files - NKS0013
        • ๐Ÿ“‰Files - NKS0014
        • ๐Ÿ“‰Files - NKS0015
        • ๐Ÿ“‰Files - NKS0016
        • ๐Ÿ“‰Files - NKS0017
        • ๐Ÿ“‰Files - NKS0018
        • ๐Ÿ“‰Files - NKS0019
        • ๐Ÿ“‰Files - NKS0020
        • ๐Ÿ“‰Files - NKS0021
        • ๐Ÿ“‰Files - NKS0022
        • ๐Ÿ“‰Files - NKS0023
        • ๐Ÿ“‰Kernel - NKS0024
        • ๐Ÿ“‰Kernel - NKS0025
        • ๐Ÿ“‰Kernel - NKS0026
        • ๐Ÿ“‰Kernel - NKS0027
        • ๐Ÿ“‰Kernel - NKS0031
        • ๐Ÿ“‰Kernel - NKS0032
        • ๐Ÿ“‰Kernel - NKS0033
        • ๐Ÿ“‰Kernel - NKS0037
        • ๐Ÿ“‰Kernel - NKS0038
        • ๐Ÿ“‰Kernel - NKS0039
        • ๐Ÿ“‰Kernel - NKS0040
        • ๐Ÿ“‰Kernel - NKS0041
        • ๐Ÿ“‰Kernel - NKS0042
        • ๐Ÿ“‰Kernel - NKS0043
        • ๐Ÿ“‰Kernel - NKS0052
        • ๐Ÿ“‰Kernel - NKS0053
        • ๐Ÿ“‰Languages - NKS0044
        • ๐Ÿ“‰Languages - NKS0045
        • ๐Ÿ“‰Languages - NKS0046
        • ๐Ÿ“‰Network - NKS0051
        • ๐Ÿ“‰Text - NKS0047
        • ๐Ÿ“‰Text - NKS0048
        • ๐Ÿ“‰Text - NKS0049
        • ๐Ÿ“‰Text - NKS0050
        • ๐Ÿ“‰Text - NKS0054
        • ๐Ÿ“‰Text - NKS0055
      • ๐Ÿ”งKernel Modification Management
      • ๐Ÿ“žInter-Mod Communication
      • ๐Ÿ“žInter-Addon Communication
    • ๐Ÿฆ Diagnostics
      • ๐Ÿ”ฌDebugging
        • ๐ŸงฌLocal Debugging
        • ๐Ÿ›ฐ๏ธRemote Debugging
      • ๐ŸงชTesting
      • ๐Ÿ’‰Other Diagnostics
    • โš’๏ธInner Workings
      • ๐Ÿ”งKernel Settings
        • โ›๏ธMechanics of Settings App
        • ๐Ÿ”ฉSettings Format
        • โš™๏ธCustom Settings
      • ๐ŸšShell Structure
        • โ”Help System
        • ๐Ÿ—œ๏ธCommand Parsing
        • ๐Ÿ”‹Command Information
        • โฒ๏ธCommand Switch Management
        • ๐ŸŽš๏ธCommand Switch Information
        • โณShell History
        • ๐Ÿ“œShell Scripting
        • ๐Ÿ“ŸShell Presets
        • ๐Ÿ’ Extra Shell Features
      • ๐ŸŒMultilingual Kernel
        • ๐ŸŒCustom Languages
      • ๐Ÿ–ฅ๏ธConsole Manipulation
        • ๐ŸงฉConsole Wrappers
        • ๐Ÿ–ฅ๏ธConsole Screen
      • ๐Ÿ–ฒ๏ธConsole Input
        • โŒจ๏ธInteractive TUI
        • ๐Ÿ“ฝ๏ธPresentation System
      • โ™ฆ๏ธInner Essentials
        • ๐ŸชงKernel Placeholders
        • ๐Ÿ”The Permissions
        • ๐Ÿ‘ฅThe Users
        • ๐Ÿ“žKernel Threads
        • ๐Ÿ”ŒKernel Drivers
        • ๐ŸŽ›๏ธKernel Arguments
        • ๐Ÿ“’Kernel Journaling
        • ๐Ÿ“กRemote Procedure
        • ๐Ÿ—ƒ๏ธNitrocid Filesystem
        • ๐ŸŒƒScreensaver Internals
        • ๐Ÿ’ฆSplash Internals
        • ๐Ÿ–ฅ๏ธKernel Platform
        • ๐ŸŽจTheme Internals
        • โ›ฑ๏ธColor Internals
        • ๐Ÿ”Privacy Consents
        • ๐Ÿ””System Notifications
        • โœ‰๏ธMAL and MOTD
        • โŒ›Progress Handlers
        • โœ’๏ธAssembly Signing
        • ๐ŸŽฐRandom Number Generation
        • ๐ŸŒNetwork Tools
      • ๐ŸŒ€Miscellaneous APIs
  • ๐ŸงฑProject Dependencies
  • Report an issue
  • Source code
  • API Reference
Powered by GitBook
On this page
  • Screen Instance
  • Screen Management
  • An example
Edit on GitHub
  1. Advanced and Power Users
  2. Inner Workings
  3. Console Manipulation

Console Screen

Your screen in front of you

Last updated 1 year ago

Nitrocid KS offers the console screen feature, which allows you to define a screen for your interactive console application. This guarantees you a dynamic terminal sequence generation that you can print to the console. Usage of the VT sequences, as seen in the Terminaux manual, can be found here:

Screen Instance

The explanation provided here is not exhaustive, but a more detailed explanation can be found in the Terminaux manual here:

You can get started by making a new instance of the Screen class and using it to add a new ScreenPart instance with its name to make a layer for your rendering sequences. This facilitates buffering the screens to the console.

The screen part instance allows you to add text in different ways:

  • AddText(): Adds a simple and static text to the buffer

  • AddTextLine(): Adds a simple and static text to the buffer with the extra new line

  • AddDynamicText(): This is the key of the Screen feature. It allows you to define a function delegate that generates text dynamically.

  • Position(): Adds a VT sequence that changes the position. Works for static text addition.

  • LeftPosition(): Adds a VT sequence that changes the cursor left position. Works for static text addition.

  • TopPosition(): Adds a VT sequence that changes the cursor top position. Works for static text addition.

  • ForegroundColor(): Adds a VT sequence that changes the foreground color. Works for static text addition.

  • BackgroundColor(): Adds a VT sequence that changes the background color. Works for static text addition.

  • ResetColor(): Adds a VT sequence that resets the colors.

  • Clear(): Clears the whole buffer.

  • GetBuffer(): Gets the resulting buffer.

AddDynamicText() is needed if you want to display anything that changes, including a box that changes when the console is resized.

Screen Management

The screen management tools allow you to manipulate with the screen rendering, such as getting the current screen instance, rendering the current screen once, etc.

  • Render() renders the current screen.

  • Render(Screen) renders the specified screen.

In the Render() functions, you can also tell the renderer to clear the screen by passing true to the optional argument, clearScreen.

However, for Render() to work, you need to add your screen instance to the list of tracked screens in the screen manager. This can be done by calling the SetCurrent() function on your screen instance.

When this is done, the screensaver manager and the console resize listener will refresh and redraw your screen, taking new console window dimensions to account. This reaction makes your interactive console applications that use screens responsive to the resize events.

Don't forget to remove your screen from the list of tracked screens once you're done using it. You can call UnsetCurrent() to make this happen.

If your application contains a main loop wrapped in a try and catch block, you must create a finally block (if not done) and call UnsetCurrent() on your screen instance. It may be necessary to move your screen instance declaration in your code outside the try and catch block.

An example

The kernel interactive testing system allows you to try the demonstration of this feature out to show you the concept of what happens when you try to resize the console when the kernel tracks your screen instance.

The screen instance in question shows you two rulers:

  • A horizontal ruler that shows you the width of the console window

  • A vertical ruler that shows you the height of the console window

โš’๏ธ
๐Ÿ–ฅ๏ธ
๐Ÿ–ฅ๏ธ
Console Screen
https://github.com/Aptivi/NitrocidKS/blob/main/public/Nitrocid/Kernel/Debugging/Testing/Facades/TestScreen.cs
รฏยปยฟ//
// Nitrocid KS  Copyright (C) 2018-2025  Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

using Terminaux.Base.Buffered;
using Nitrocid.ConsoleBase.Colors;
using Terminaux.Inputs.Styles.Infobox;
using Nitrocid.Languages;
using System;
using System.Text;
using Terminaux.Colors;
using Terminaux.Sequences.Builder.Types;
using Terminaux.Base;
using Terminaux.Colors.Data;
using Terminaux.Inputs;
using Terminaux.Base.Extensions;

namespace Nitrocid.Kernel.Debugging.Testing.Facades
{
    internal class TestScreen : TestFacade
    {
        public override string TestName => Translate.DoTranslation("Tests the screen feature for the console");
        public override TestSection TestSection => TestSection.ConsoleBase;
        public override void Run()
        {
            // Show the screen measurement sticks
            var stickScreen = new Screen();
            try
            {
                var stickScreenPart = new ScreenPart();
                stickScreenPart.AddDynamicText(() =>
                {
                    var builder = new StringBuilder();
                    builder.Append(
                        ConsolePositioning.RenderChangePosition(0, 1) +
                        ColorTools.RenderSetConsoleColor(new Color(ConsoleColors.Silver), true) +
                        GenerateWidthStick() + GenerateHeightStick() +
                        ColorTools.RenderResetColors()
                    );
                    return builder.ToString();
                });
                stickScreen.AddBufferedPart("Test", stickScreenPart);
                ScreenTools.SetCurrent(stickScreen);
                ScreenTools.Render();
                Input.ReadKey();
            }
            catch (Exception ex)
            {
                InfoBoxModalColor.WriteInfoBoxModalColor(Translate.DoTranslation("Screen failed to render:") + $" {ex.Message}", KernelColorTools.GetColor(KernelColorType.Error));
            }
            finally
            {
                ScreenTools.UnsetCurrent(stickScreen);
            }
        }

        private static string GenerateWidthStick() =>
            new(' ', ConsoleWrapper.WindowWidth);

        private static string GenerateHeightStick()
        {
            var stick = new StringBuilder();
            for (int i = 0; i < ConsoleWrapper.WindowHeight; i++)
            {
                stick.Append(CsiSequences.GenerateCsiCursorPosition(2, i));
                stick.Append(' ');
            }
            return stick.ToString();
        }
    }
}