Cleaned up the code a bit
This commit is contained in:
Родитель
cbb19aa090
Коммит
98090fa1c9
|
@ -0,0 +1 @@
|
|||
github: patriksvensson
|
|
@ -0,0 +1,49 @@
|
|||
name: Continuous Integration
|
||||
on: pull_request
|
||||
|
||||
env:
|
||||
# Set the DOTNET_SKIP_FIRST_TIME_EXPERIENCE environment variable to stop wasting time caching packages
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
# Disable sending usage data to Microsoft
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: true
|
||||
|
||||
jobs:
|
||||
|
||||
###################################################
|
||||
# BUILD
|
||||
###################################################
|
||||
|
||||
build:
|
||||
name: Build
|
||||
if: "!contains(github.event.head_commit.message, 'skip-ci')"
|
||||
strategy:
|
||||
matrix:
|
||||
kind: ['linux', 'windows', 'macOS']
|
||||
include:
|
||||
- kind: linux
|
||||
os: ubuntu-latest
|
||||
- kind: windows
|
||||
os: windows-latest
|
||||
- kind: macOS
|
||||
os: macos-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: 'Get Git tags'
|
||||
run: git fetch --tags
|
||||
shell: bash
|
||||
|
||||
- name: Setup dotnet
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 5.0.100
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet tool restore
|
||||
dotnet cake
|
|
@ -0,0 +1,88 @@
|
|||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'src/**'
|
||||
|
||||
env:
|
||||
# Set the DOTNET_SKIP_FIRST_TIME_EXPERIENCE environment variable to stop wasting time caching packages
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
|
||||
# Disable sending usage data to Microsoft
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: true
|
||||
|
||||
jobs:
|
||||
|
||||
###################################################
|
||||
# BUILD
|
||||
###################################################
|
||||
|
||||
build:
|
||||
name: Build
|
||||
if: "!contains(github.event.head_commit.message, 'skip-ci')"
|
||||
strategy:
|
||||
matrix:
|
||||
kind: ['linux', 'windows', 'macOS']
|
||||
include:
|
||||
- kind: linux
|
||||
os: ubuntu-latest
|
||||
- kind: windows
|
||||
os: windows-latest
|
||||
- kind: macOS
|
||||
os: macos-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: 'Get Git tags'
|
||||
run: git fetch --tags
|
||||
shell: bash
|
||||
|
||||
- name: Setup dotnet
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 5.0.100
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet tool restore
|
||||
dotnet cake
|
||||
|
||||
###################################################
|
||||
# PUBLISH
|
||||
###################################################
|
||||
|
||||
publish:
|
||||
name: Publish
|
||||
needs: [build]
|
||||
if: "!contains(github.event.head_commit.message, 'skip-ci')"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: 'Get Git tags'
|
||||
run: git fetch --tags
|
||||
shell: bash
|
||||
|
||||
- name: Setup dotnet
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 5.0.100
|
||||
|
||||
- name: Publish
|
||||
shell: bash
|
||||
run: |
|
||||
dotnet tool restore
|
||||
dotnet cake --target="publish" \
|
||||
--nuget-key="${{secrets.NUGET_API_KEY}}"
|
|
@ -0,0 +1,79 @@
|
|||
var target = Argument("target", "Default");
|
||||
var configuration = Argument("configuration", "Release");
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Tasks
|
||||
|
||||
Task("Build")
|
||||
.Does(context =>
|
||||
{
|
||||
DotNetCoreBuild("./src/TermInfo.sln", new DotNetCoreBuildSettings {
|
||||
Configuration = configuration,
|
||||
NoIncremental = context.HasArgument("rebuild"),
|
||||
MSBuildSettings = new DotNetCoreMSBuildSettings()
|
||||
.TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error)
|
||||
});
|
||||
});
|
||||
|
||||
Task("Test")
|
||||
.IsDependentOn("Build")
|
||||
.Does(context =>
|
||||
{
|
||||
DotNetCoreTest("./src/TermInfo.sln", new DotNetCoreTestSettings {
|
||||
Configuration = configuration,
|
||||
NoRestore = true,
|
||||
NoBuild = true,
|
||||
});
|
||||
});
|
||||
|
||||
Task("Package")
|
||||
.IsDependentOn("Test")
|
||||
.Does(context =>
|
||||
{
|
||||
context.CleanDirectory("./.artifacts");
|
||||
|
||||
context.DotNetCorePack($"./src/TermInfo.sln", new DotNetCorePackSettings {
|
||||
Configuration = configuration,
|
||||
NoRestore = true,
|
||||
NoBuild = true,
|
||||
OutputDirectory = "./.artifacts",
|
||||
MSBuildSettings = new DotNetCoreMSBuildSettings()
|
||||
.TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error)
|
||||
});
|
||||
});
|
||||
|
||||
Task("Publish-NuGet")
|
||||
.WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, "Not running on GitHub Actions")
|
||||
.IsDependentOn("Package")
|
||||
.Does(context =>
|
||||
{
|
||||
var apiKey = Argument<string>("nuget-key", null);
|
||||
if(string.IsNullOrWhiteSpace(apiKey)) {
|
||||
throw new CakeException("No NuGet API key was provided.");
|
||||
}
|
||||
|
||||
// Publish to GitHub Packages
|
||||
foreach(var file in context.GetFiles("./.artifacts/*.nupkg"))
|
||||
{
|
||||
context.Information("Publishing {0}...", file.GetFilename().FullPath);
|
||||
DotNetCoreNuGetPush(file.FullPath, new DotNetCoreNuGetPushSettings
|
||||
{
|
||||
Source = "https://api.nuget.org/v3/index.json",
|
||||
ApiKey = apiKey,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Targets
|
||||
|
||||
Task("Publish")
|
||||
.IsDependentOn("Publish-NuGet");
|
||||
|
||||
Task("Default")
|
||||
.IsDependentOn("Package");
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Execution
|
||||
|
||||
RunTarget(target)
|
|
@ -0,0 +1,95 @@
|
|||
root = false
|
||||
|
||||
[*.cs]
|
||||
# IDE0055: Fix formatting
|
||||
dotnet_diagnostic.IDE0055.severity = warning
|
||||
|
||||
# SA1101: Prefix local calls with this
|
||||
dotnet_diagnostic.SA1101.severity = none
|
||||
|
||||
# SA1633: File should have header
|
||||
dotnet_diagnostic.SA1633.severity = none
|
||||
|
||||
# SA1201: Elements should appear in the correct order
|
||||
dotnet_diagnostic.SA1201.severity = none
|
||||
|
||||
# SA1202: Public members should come before private members
|
||||
dotnet_diagnostic.SA1202.severity = none
|
||||
|
||||
# SA1309: Field names should not begin with underscore
|
||||
dotnet_diagnostic.SA1309.severity = none
|
||||
|
||||
# SA1404: Code analysis suppressions should have justification
|
||||
dotnet_diagnostic.SA1404.severity = none
|
||||
|
||||
# SA1516: Elements should be separated by a blank line
|
||||
dotnet_diagnostic.SA1516.severity = none
|
||||
|
||||
# CA1303: Do not pass literals as localized parameters
|
||||
dotnet_diagnostic.CA1303.severity = none
|
||||
|
||||
# CSA1204: Static members should appear before non-static members
|
||||
dotnet_diagnostic.SA1204.severity = none
|
||||
|
||||
# IDE0052: Remove unread private members
|
||||
dotnet_diagnostic.IDE0052.severity = warning
|
||||
|
||||
# IDE0063: Use simple 'using' statement
|
||||
csharp_prefer_simple_using_statement = false:suggestion
|
||||
|
||||
# IDE0018: Variable declaration can be inlined
|
||||
dotnet_diagnostic.IDE0018.severity = warning
|
||||
|
||||
# SA1625: Element documenation should not be copied and pasted
|
||||
dotnet_diagnostic.SA1625.severity = none
|
||||
|
||||
# IDE0005: Using directive is unnecessary
|
||||
dotnet_diagnostic.IDE0005.severity = warning
|
||||
|
||||
# SA1117: Parameters should be on same line or separate lines
|
||||
dotnet_diagnostic.SA1117.severity = none
|
||||
|
||||
# SA1404: Code analysis suppression should have justification
|
||||
dotnet_diagnostic.SA1404.severity = none
|
||||
|
||||
# SA1101: Prefix local calls with this
|
||||
dotnet_diagnostic.SA1101.severity = none
|
||||
|
||||
# SA1633: File should have header
|
||||
dotnet_diagnostic.SA1633.severity = none
|
||||
|
||||
# SA1649: File name should match first type name
|
||||
dotnet_diagnostic.SA1649.severity = none
|
||||
|
||||
# SA1402: File may only contain a single type
|
||||
dotnet_diagnostic.SA1402.severity = none
|
||||
|
||||
# CA1814: Prefer jagged arrays over multidimensional
|
||||
dotnet_diagnostic.CA1814.severity = none
|
||||
|
||||
# RCS1194: Implement exception constructors.
|
||||
dotnet_diagnostic.RCS1194.severity = none
|
||||
|
||||
# CA1032: Implement standard exception constructors
|
||||
dotnet_diagnostic.CA1032.severity = none
|
||||
|
||||
# CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly
|
||||
dotnet_diagnostic.CA1826.severity = none
|
||||
|
||||
# RCS1079: Throwing of new NotImplementedException.
|
||||
dotnet_diagnostic.RCS1079.severity = warning
|
||||
|
||||
# RCS1057: Add empty line between declarations.
|
||||
dotnet_diagnostic.RCS1057.severity = none
|
||||
|
||||
# IDE0004: Remove Unnecessary Cast
|
||||
dotnet_diagnostic.IDE0004.severity = warning
|
||||
|
||||
# CA1810: Initialize reference type static fields inline
|
||||
dotnet_diagnostic.CA1810.severity = none
|
||||
|
||||
# SA1636: File header copyright text should match
|
||||
dotnet_diagnostic.SA1636.severity = none
|
||||
|
||||
# CA1724: Namespace conflict
|
||||
dotnet_diagnostic.CA1724.severity = none
|
|
@ -0,0 +1,45 @@
|
|||
<Project>
|
||||
<PropertyGroup Label="Settings">
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>embedded</DebugType>
|
||||
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="Deterministic Build" Condition="'$(GITHUB_ACTIONS)' == 'true'">
|
||||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="Package Information">
|
||||
<Description>A .NET library to read binary terminfo files.</Description>
|
||||
<Authors>Patrik Svensson, Phil Scott</Authors>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/spectreconsole/wcwidth</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/spectreconsole/wcwidth</PackageProjectUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageReleaseNotes>https://github.com/spectreconsole/wcwidth/releases</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="Source Link">
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.5.0" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,8 @@
|
|||
<Project>
|
||||
<Target Name="Versioning" BeforeTargets="MinVer">
|
||||
<PropertyGroup Label="Build">
|
||||
<MinVerDefaultPreReleasePhase>preview</MinVerDefaultPreReleasePhase>
|
||||
<MinVerVerbosity>normal</MinVerVerbosity>
|
||||
</PropertyGroup>
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,18 @@
|
|||
root = false
|
||||
|
||||
[*.cs]
|
||||
|
||||
# CS1591: Missing XML comment for publicly visible type or member
|
||||
dotnet_diagnostic.CS1591.severity = none
|
||||
|
||||
# SA1600: Elements should be documented
|
||||
dotnet_diagnostic.SA1600.severity = none
|
||||
|
||||
# CA1305: Specify IFormatProvider
|
||||
dotnet_diagnostic.CA1305.severity = none
|
||||
|
||||
# CA1055: URI-like return values should not be strings
|
||||
dotnet_diagnostic.CA1055.severity = none
|
||||
|
||||
# Default severity for all analyzer diagnostics
|
||||
dotnet_analyzer_diagnostic.severity = none
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using Generator.Commands;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
|
|
|
@ -9,8 +9,14 @@
|
|||
|
||||
namespace TermInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents known terminfo capabilities.
|
||||
/// </summary>
|
||||
public static class TermInfoCaps
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents known boolean terminfo capabilities.
|
||||
/// </summary>
|
||||
public enum Boolean
|
||||
{
|
||||
{{- for cap in capabilities.booleans }}
|
||||
|
@ -21,6 +27,9 @@ namespace TermInfo
|
|||
{{~ end ~}}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents known numeric terminfo capabilities.
|
||||
/// </summary>
|
||||
public enum Num
|
||||
{
|
||||
{{- for cap in capabilities.nums }}
|
||||
|
@ -31,6 +40,9 @@ namespace TermInfo
|
|||
{{~ end ~}}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents known string terminfo capabilities.
|
||||
/// </summary>
|
||||
public enum String
|
||||
{
|
||||
{{- for cap in capabilities.strings }}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -22,4 +23,8 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\stylecop.json" Link="Properties/stylecop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
root = false
|
||||
|
||||
[*.cs]
|
||||
# CS1591: Missing XML comment for publicly visible type or member
|
||||
dotnet_diagnostic.CS1591.severity = none
|
||||
|
||||
# SA1600: Elements should be documented
|
||||
dotnet_diagnostic.SA1600.severity = none
|
||||
|
||||
# SA1633: File should have header
|
||||
dotnet_diagnostic.SA1633.severity = none
|
||||
|
||||
# CA1707: Identifiers should not contain underscores
|
||||
dotnet_diagnostic.CA1707.severity = none
|
|
@ -1,12 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using TermInfo;
|
||||
using Xunit;
|
||||
|
||||
namespace TermInfo.Tests
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -14,6 +13,10 @@
|
|||
<EmbeddedResource Include="Data\xterm+256color" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\stylecop.json" Link="Properties/stylecop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="Shouldly" Version="4.0.3" />
|
||||
|
|
|
@ -7,6 +7,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TermInfo", "TermInfo\TermIn
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TermInfo.Tests", "TermInfo.Tests\TermInfo.Tests.csproj", "{4D5E6C3E-C7AC-426C-AABE-9C44B1834C93}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TermInfo.Generator", "TermInfo.Generator\TermInfo.Generator.csproj", "{7F1EFE12-88C8-493F-8FC7-C40488179D89}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3D688222-B83C-4EDB-9ECD-C07CEC94FF2C}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
Directory.Build.props = Directory.Build.props
|
||||
Directory.Build.targets = Directory.Build.targets
|
||||
stylecop.json = stylecop.json
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -41,6 +51,18 @@ Global
|
|||
{4D5E6C3E-C7AC-426C-AABE-9C44B1834C93}.Release|x64.Build.0 = Release|Any CPU
|
||||
{4D5E6C3E-C7AC-426C-AABE-9C44B1834C93}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4D5E6C3E-C7AC-426C-AABE-9C44B1834C93}.Release|x86.Build.0 = Release|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Release|x64.Build.0 = Release|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{7F1EFE12-88C8-493F-8FC7-C40488179D89}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -4,9 +4,9 @@ using System.Text;
|
|||
|
||||
namespace TermInfo
|
||||
{
|
||||
public static class StreamExtensions
|
||||
internal static class StreamExtensions
|
||||
{
|
||||
public static string ReadString(this Stream stream, int count)
|
||||
public static string? ReadString(this Stream stream, int count)
|
||||
{
|
||||
var buffer = new byte[count];
|
||||
var read = stream.Read(buffer, 0, count);
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TermInfo
|
||||
{
|
||||
|
|
|
@ -38,6 +38,11 @@ namespace TermInfo
|
|||
private static string[] ReadNames(Stream stream, TermInfoHeader header)
|
||||
{
|
||||
var names = stream.ReadString(header.NameSectionLength);
|
||||
if (names == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not read terminfo name section.");
|
||||
}
|
||||
|
||||
return names.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
|
@ -86,11 +91,16 @@ namespace TermInfo
|
|||
return offsets;
|
||||
}
|
||||
|
||||
private static string[] ReadStrings(Stream stream, TermInfoHeader header, int[] offsets)
|
||||
private static string?[] ReadStrings(Stream stream, TermInfoHeader header, int[] offsets)
|
||||
{
|
||||
// Read strings
|
||||
var strings = new string[offsets.Length];
|
||||
var strings = new string?[offsets.Length];
|
||||
var table = stream.ReadString(header.StringTableLength);
|
||||
if (table == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not read terminfo string table");
|
||||
}
|
||||
|
||||
for (var i = 0; i < offsets.Length; i++)
|
||||
{
|
||||
if (offsets[i] != -1)
|
||||
|
|
|
@ -3,21 +3,18 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<PackageId>TermInfo</PackageId>
|
||||
<Version>0.1</Version>
|
||||
<Authors>Patrik Svensson</Authors>
|
||||
<Authors>Patrik Svensson, Phil Scott</Authors>
|
||||
<Nullable>enable</Nullable>
|
||||
<Product>TermInfo</Product>
|
||||
<Description>A library to read binary terminfo files.</Description>
|
||||
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
|
||||
<PackageProjectUrl>https://github.com/patriksvensson/terminfo</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/patriksvensson/terminfo</RepositoryUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/spectreconsole/terminfo</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/spectreconsole/terminfo</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
<AdditionalFiles Include="..\stylecop.json" Link="Properties/stylecop.json" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -9,8 +9,14 @@
|
|||
|
||||
namespace TermInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents known terminfo capabilities.
|
||||
/// </summary>
|
||||
public static class TermInfoCaps
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents known boolean terminfo capabilities.
|
||||
/// </summary>
|
||||
public enum Boolean
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -234,6 +240,9 @@ namespace TermInfo
|
|||
ReturnDoesClrEol = 43,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents known numeric terminfo capabilities.
|
||||
/// </summary>
|
||||
public enum Num
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -432,6 +441,9 @@ namespace TermInfo
|
|||
NumberOfFunctionKeys = 38,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents known string terminfo capabilities.
|
||||
/// </summary>
|
||||
public enum String
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TermInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a parsed terminfo description.
|
||||
/// </summary>
|
||||
public sealed partial class TermInfoData
|
||||
{
|
||||
private readonly string[] _names;
|
||||
private readonly bool[] _booleans;
|
||||
private readonly int[] _nums;
|
||||
private readonly string[] _strings;
|
||||
private readonly string?[] _strings;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the names of the parsed terminfo description.
|
||||
/// </summary>
|
||||
public string[] Names => _names;
|
||||
|
||||
internal TermInfoData(string[] names, bool[] booleans, int[] nums, string[] strings)
|
||||
internal TermInfoData(string[] names, bool[] booleans, int[] nums, string?[] strings)
|
||||
{
|
||||
_names = names;
|
||||
_booleans = booleans;
|
||||
|
@ -24,6 +27,11 @@ namespace TermInfo
|
|||
_strings = strings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads terminfo description from a stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream to read from.</param>
|
||||
/// <returns>The parsed terminfo description.</returns>
|
||||
public static TermInfoData Read(Stream stream)
|
||||
{
|
||||
if (stream is null)
|
||||
|
@ -34,6 +42,11 @@ namespace TermInfo
|
|||
return Parser.Parse(stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific boolean terminfo capability value.
|
||||
/// </summary>
|
||||
/// <param name="value">The capability to get the value for.</param>
|
||||
/// <returns>The terminfo capability value.</returns>
|
||||
public bool? GetBoolean(TermInfoCaps.Boolean value)
|
||||
{
|
||||
if (TryGetBoolean(value, out var result))
|
||||
|
@ -44,7 +57,11 @@ namespace TermInfo
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific numeric terminfo capability value.
|
||||
/// </summary>
|
||||
/// <param name="value">The capability to get the value for.</param>
|
||||
/// <returns>The terminfo capability value.</returns>
|
||||
public int? GetNum(TermInfoCaps.Num value)
|
||||
{
|
||||
if (TryGetNum(value, out var result))
|
||||
|
@ -55,7 +72,12 @@ namespace TermInfo
|
|||
return null;
|
||||
}
|
||||
|
||||
public string GetString(TermInfoCaps.String value)
|
||||
/// <summary>
|
||||
/// Gets a specific string terminfo capability value.
|
||||
/// </summary>
|
||||
/// <param name="value">The capability to get the value for.</param>
|
||||
/// <returns>The terminfo capability value.</returns>
|
||||
public string? GetString(TermInfoCaps.String value)
|
||||
{
|
||||
if (TryGetString(value, out var result))
|
||||
{
|
||||
|
@ -65,7 +87,13 @@ namespace TermInfo
|
|||
return null;
|
||||
}
|
||||
|
||||
public bool TryGetBoolean(TermInfoCaps.Boolean value, out bool? result)
|
||||
/// <summary>
|
||||
/// Tries to get a specific boolean terminfo capability value.
|
||||
/// </summary>
|
||||
/// <param name="value">The capability to get the value for.</param>
|
||||
/// <param name="result">The terminfo capability value, or <c>null</c> if missing.</param>
|
||||
/// <returns><c>true</c> if the capability was found, otherwise <c>false</c>.</returns>
|
||||
public bool TryGetBoolean(TermInfoCaps.Boolean value, [NotNullWhen(true)] out bool? result)
|
||||
{
|
||||
var index = (int)value;
|
||||
if (index >= _booleans.Length)
|
||||
|
@ -78,7 +106,13 @@ namespace TermInfo
|
|||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetNum(TermInfoCaps.Num value, out int? result)
|
||||
/// <summary>
|
||||
/// Tries to get a specific numeric terminfo capability value.
|
||||
/// </summary>
|
||||
/// <param name="value">The capability to get the value for.</param>
|
||||
/// <param name="result">The terminfo capability value, or <c>null</c> if missing.</param>
|
||||
/// <returns><c>true</c> if the capability was found, otherwise <c>false</c>.</returns>
|
||||
public bool TryGetNum(TermInfoCaps.Num value, [NotNullWhen(true)] out int? result)
|
||||
{
|
||||
var index = (int)value;
|
||||
if (index >= _nums.Length)
|
||||
|
@ -97,7 +131,13 @@ namespace TermInfo
|
|||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetString(TermInfoCaps.String value, out string result)
|
||||
/// <summary>
|
||||
/// Tries to get a specific string terminfo capability value.
|
||||
/// </summary>
|
||||
/// <param name="value">The capability to get the value for.</param>
|
||||
/// <param name="result">The terminfo capability value, or <c>null</c> if missing.</param>
|
||||
/// <returns><c>true</c> if the capability was found, otherwise <c>false</c>.</returns>
|
||||
public bool TryGetString(TermInfoCaps.String value, [NotNullWhen(true)] out string? result)
|
||||
{
|
||||
var index = (int)value;
|
||||
if (index >= _strings.Length)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace TermInfo
|
||||
|
@ -11,7 +11,7 @@ namespace TermInfo
|
|||
public int StringOffsetCount { get; set; }
|
||||
public int StringTableLength { get; set; }
|
||||
|
||||
public static bool TryRead(Stream stream, out TermInfoHeader header)
|
||||
public static bool TryRead(Stream stream, [NotNullWhen(true)] out TermInfoHeader? header)
|
||||
{
|
||||
var magic = stream.ReadShort();
|
||||
if (magic != 282)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
|
||||
"settings": {
|
||||
"documentationRules": {
|
||||
"xmlHeader": false,
|
||||
"documentExposedElements": true,
|
||||
"documentInternalElements": false,
|
||||
"documentPrivateElements": false,
|
||||
"documentPrivateFields": false
|
||||
},
|
||||
"layoutRules": {
|
||||
"newlineAtEndOfFile": "allow",
|
||||
"allowConsecutiveUsings": true
|
||||
},
|
||||
"orderingRules": {
|
||||
"usingDirectivesPlacement": "outsideNamespace",
|
||||
"systemUsingDirectivesFirst": true,
|
||||
"elementOrder": [
|
||||
"kind",
|
||||
"accessibility",
|
||||
"constant",
|
||||
"static",
|
||||
"readonly"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче