Skip to content

Commit

Permalink
Prep for Terminal upgrade
Browse files Browse the repository at this point in the history
* Rename OkTools.Core.Terminal -> just OkTools.Terminal
* Start on an OkTools.Terminal package
* Got warning-clean in Rider
* Switched from .net 7 to 9 support (kept 8)
  • Loading branch information
scottbilas committed Nov 26, 2024
1 parent c2f5789 commit 3e0f6f5
Show file tree
Hide file tree
Showing 35 changed files with 163 additions and 125 deletions.
4 changes: 2 additions & 2 deletions OkTools-Working.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lyfe.Cli", "src\Lyfe.Cli\Ly
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lyfe.Cli-Tests", "src\Lyfe.Cli\Lyfe.Cli-Tests.csproj", "{C875B7D7-7FF4-4732-9FE0-A7A35D077F94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Terminal", "src\Core.Terminal\Core.Terminal.csproj", "{D6D04E0D-8325-4BDF-B4E8-2CBFF54764DE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal", "src\Terminal\Terminal.csproj", "{D6D04E0D-8325-4BDF-B4E8-2CBFF54764DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Terminal-Tests", "src\Core.Terminal\Core.Terminal-Tests.csproj", "{CB4C57D5-478F-4066-BC7A-2C2F42F36109}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal-Tests", "src\Terminal\Terminal-Tests.csproj", "{CB4C57D5-478F-4066-BC7A-2C2F42F36109}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 2 additions & 2 deletions OkTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lyfe.Cli", "src\Lyfe.Cli\Ly
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lyfe.Cli-Tests", "src\Lyfe.Cli\Lyfe.Cli-Tests.csproj", "{C875B7D7-7FF4-4732-9FE0-A7A35D077F94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Terminal", "src\Core.Terminal\Core.Terminal.csproj", "{D6D04E0D-8325-4BDF-B4E8-2CBFF54764DE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal", "src\Terminal\Terminal.csproj", "{D6D04E0D-8325-4BDF-B4E8-2CBFF54764DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Terminal-Tests", "src\Core.Terminal\Core.Terminal-Tests.csproj", "{CB4C57D5-478F-4066-BC7A-2C2F42F36109}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal-Tests", "src\Terminal\Terminal-Tests.csproj", "{CB4C57D5-478F-4066-BC7A-2C2F42F36109}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stale.Cli-Tests", "src\Stale.Cli\Stale.Cli-Tests.csproj", "{12C369B7-DF63-4E2A-8638-AAAEB8F7CAAC}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions Stale.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flog", "src\Flog\Flog.cspro
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flog.Cli", "src\Flog.Cli\Flog.Cli.csproj", "{8B492F02-DFFE-49A0-91FA-2F7D6DAFC96B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Terminal", "src\Core.Terminal\Core.Terminal.csproj", "{97404C8D-5AF4-4421-952C-0942D453D692}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal", "src\Terminal\Terminal.csproj", "{97404C8D-5AF4-4421-952C-0942D453D692}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Terminal-Tests", "src\Core.Terminal\Core.Terminal-Tests.csproj", "{85998317-0436-45AD-A4CB-278EC8055ADD}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal-Tests", "src\Terminal\Terminal-Tests.csproj", "{85998317-0436-45AD-A4CB-278EC8055ADD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stale.Cli-Tests", "src\Stale.Cli\Stale.Cli-Tests.csproj", "{3D3084A6-EE49-4911-9C26-BAA0CDF997DC}"
EndProject
Expand Down
15 changes: 0 additions & 15 deletions src/Core.Terminal/Core.Terminal.csproj

This file was deleted.

1 change: 0 additions & 1 deletion src/Core/CliUtility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace OkTools.Core;
Expand Down
4 changes: 1 addition & 3 deletions src/Core/CliUtility.t.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Reflection;

class CliUtilityTests
class CliUtilityTests
{
[Test]
public void ParseCommandLineArgs_CommandLineArgsToString()
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RootNamespace>OkTools.Core</RootNamespace>
<TargetFrameworks>$(TargetFrameworks);netstandard2.1</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn);CS1591</NoWarn> <!-- just doing spot-docs -->
<DefineConstants>$(DefineConstants);NICEIO_PUBLIC</DefineConstants>

<!-- because it's a package, avoid adding requirements -->
Expand Down
4 changes: 1 addition & 3 deletions src/Flog.Cli/FlogCli.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using OkTools.Core.Terminal;

const string programVersion = "0.1";
const string programVersion = "0.1";

// fine to use console directly here, it's outside of any tui work
#pragma warning disable RS0030
Expand Down
96 changes: 47 additions & 49 deletions src/Flog.Cli/Utils/InputParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text;
using System.Threading.Channels;
using Vezel.Cathode.Text.Control;

using static Vezel.Cathode.Text.Control.ControlConstants;
enum InputParseResult { Accept, NoMatch, Partial }

class InputParser
Expand Down Expand Up @@ -74,7 +74,7 @@ async void Parse(bool timerExpired)
break;

var b = _input.Read();
if (b != ControlConstants.ESC)
if (b != ESC)
{
// unrecognized sequence or timeout, so push to app to figure it out
await _events.WriteAsync(new CharEvent((char)b, _inEscape, false));
Expand Down Expand Up @@ -142,66 +142,64 @@ public ControlMapping(string input, char ch, bool alt = false, bool ctrl = false
[
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.pdf

new("\x1b[A", ConsoleKey.UpArrow),
new("\x1b[1;5A", ConsoleKey.UpArrow, ctrl: true),
new("\x1b[B", ConsoleKey.DownArrow),
new("\x1b[1;5B", ConsoleKey.DownArrow, ctrl: true),
new("\x1b[C", ConsoleKey.RightArrow),
new("\x1b[1;5C", ConsoleKey.RightArrow, ctrl: true),
new("\x1b[D", ConsoleKey.LeftArrow),
new("\x1b[1;5D", ConsoleKey.LeftArrow, ctrl: true),
new(CSI+"A", ConsoleKey.UpArrow),
new(CSI+"1;5A", ConsoleKey.UpArrow, ctrl: true),
new(CSI+"B", ConsoleKey.DownArrow),
new(CSI+"1;5B", ConsoleKey.DownArrow, ctrl: true),
new(CSI+"C", ConsoleKey.RightArrow),
new(CSI+"1;5C", ConsoleKey.RightArrow, ctrl: true),
new(CSI+"D", ConsoleKey.LeftArrow),
new(CSI+"1;5D", ConsoleKey.LeftArrow, ctrl: true),

new("\x1b[H", ConsoleKey.Home),
new("\x1b[F", ConsoleKey.End),
new(CSI+"H", ConsoleKey.Home),
new(CSI+"F", ConsoleKey.End),

new("\x1b[2~", ConsoleKey.Insert),
new("\x1b[3~", ConsoleKey.Delete),
new(CSI+"2~", ConsoleKey.Insert),
new(CSI+"3~", ConsoleKey.Delete),

new("\x1b[5~", ConsoleKey.PageUp),
new("\x1b[6~", ConsoleKey.PageDown),
new(CSI+"5~", ConsoleKey.PageUp),
new(CSI+"6~", ConsoleKey.PageDown),

new("\x7f", ConsoleKey.Backspace),
new("\r", ConsoleKey.Enter),

new("\x1bOP", ConsoleKey.F1),
new("\x1bOQ", ConsoleKey.F2),
new("\x1bOR", ConsoleKey.F3),
new("\x1bOS", ConsoleKey.F4),
new("\x1b[15~", ConsoleKey.F5),
new("\x1b[17~", ConsoleKey.F6),
new("\x1b[18~", ConsoleKey.F7),
new("\x1b[19~", ConsoleKey.F8),
new("\x1b[20~", ConsoleKey.F9),
new("\x1b[21~", ConsoleKey.F10),
new("\x1b[23~", ConsoleKey.F11),
new("\x1b[24~", ConsoleKey.F12),

new("\x1b[15;2~", ConsoleKey.F5, shift: true),
new("\x1b[17;2~", ConsoleKey.F6, shift: true),
new("\x1b[18;2~", ConsoleKey.F7, shift: true),
new("\x1b[19;2~", ConsoleKey.F8, shift: true),
new("\x1b[20;2~", ConsoleKey.F9, shift: true),
new("\x1b[21;2~", ConsoleKey.F10, shift: true),
new("\x1b[23;2~", ConsoleKey.F11, shift: true),
new("\x1b[24;2~", ConsoleKey.F12, shift: true),
new(ESC+"OP", ConsoleKey.F1),
new(ESC+"OQ", ConsoleKey.F2),
new(ESC+"OR", ConsoleKey.F3),
new(ESC+"OS", ConsoleKey.F4),
new(CSI+"15~", ConsoleKey.F5),
new(CSI+"17~", ConsoleKey.F6),
new(CSI+"18~", ConsoleKey.F7),
new(CSI+"19~", ConsoleKey.F8),
new(CSI+"20~", ConsoleKey.F9),
new(CSI+"21~", ConsoleKey.F10),
new(CSI+"23~", ConsoleKey.F11),
new(CSI+"24~", ConsoleKey.F12),

new(CSI+"15;2~", ConsoleKey.F5, shift: true),
new(CSI+"17;2~", ConsoleKey.F6, shift: true),
new(CSI+"18;2~", ConsoleKey.F7, shift: true),
new(CSI+"19;2~", ConsoleKey.F8, shift: true),
new(CSI+"20;2~", ConsoleKey.F9, shift: true),
new(CSI+"21;2~", ConsoleKey.F10, shift: true),
new(CSI+"23;2~", ConsoleKey.F11, shift: true),
new(CSI+"24;2~", ConsoleKey.F12, shift: true),

// TODO: do a better way of mapping this
// note that ^M == \r == Enter key..could be we really do want Console+CharKey unified..or maybe ctrl-keys are
// *always* a ConsoleKey because they're ctrl sequences. also less confusing when trying to figure out what to
// match against on the receiving side (don't have to look up what ^J or ^M or \r means).
new("\x1", 'a', ctrl: true),
new("\x2", 'b', ctrl: true),
new("\x3", 'c', ctrl: true),
new("\x4", 'd', ctrl: true),
new("\x5", 'e', ctrl: true),
new("\x6", 'f', ctrl: true),
new("\xb", 'k', ctrl: true),
new("\xc", 'l', ctrl: true),
new("\x14", 't', ctrl: true),
new("\x15", 'u', ctrl: true)
new("\x1", 'a', ctrl: true),
new("\x2", 'b', ctrl: true),
new("\x3", 'c', ctrl: true),
new("\x4", 'd', ctrl: true),
new("\x5", 'e', ctrl: true),
new("\x6", 'f', ctrl: true),
new("\xb", 'k', ctrl: true),
new("\xc", 'l', ctrl: true),
new("\x14", 't', ctrl: true),
new("\x15", 'u', ctrl: true)
];
// .Concat()
// .ToArray();

async Task<InputParseResult> ParseControlKey()
{
Expand Down
26 changes: 13 additions & 13 deletions src/Flog.Cli/Views/DisplayLine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

[DebuggerDisplay("\"{Span.Slice(0, Length <= 30 ? Length : 30)}\" (len={Length}, remain={m_chars.Length - Length})")]
[DebuggerDisplay("\"{Span.Slice(0, Length <= 30 ? Length : 30)}\" (len={Length}, remain={_chars.Length - Length})")]
readonly struct DisplayLine
{
DisplayLine(int lineIndex, string chars, int begin, int end)
Expand All @@ -10,23 +10,23 @@ readonly struct DisplayLine
Debug.Assert(end >= 0 && end <= chars.Length);

LineIndex = lineIndex;
m_chars = chars;
m_begin = begin;
m_end = end;
_chars = chars;
_begin = begin;
_end = end;
}

public readonly int LineIndex;

readonly string m_chars;
readonly int m_begin, m_end;
readonly string _chars;
readonly int _begin, _end;

public bool IsValid => m_chars != null;
public int Length => m_end - m_begin;
public int Remain => m_chars.Length - m_end;
public ReadOnlySpan<char> Span => m_chars.AsSpan(m_begin, Length);
public bool IsValid => _chars != null;
public int Length => _end - _begin;
public int Remain => _chars.Length - _end;
public ReadOnlySpan<char> Span => _chars.AsSpan(_begin, Length);

public bool NeedsLeadingTruncateMarker => m_begin != 0;
public bool NeedsTrailingTruncateMarker => m_end != m_chars.Length;
public bool NeedsLeadingTruncateMarker => _begin != 0;
public bool NeedsTrailingTruncateMarker => _end != _chars.Length;

public DisplayLine RemainTruncated(int maxWidth, int truncMarkerWidth)
{
Expand All @@ -36,7 +36,7 @@ public DisplayLine RemainTruncated(int maxWidth, int truncMarkerWidth)
if (width > maxWidth)
width = maxWidth - truncMarkerWidth;

return new(LineIndex, m_chars, m_end, m_end + width);
return new(LineIndex, _chars, _end, _end + width);
}

public static DisplayLine NewTruncated(int lineIndex, string line, int maxWidth, int truncMarkerWidth)
Expand Down
1 change: 0 additions & 1 deletion src/Loggo.Cli/LoggoCli.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text.RegularExpressions;
using DocoptNet;
using OkTools.Core.Terminal;

#pragma warning disable RS0030 // vezel.cathode warning about Console (haven't converted to vezel yet)

Expand Down
2 changes: 1 addition & 1 deletion src/PmlTool.Cli/PmlToolCli.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DocoptNet;
using OkTools.Core.Terminal;
using OkTools.Terminal;

const string programVersion = "0.1";

Expand Down
8 changes: 4 additions & 4 deletions src/ProcMonUtils/PmlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ void ReadProcessData(long processesOffset)

var processCount = _reader.ReadInt32();
SeekCurrent(processCount * 4); // jump over the process indexes array
var processDataOffsets = new int[processCount];
for (var iprocess = 0; iprocess < processDataOffsets.Length; ++iprocess)
processDataOffsets[iprocess] = _reader.ReadInt32();
//var processDataOffsets = new int[processCount]; // never used this..forget why it's here
//for (var iprocess = 0; iprocess < processDataOffsets.Length; ++iprocess)
// processDataOffsets[iprocess] = _reader.ReadInt32();
PmlProcess? systemProcess = null;
for (var iprocess = 0; iprocess < processDataOffsets.Length; ++iprocess)
for (var iprocess = 0; iprocess < processCount/*processDataOffsets.Length*/; ++iprocess)
{
var processIndex = _reader.ReadInt32(); // The process index (for events to use as a reference to the process)
var processId = _reader.ReadInt32(); // Process id
Expand Down
2 changes: 1 addition & 1 deletion src/Showkeys.Cli/DriveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Channels;
using OkTools.Core.Terminal;
using OkTools.Terminal;
using Vezel.Cathode;
using Vezel.Cathode.Text.Control;

Expand Down
2 changes: 1 addition & 1 deletion src/Showkeys.Cli/DriveUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Drawing;
using OkTools.Core.Terminal;
using OkTools.Terminal;
using Vezel.Cathode.Text.Control;

interface IEvent;
Expand Down
4 changes: 2 additions & 2 deletions src/Showkeys.Cli/ShowkeysCli.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Drawing;
using System.Runtime.CompilerServices;
using DocoptNet;
using OkTools.Core.Terminal;
using OkTools.Terminal;
using Vezel.Cathode.Text.Control;
using static Vezel.Cathode.Terminal;

Expand All @@ -19,7 +19,7 @@ drive Exercise the terminal to see what different vt100 sequences do.
Options:
--dotnet Use the built-in dotnet Console key reader in cooked mode, rather than Cathode (ansi sequences, raw mode).
--ansi Use OkTools.Core.Terminal.AnsiInputReaderReader to receive key events.
--ansi Use OkTools.Terminal.AnsiInputReaderReader to receive key events.
--save Save the screen before entering drive mode and restore it afterwards.
""";

Expand Down
2 changes: 1 addition & 1 deletion src/Stale.Cli/StaleApp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Drawing;
using System.Threading.Channels;
using OkTools.Core.Terminal;
using OkTools.Terminal;
using Spectre.Console;
using Vezel.Cathode.Text.Control;
using Color = Spectre.Console.Color;
Expand Down
2 changes: 1 addition & 1 deletion src/Stale.Cli/Support/Context.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Dumpify;
using OkTools.Core.Terminal;
using OkTools.Terminal;
using Spectre.Console;
using Spectre.Console.Rendering;
using Vezel.Cathode;
Expand Down
2 changes: 1 addition & 1 deletion src/Stale.Cli/UI/StatusPane.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OkTools.Core.Terminal;
using OkTools.Terminal;
using Spectre.Console;
using Vezel.Cathode.Text.Control;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Vezel.Cathode.IO;
using static Vezel.Cathode.Text.Control.ControlConstants;

namespace OkTools.Core.Terminal;
namespace OkTools.Terminal;

// i can get rid of most of this class once this is implemented:
// https://github.com/vezel-dev/cathode/issues/59 "Implement a control sequence parser"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OkTools.Core.Terminal;
namespace OkTools.Terminal;

public static class CharUtils
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OkTools.Core.Terminal;
using OkTools.Terminal;

class CharUtilsTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Vezel.Cathode.Text.Control;
using static Vezel.Cathode.Text.Control.ControlConstants;

namespace OkTools.Core.Terminal.Extensions;
namespace OkTools.Terminal.Extensions;

[PublicAPI]
public static class ControlBuilderExtensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DocoptNet;

namespace OkTools.Core.Terminal.Extensions;
namespace OkTools.Terminal.Extensions;

// ReSharper disable MethodHasAsyncOverload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Spectre.Console.Rendering;
using Vezel.Cathode.Text.Control;

namespace OkTools.Core.Terminal.Extensions;
namespace OkTools.Terminal.Extensions;

[PublicAPI]
public static class SpectreExtensions
Expand Down
Loading

0 comments on commit 3e0f6f5

Please sign in to comment.