UnixConsoleEcho 0.1.0

dotnet add package UnixConsoleEcho --version 0.1.0
                    
NuGet\Install-Package UnixConsoleEcho -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UnixConsoleEcho" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UnixConsoleEcho" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="UnixConsoleEcho" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UnixConsoleEcho --version 0.1.0
                    
#r "nuget: UnixConsoleEcho, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=UnixConsoleEcho&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=UnixConsoleEcho&version=0.1.0
                    
Install as a Cake Tool

UnixConsoleEcho

This is a small library that provides an API to disable and enable console input echo on Unix platforms. All native code from this project is taken from non-public API's within corefx.

Why

To provide a way to implement alternative versions of Console.ReadKey for Unix platforms. Currently the Unix implementation of ReadKey can not be used at the same time as the CursorTop or CursorLeft properties. If ReadKey is running in one thread, and one of those properties is called in another, that thread will block until ReadKey finishes.

This project provides access to the native code from corefx that is used to disable console input echo, allowing other projects to implement their own ReadKey methods that do not have the same issue. This is mainly meant as a workaround until a ReadKeyAsync method is (hopefully) implemented in corefx.

Although this was made specifically to be consumed by PowerShellEditorServices, it is not a Microsoft project.

Usage

Reference the package

dotnet add ./Project.csproj package UnixConsoleEcho

Example

public static System.ConsoleKeyInfo ReadKey()
{
    UnixConsoleEcho.InputEcho.Disable();
    try
    {
        while (!System.Console.KeyAvailable)
        {
            System.Threading.Thread.Sleep(50);
        }

        return System.Console.ReadKey(true);
    }
    finally
    {
        UnixConsoleEcho.InputEcho.Enable();
    }
}

Including in Build Output

If you are building for netstandard* and are not using dotnet publish (for example, if you are creating a binary module for PowerShell) make sure you include both the managed assembly and the native runtime libraries. The easiest way to do this is to run dotnet publish and copy them to your release directory in your build script. If you are building for 4.6.x, this is handled automatically.

Building Nuget Package

Linux Steps

Set-Location ./UnixConsoleEcho
Invoke-Build
# Copy ./src/Native/Unix/build/libdisablekeyecho.so to the same path on a Windows machine

MacOS Steps

Set-Location ./UnixConsoleEcho
Invoke-Build
# Copy ./src/Native/Unix/build/libdisablekeyecho.dylib to the same path on a Windows machine

Windows Steps

Invoke-Build -Configuration Release -Task Pack
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 is compatible.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net45 was computed.  net451 is compatible.  net452 was computed.  net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 41,141 12/30/2017