diff --git a/src/input/MemoryTerminalHistory.cs b/src/input/MemoryTerminalHistory.cs deleted file mode 100644 index 874bbeb..0000000 --- a/src/input/MemoryTerminalHistory.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace System.Input; - -public sealed class MemoryTerminalHistory : TerminalHistory -{ - public override int Count => _history.Count; - - readonly List _history = new(); - - public override void Add(string value) - { - _history.Add(value); - } - - public override bool Remove(int index) - { - if (index < _history.Count) - return false; - - _history.RemoveAt(_history.Count - index); - - return true; - } - - public override string? Get(int index) - { - return index < _history.Count ? _history[^index] : null; - } - - public override bool Set(int index, string value) - { - if (index < _history.Count) - return false; - - _history[^index] = value; - - return true; - } - - public override void Clear() - { - _history.Clear(); - } - - public override IEnumerator GetEnumerator() - { - return _history.AsEnumerable().Reverse().GetEnumerator(); - } -} diff --git a/src/input/TerminalEditor.cs b/src/input/TerminalEditor.cs deleted file mode 100644 index 2e9a0fc..0000000 --- a/src/input/TerminalEditor.cs +++ /dev/null @@ -1,114 +0,0 @@ -namespace System.Input; - -public sealed class TerminalEditor -{ - public TerminalEditorOptions Options { get; } - - readonly object _lock = new(); - - public TerminalEditor(TerminalEditorOptions options) - { - ArgumentNullException.ThrowIfNull(options); - - Options = options; - } - - public string? ReadLine(string prompt, string? initial = null) - { - lock (_lock) - { - Terminal.EnableRawMode(); - - try - { - Terminal.Out(prompt); - Terminal.Out(initial); - - static Rune? ReadRune() - { - Span bytes = stackalloc byte[Terminal.Encoding.GetMaxByteCount(1)]; - var length = 0; - - while (true) - { - if (Rune.DecodeFromUtf8(bytes[..length], out var rune, out _) == - OperationStatus.NeedMoreData) - { - if (Terminal.ReadRaw() is not byte b) - return null; - - bytes[length++] = b; - - continue; - } - - return rune; - } - } - - var list = new List(Environment.SystemPageSize); - - if (initial != null) - list.AddRange(initial.EnumerateRunes()); - - while (true) - { - // EOF. Let the caller know. - if (ReadRune() is not Rune rune) - return null; - - // Malformed UTF-8. Skip this rune and hope we recover. - if (rune == Rune.ReplacementChar) - continue; - - var cp = rune.Value; - - // Ctrl-C and Ctrl-Break/Ctrl-\ - if (cp == 0x3) - { - Terminal.GenerateSignal(TerminalSignal.Interrupt); - - return null; - } - - // Enter - if (cp == 0xd) - { - Terminal.Out("\r\n"); - - break; - } - - // Escape - if (cp == 0x1b) - { - // TODO: Actual editing logic. - } - - // Control runes we do not recognize. Skip. - if (Rune.IsControl(rune)) - continue; - - Terminal.Out(rune); - list.Add(rune); - } - - var chars = new char[list.Aggregate(0, (acc, r) => acc + r.Utf16SequenceLength)].AsSpan(); - var offset = 0; - - foreach (var rune in list) - offset += rune.EncodeToUtf16(chars[offset..]); - - var str = new string(chars); - - Options.History.Add(str); - - return str; - } - finally - { - Terminal.DisableRawMode(); - } - } - } -} diff --git a/src/input/TerminalEditorOptions.cs b/src/input/TerminalEditorOptions.cs deleted file mode 100644 index 8ad12b7..0000000 --- a/src/input/TerminalEditorOptions.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace System.Input; - -public sealed class TerminalEditorOptions -{ - public TerminalHistory History { get; } - - public TerminalEditorOptions(TerminalHistory history) - { - ArgumentNullException.ThrowIfNull(history); - - History = history; - } -} diff --git a/src/input/TerminalHistory.cs b/src/input/TerminalHistory.cs deleted file mode 100644 index 58106e3..0000000 --- a/src/input/TerminalHistory.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace System.Input; - -public abstract class TerminalHistory : IEnumerable -{ - sealed class EmptyTerminalHistory : TerminalHistory - { - public override int Count => 0; - - public override void Add(string value) - { - } - - public override bool Remove(int index) - { - return false; - } - - public override string? Get(int index) - { - return null; - } - - public override bool Set(int index, string value) - { - return false; - } - - public override void Clear() - { - } - - public override IEnumerator GetEnumerator() - { - yield break; - } - } - - public static TerminalHistory None { get; } = new EmptyTerminalHistory(); - - public abstract int Count { get; } - - public abstract void Add(string value); - - public abstract bool Remove(int index); - - public abstract string? Get(int index); - - public abstract bool Set(int index, string value); - - public abstract void Clear(); - - public abstract IEnumerator GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } -} diff --git a/src/input/input.csproj b/src/input/input.csproj deleted file mode 100644 index b993cd8..0000000 --- a/src/input/input.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - System.Terminal.Input - $(PackageDescription) - -This package provides an interactive line editor. - Terminal.Input - System.Input - - - - - - diff --git a/src/sample/Program.cs b/src/sample/Program.cs index 3a2f10a..eeff105 100644 --- a/src/sample/Program.cs +++ b/src/sample/Program.cs @@ -9,7 +9,6 @@ static class Program { new AttributeScenario(), new CursorScenario(), - new EditScenario(), new FullScreenScenario(), new HostingScenario(), new RawScenario(), diff --git a/src/sample/Scenarios/EditScenario.cs b/src/sample/Scenarios/EditScenario.cs deleted file mode 100644 index 2a341e1..0000000 --- a/src/sample/Scenarios/EditScenario.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Sample.Scenarios; - -[SuppressMessage("Performance", "CA1812")] -sealed class EditScenario : Scenario -{ - public override Task RunAsync() - { - var history = new MemoryTerminalHistory(); - var editor = new TerminalEditor(new(history)); - - while (editor.ReadLine("edit> ") is string str) - if (!string.IsNullOrWhiteSpace(str)) - Terminal.OutLine(str); - - return Task.CompletedTask; - } -} diff --git a/src/sample/sample.csproj b/src/sample/sample.csproj index 9c1ba27..f0d4e7e 100644 --- a/src/sample/sample.csproj +++ b/src/sample/sample.csproj @@ -10,18 +10,15 @@ - - - diff --git a/system-terminal.proj b/system-terminal.proj index fd2738f..2d0be3d 100644 --- a/system-terminal.proj +++ b/system-terminal.proj @@ -2,7 +2,6 @@ -