Clean up the API a bit
This commit is contained in:
Родитель
2287b4dc6e
Коммит
0a6bf3e3b9
Двоичный файл не отображается.
|
@ -7,10 +7,12 @@
|
|||
|
||||
<ItemGroup>
|
||||
<None Remove="Data\xterm+256color" />
|
||||
<None Remove="Data\xterm+88color" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Data\xterm+256color" />
|
||||
<EmbeddedResource Include="Data\xterm+88color" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace TermInfo.Tests
|
||||
{
|
||||
public sealed class TermInfoDataTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("xterm+256color", 256)]
|
||||
[InlineData("xterm+88color", 88)]
|
||||
public void Should_Read_MaxColors(string terminfo, int expected)
|
||||
{
|
||||
// Given
|
||||
var stream = EmbeddedResourceReader.LoadResourceStream($"TermInfo.Tests/Data/{terminfo}");
|
||||
|
||||
// When
|
||||
var info = TermInfoData.Read(stream);
|
||||
|
||||
// Then
|
||||
info.MaxColors.ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +1,9 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace TermInfo.Tests
|
||||
{
|
||||
public sealed class ParserTests
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Read_Terminfo_File()
|
||||
{
|
||||
// Given
|
||||
var stream = EmbeddedResourceReader.LoadResourceStream("TermInfo.Tests/Data/xterm+256color");
|
||||
|
||||
// When
|
||||
var info = TermInfoData.Read(stream);
|
||||
|
||||
// Then
|
||||
info.MaxColors.ShouldBe(256);
|
||||
info.AutoLeftMargin.ShouldBe(false);
|
||||
info.OrigColors.ShouldBe("\u001b]104\a");
|
||||
}
|
||||
}
|
||||
|
||||
public static class EmbeddedResourceReader
|
||||
{
|
||||
public static Stream LoadResourceStream(string resourceName)
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
namespace TermInfo
|
||||
|
@ -49,12 +48,13 @@ namespace TermInfo
|
|||
/// <returns>The terminfo capability value.</returns>
|
||||
public bool? GetBoolean(TermInfoCaps.Boolean value)
|
||||
{
|
||||
if (TryGetBoolean(value, out var result))
|
||||
var index = (int)value;
|
||||
if (index >= _booleans.Length)
|
||||
{
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
return _booleans[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -64,12 +64,19 @@ namespace TermInfo
|
|||
/// <returns>The terminfo capability value.</returns>
|
||||
public int? GetNum(TermInfoCaps.Num value)
|
||||
{
|
||||
if (TryGetNum(value, out var result))
|
||||
var index = (int)value;
|
||||
if (index >= _nums.Length)
|
||||
{
|
||||
return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
var result = _nums[index];
|
||||
if (result == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -78,82 +85,20 @@ namespace TermInfo
|
|||
/// <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))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = _booleans[index];
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = _nums[index];
|
||||
if (result == -1)
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
result = _strings[index];
|
||||
var result = _strings[index];
|
||||
if (result == null)
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче