Shos.Console 1.1.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package Shos.Console --version 1.1.6
                    
NuGet\Install-Package Shos.Console -Version 1.1.6
                    
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="Shos.Console" Version="1.1.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shos.Console" Version="1.1.6" />
                    
Directory.Packages.props
<PackageReference Include="Shos.Console" />
                    
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 Shos.Console --version 1.1.6
                    
#r "nuget: Shos.Console, 1.1.6"
                    
#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.
#:package Shos.Console@1.1.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Shos.Console&version=1.1.6
                    
Install as a Cake Addin
#tool nuget:?package=Shos.Console&version=1.1.6
                    
Install as a Cake Tool

Shos.Console

English | 日本語

Summary

Console Library (.NET 8.0 / .NET 10.0)

A library for Console.

  • GridView: Draw a collection as a table to console
  • ConsoleHelper: Read a password from the console and hash/verify it
  • ColorSetter: Temporarily set the console foreground and background colors
  • JapaneseTextNormalizer: Normalize Japanese text

Supported Frameworks

  • .NET 8.0 (net8.0)
  • .NET 10.0 (net10.0)

The NuGet package contains assemblies for both target frameworks.

NuGet

You can install Shos.Console to your project with NuGet on Visual Studio.

Package Manager

PM>Install-Package Shos.Console -version 1.1.6

.NET CLI

>dotnet add package Shos.Console --version 1.1.6

PackageReference

<PackageReference Include="Shos.Console" Version="1.1.6" />

Projects

Shos.Console

Library (targets .NET 8.0 and .NET 10.0).

GridView
  • Draw a collection as a table to console
  • Support for full-width and half-width characters (所謂全角・半角文字対応)
  • Data can also be passed per column name (IEnumerable<(string, IEnumerable<object?>)>)
  • Extension method version: ShowTable()
ConsoleHelper
  • public static string ReadPassword(string message)
    • Reads a password from the console input and returns a salted PBKDF2-SHA256 hash.
  • public static string HashPassword(string password)
    • Creates a salted PBKDF2-SHA256 hash without reading from the console.
  • public static bool VerifyPassword(string password, string passwordHash)
    • Verifies a password against a hash returned by ReadPassword or HashPassword.
    • Hash values returned by older versions (unsalted SHA-256) are not compatible and must be migrated.
ColorSetter
  • A class that temporarily sets the console foreground and background colors.
JapaneseTextNormalizer
  • Provides methods to normalize Japanese text by converting inappropriate ASCII characters and half-width katakana to their appropriate forms.

Shos.Console.Sample

Sample for Shos.Console (targets .NET 8.0 and .NET 10.0).

Shos.ConsoleTests

Tests for Shos.Console (MSTest, targets .NET 8.0 and .NET 10.0).

Build and Test

Requires the .NET 10 SDK (which can also build net8.0 targets). Running the tests for each target framework requires the corresponding .NET runtime.

>dotnet build Shos.Console.sln
>dotnet test Shos.Console.sln

To run for a specific framework:

>dotnet test Shos.Console.sln -f net10.0

Release Notes

1.1.6

  • Supports both .NET 8.0 and .NET 10.0 (multi-targeting).
  • ConsoleHelper: Password hashes use salted PBKDF2-SHA256. Added HashPassword and VerifyPassword.
  • GridView: Enumerates each input sequence only once, skips indexer properties, and tolerates a null first row.
  • JapaneseTextNormalizer: Normalizes full-width wave dash and full-width tilde to ~.

Sample

See the sample: https://github.com/Fujiwo/Shos.Console/blob/main/Shos.Console.Sample/Program.cs


using System.Collections.Generic;
using System.Linq;

namespace Shos.Console.Sample
{
    // Japanese (日本語)
    class Program
    {
        static void 英数字記号のみの場合()
        {
            var staffs = new[] {
                new { Number = 101, Name = "Takuro Yoshida" , Email = "takuro.y@xxx.com"  , Score =   0.0 },
                new { Number = 111, Name = "Miyuki Nakajima", Email = "m.nakajima@xxx.com", Score =   8.3 },
                new { Number = 120, Name = "Sho Kiryuin"    , Email = "eiichi@xxx.com"    , Score =  99.7 },
                new { Number =   9, Name = "Kana Nishino"   , Email = "kana@xxx.com"      , Score = 100.0 }
            }.OrderBy(staff => staff.Number);

            GridView.Show(dataSource: staffs);
        }

        static void 所謂全角半角混じりの場合()
        {
            var 全社員 = new[] {
                new { 社員番号 = 101, 氏名 = "吉田 拓郎  ", フリガナ = "ヨシダ タクロウ" , メール = "takuro.y@xxx.com"  , 点数 =   0.0 },
                new { 社員番号 = 111, 氏名 = "中島 みゆき", フリガナ = "ナカジマ ミユキ" , メール = "m.nakajima@xxx.com", 点数 =   8.3 },
                new { 社員番号 = 120, 氏名 = "鬼龍院 翔"  , フリガナ = "キリュウイン ショウ", メール = "eiichi@xxx.com"    , 点数 =  99.7 },
                new { 社員番号 =   9, 氏名 = "西野 かな"  , フリガナ = "ニシノ カナ"    , メール = "kana@xxx.com"      , 点数 = 100.0 }
            }.OrderBy(社員 => 社員.氏名);

            GridView.Show(dataSource: 全社員, hasFrame: true);
        }

        class Staff
        {
            public int    Number         { get; set; }
            public string FamilyName     { get; set; } = "";
            public string GivenName      { get; set; } = "";
            public string FullName => $"{FamilyName} {GivenName}";
            public string FamilyNameRuby { get; set; } = "";
            public string GivenNameRuby  { get; set; } = "";
            public string FullNameRuby => $"{FamilyNameRuby} {GivenNameRuby}";
            public string Email          { get; set; } = "";
        }

        static void クラス利用の場合()
        {
            var staffs = new List<Staff> {
                new Staff { Number = 101, FamilyName = "吉田"  , GivenName = "拓郎  ", FamilyNameRuby = "ヨシダ"  , GivenNameRuby = "タクロウ", Email = "takuro.y@xxx.com"   },
                new Staff { Number = 111, FamilyName = "中島"  , GivenName = "みゆき", FamilyNameRuby = "ナカジマ" , GivenNameRuby = "ミユキ" , Email = "m.nakajima@xxx.com" },
                new Staff { Number =  12, FamilyName = "鬼龍院", GivenName = "翔"    , FamilyNameRuby = "キリュウイン", GivenNameRuby = "ショウ" , Email = "eiichi@xxx.com"     },
                new Staff { Number =   9, FamilyName = "西野"  , GivenName = "かな"  , FamilyNameRuby = "ニシノ"   , GivenNameRuby = "カナ"  , Email = "kana@xxx.com"       }
            };

            var scoreTable = new Dictionary<int, double> {
                { 101, 100.0 },
                { 111,  80.0 },
                {  12,   8.0 },
                {   9,   0.0 }
            };

            GridView.Show(
                dataSource: staffs.OrderBy(staff => staff.Number)
                                  .Select(staff => new {
                    社員番号 = staff.Number      ,
                    氏名     = staff.FullName    ,
                    フリガナ    = staff.FullNameRuby,
                    メール      = staff.Email       ,
                    得点     = scoreTable[staff.Number]
                }),
                hasFrame: true
            );
        }

        class Department
        {
            public int Code { get; set; }
            public string Name { get; set; } = "";
        }

        class Employee
        {
            public string Name { get; set; } = "";
            public int Number { get; set; }
            public Department? Department { get; set; }
        }

        static void クラスを2つ利用した場合()
        {
            var departments = new[] {
                new Department { Code = 1001, Name = "人事部"        },
                new Department { Code =  501, Name = "経理部"        },
                new Department { Code = 3001, Name = "R&D室"         },
                new Department { Code =   27, Name = "土木開発事業部"}
            };

            var staffs = new[] {
                new Employee { Name = "西村 要"    , Number =   3, Department = departments[0] },
                new Employee { Name = "川村 咲"    , Number = 101, Department = departments[1] },
                new Employee { Name = "東 さくら"  , Number =  40, Department = departments[1] },
                new Employee { Name = "柴咲 育三郎", Number =  27, Department = departments[2] }
            };

            System.Console.WriteLine("(1) GridView.Show(departments)");

            GridView.Show(dataSource: departments, hasFrame: true);

            System.Console.WriteLine("(2.1) GridView.Show(staffs)");

            GridView.Show(dataSource: staffs, hasFrame: true);

            System.Console.WriteLine("(2.2) GridView.Show(staffs.Select(...))");

            GridView.Show(
                dataSource: staffs.Select(staff => new { 名前 = staff.Name, 番号 = staff.Number, 部署 = $"{staff.Department?.Name ?? ""}({staff.Department?.Code})" }),
                hasFrame: true
            );

            System.Console.WriteLine("(2.3) staffs.Select(...).ShowTable() | Extension method version");

            // Extension method version
            staffs.OrderBy(staff => staff.Number)
                  .Select(staff => new { 名前 = staff.Name, 番号 = staff.Number, 部署 = $"{staff.Department?.Name ?? ""}({staff.Department?.Code})" })
                  .ShowTable();
        }
        
        static void カラム名ごとにデータを渡す場合()
        {
            var 全社員 = new (string, IEnumerable<object?>)[] {
                ("社員番号", new object[] { 101, 111, 120, 9, 100 }),
                ("氏名"   , new object[] { "吉田 拓郎", "中島 みゆき", "鬼龍院 翔", "西野 かな" }),
                ("フリガナ"   , new object[] { "ヨシダ タクロウ", "ナカジマ ミユキ", "キリュウイン ショウ", "ニシノ カナ" }),
                ("メール"   , new object[] { "takuro.y@xxx.com", "m.nakajima@xxx.com", "eiichi@xxx.com", "kana@xxx.com" }),
            };

            GridView.Show(dataSource: 全社員, hasFrame: true);
        }
        struct MenuItem
        {
            public enum Kind { 社員, 部署, その他 };

            public string Key { get; set; }
            public string Title { get; set; }
        }

        static void カラム名ごとにデータを渡す場合応用編()
        {
            var menuItems = new (MenuItem, MenuItem.Kind)[] {
                (new MenuItem { Key = "1", Title = "検索" }, MenuItem.Kind.社員),
                (new MenuItem { Key = "2", Title = "追加" }, MenuItem.Kind.社員),
                (new MenuItem { Key = "3", Title = "削除" }, MenuItem.Kind.社員),
                (new MenuItem { Key = "4", Title = "変更" }, MenuItem.Kind.社員),
                (new MenuItem { Key = "1", Title = "検索" }, MenuItem.Kind.部署),
                (new MenuItem { Key = "2", Title = "追加" }, MenuItem.Kind.部署),
                (new MenuItem { Key = "3", Title = "削除" }, MenuItem.Kind.部署),
                (new MenuItem { Key = "4", Title = "変更" }, MenuItem.Kind.部署),
                (new MenuItem { Key = "1", Title = "保存" }, MenuItem.Kind.その他),
                (new MenuItem { Key = "2", Title = "終了" }, MenuItem.Kind.その他)
            };

            var groups = menuItems.GroupBy(x => x.Item2);
            var dataSource = groups.Select(x => (x.Key.ToString(), x.Select(_ => (object?)$"({_.Item1.Key}){_.Item1.Title}")));
            dataSource.ShowTable(hasFrame: true);
        }

        static void Main()
        {
            new System.Action[] { 英数字記号のみの場合, 所謂全角半角混じりの場合, クラス利用の場合, クラスを2つ利用した場合, カラム名ごとにデータを渡す場合, カラム名ごとにデータを渡す場合応用編 }
            .ForEach((index, test) =>
            {
                System.Console.WriteLine($"■ Test {index + 1}");
                test();
                System.Console.WriteLine();
            });
        }
    }
}

Result:


■ Test 1
Number Name            Email              Score
     9 Kana Nishino    kana@xxx.com       100.0
   101 Takuro Yoshida  takuro.y@xxx.com     0.0
   111 Miyuki Nakajima m.nakajima@xxx.com   8.3
   120 Sho Kiryuin     eiichi@xxx.com      99.7

■ Test 2
+----------+-------------+------------+--------------------+-------+
| 社員番号 | 氏名        | フリガナ      | メール                | 点数  |
+----------+-------------+------------+--------------------+-------+
|      120 | 鬼龍院 翔   | キリュウイン ショウ | eiichi@xxx.com     |  99.7 |
|      101 | 吉田 拓郎   | ヨシダ タクロウ  | takuro.y@xxx.com   |   0.0 |
|        9 | 西野 かな   | ニシノ カナ     | kana@xxx.com       | 100.0 |
|      111 | 中島 みゆき | ナカジマ ミユキ  | m.nakajima@xxx.com |   8.3 |
+----------+-------------+------------+--------------------+-------+

■ Test 3
+----------+-------------+------------+--------------------+-------+
| 社員番号 | 氏名        | フリガナ      | メール                | 得点  |
+----------+-------------+------------+--------------------+-------+
|        9 | 西野 かな   | ニシノ カナ     | kana@xxx.com       |   0.0 |
|       12 | 鬼龍院 翔   | キリュウイン ショウ | eiichi@xxx.com     |   8.0 |
|      101 | 吉田 拓郎   | ヨシダ タクロウ  | takuro.y@xxx.com   | 100.0 |
|      111 | 中島 みゆき | ナカジマ ミユキ  | m.nakajima@xxx.com |  80.0 |
+----------+-------------+------------+--------------------+-------+

■ Test 4
(1) GridView.Show(departments)
+------+----------------+
| Code | Name           |
+------+----------------+
| 1001 | 人事部         |
|  501 | 経理部         |
| 3001 | R&D室          |
|   27 | 土木開発事業部 |
+------+----------------+
(2.1) GridView.Show(staffs)
+-------------+--------+----------------------------------------+
| Name        | Number | Department                             |
+-------------+--------+----------------------------------------+
| 西村 要     |      3 | Shos.Console.Sample.Program+Department |
| 川村 咲     |    101 | Shos.Console.Sample.Program+Department |
| 東 さくら   |     40 | Shos.Console.Sample.Program+Department |
| 柴咲 育三郎 |     27 | Shos.Console.Sample.Program+Department |
+-------------+--------+----------------------------------------+
(2.2) GridView.Show(staffs.Select(...))
+-------------+------+--------------+
| 名前        | 番号 | 部署         |
+-------------+------+--------------+
| 西村 要     |    3 | 人事部(1001) |
| 川村 咲     |  101 | 経理部(501)  |
| 東 さくら   |   40 | 経理部(501)  |
| 柴咲 育三郎 |   27 | R&D室(3001)  |
+-------------+------+--------------+
(2.3) staffs.Select(...).ShowTable() | Extension method version
+-------------+------+--------------+
| 名前        | 番号 | 部署         |
+-------------+------+--------------+
| 西村 要     |    3 | 人事部(1001) |
| 柴咲 育三郎 |   27 | R&D室(3001)  |
| 東 さくら   |   40 | 経理部(501)  |
| 川村 咲     |  101 | 経理部(501)  |
+-------------+------+--------------+

■ Test 5
+----------+-------------+------------+--------------------+
| 社員番号 | 氏名        | フリガナ      | メール                |
+----------+-------------+------------+--------------------+
|      101 | 吉田 拓郎   | ヨシダ タクロウ  | takuro.y@xxx.com   |
|      111 | 中島 みゆき | ナカジマ ミユキ  | m.nakajima@xxx.com |
|      120 | 鬼龍院 翔   | キリュウイン ショウ | eiichi@xxx.com     |
|        9 | 西野 かな   | ニシノ カナ     | kana@xxx.com       |
|      100 |             |            |                    |
+----------+-------------+------------+--------------------+

Author Info

Fujio Kojima: a software developer in Japan

  • Microsoft MVP for Development Tools - Visual C# (Jul. 2005 - Dec. 2014)
  • Microsoft MVP for .NET (Jan. 2015 - Oct. 2015)
  • Microsoft MVP for Visual Studio and Development Technologies (Nov. 2015 - Jun. 2018)
  • Microsoft MVP for Developer Technologies (Nov. 2018 - Jun. 2027)
  • MVP Profile
  • Blog (Japanese)
  • Web Site (Japanese)
  • Twitter
  • Instagram

License

This library is under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
1.1.8 84 10/10/2026
1.1.7 85 10/10/2026
1.1.6 78 10/9/2026
1.1.5 425 8/28/2024
1.1.4 300 8/28/2024
1.1.3 302 8/9/2024
1.1.1 253 8/8/2024
1.1.0 263 8/8/2024
1.0.9 278 8/8/2024
1.0.8 257 8/8/2024
1.0.7 279 8/7/2024
1.0.6 260 8/7/2024
1.0.5 272 8/7/2024
1.0.4 259 8/7/2024
1.0.3 303 3/26/2024
1.0.2.1 651 6/16/2022
1.0.2 579 6/16/2022
1.0.1 590 6/16/2022
1.0.0 593 6/16/2022