Skip to content

Commit 95fa7c2

Browse files
authored
Various bug fixes (#32)
✓ Fix `Systems.Immutable` cascading dependency issue ✓ Fix `clear-history` adding itself to history ✓ Fix extraneous warnings
1 parent d90e27f commit 95fa7c2

26 files changed

Lines changed: 990 additions & 139 deletions

CHANGELOG.md

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,25 @@
1-
Changelog
2-
=========
1+
# Changelog
32

4-
## 1.02 `08a66da` - 2018-09-14
3+
All notable changes to this project will be documented in this file.
54

6-
### Added
7-
- Variables: defined with `set name value`, accessed with `$name`. Run `set` with no arguments to display all variables and their values.
8-
- Option to change the alpha value of the input background texture.
9-
- Command hint argument for better error messages. Use `RegisterCommand(Hint = "Command $a")]` to show a command's usage.
10-
11-
### Changed
12-
- Better autocompletion: autocomplete can now partially complete words when there are multiple suggestions available.
13-
14-
### Fixed
15-
- Fix background texture being destroyed when loading a scene with the Terminal set to `DontDestroyOnLoad`.
16-
- Fix hotkeys bound to function keys causing the input to not register the first character.
17-
- Fix formatting on autocomplete suggestions.
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
186

19-
## 1.01 `9a1b0b3` - 2018-08-09
7+
## [1.0.0-rc25.0] - 2026-03-10
208

219
### Added
22-
- Option to to change the position of the toggle GUI buttons.
23-
- Option to change the window size ratio between the partial and full window height.
24-
- Optional GUI button to run a command (useful for mobile devices).
10+
11+
- Per-command history opt-out: set `AddToHistory = false` on `RegisterCommandAttribute` to prevent a command from being recorded in history. Also available as the `addToHistory` parameter and field on `CommandInfo` and the `addToHistory` parameter on `CommandShell.AddCommand` (all defaulting to `true`).
12+
- `ReadOnlyHashSet<T>` and `ReadOnlyHashSetExtensions` (with `ToReadOnlyHashSet` extension method) in `WallstopStudios.DxCommandTerminal.DataStructures`.
2513

2614
### Changed
27-
- Autocomplete now uses the last word in the input text, rather than just completing the first word.
2815

29-
## 1.0 `db07b43` - 2018-07-15
16+
- `clear-history` command no longer records itself in command history.
17+
- `CommandShell.AutoRegisteredCommands` and `CommandShell.IgnoredCommands` changed type from `ImmutableHashSet<string>` to `ReadOnlyHashSet<string>`.
3018

31-
### Added
32-
- Customizable toggle hotkey.
33-
- Two new terminal colors (customizable).
34-
- Option to change prompt character (or remove it).
35-
- Option to open a larger terminal window with a separate hotkey.
36-
- Command autocompletion (use the tab key while typing a command).
37-
- Option to toggle window using GUI buttons (disabled by default).
38-
- Option to customize the input background contrast.
19+
### Removed
20+
21+
- Bundled `System.Collections.Immutable.dll` has been removed; projects that already reference `System.Collections.Immutable` (e.g. via NuGet or another package) will no longer experience DLL conflicts.
3922

4023
### Fixed
41-
- Input registering hotkey character when hotkey was pressed.
42-
- Inspector presentation.
4324

44-
### Removed
45-
- `LS` command in favor of `HELP` with no arguments to list all registered commands.
25+
- Setting `ignoreDefaultCommands` to `true` on `TerminalUI` had no effect — built-in commands were still registered. Root cause: the `RegisterCommandAttribute` internal constructor was not propagating the `isDefault` parameter to the `Default` property.

Runtime/AssemblyInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("WallstopStudios.DxCommandTerminal.Editor")]
4+
[assembly: InternalsVisibleTo("WallstopStudios.DxCommandTerminal.Tests.Runtime")]

Runtime/AssemblyInfo.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Attributes/RegisterCommandAttribute.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ public sealed class RegisterCommandAttribute : Attribute
1919

2020
public bool DevelopmentOnly { get; set; }
2121

22+
public bool AddToHistory { get; set; } = true;
23+
2224
public RegisterCommandAttribute(string commandName = null)
2325
{
2426
commandName = commandName?.Replace(" ", string.Empty).Trim();
2527
Name = commandName;
2628
}
2729

2830
internal RegisterCommandAttribute(bool isDefault)
29-
: this(string.Empty) { }
31+
: this(string.Empty)
32+
{
33+
Default = isDefault;
34+
}
3035

3136
public void NormalizeName(MethodInfo method)
3237
{

Runtime/CommandTerminal/Backend/BuiltinCommands.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ public static void CommandClearConsole(CommandArg[] args)
267267
isDefault: true,
268268
Name = "clear-history",
269269
Help = "Clear the command console's history",
270-
MaxArgCount = 0
270+
MaxArgCount = 0,
271+
AddToHistory = false
271272
)]
272273
public static void CommandClearHistory(CommandArg[] args)
273274
{

Runtime/CommandTerminal/Backend/CommandHistory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public sealed class CommandHistory
99
{
1010
public int Capacity => _history.Capacity;
1111

12+
public int Count => _history.Count;
13+
1214
private readonly CyclicBuffer<(string text, bool? success, bool? errorFree)> _history;
1315

1416
private int _position;

Runtime/CommandTerminal/Backend/CommandInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ public readonly struct CommandInfo
99
public readonly int maxArgCount;
1010
public readonly string help;
1111
public readonly string hint;
12+
public readonly bool addToHistory;
1213

1314
public CommandInfo(
1415
Action<CommandArg[]> proc,
1516
int minArgCount,
1617
int maxArgCount,
1718
string help,
18-
string hint
19+
string hint,
20+
bool addToHistory = true
1921
)
2022
{
2123
this.proc = proc;
2224
this.maxArgCount = maxArgCount;
2325
this.minArgCount = minArgCount;
2426
this.help = help;
2527
this.hint = hint;
28+
this.addToHistory = addToHistory;
2629
}
2730
}
2831
}

Runtime/CommandTerminal/Backend/CommandShell.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ namespace WallstopStudios.DxCommandTerminal.Backend
22
{
33
using System;
44
using System.Collections.Generic;
5-
using System.Collections.Immutable;
65
using System.Linq;
76
using System.Reflection;
87
using System.Text;
98
using Attributes;
9+
using DataStructures;
1010
using UnityEngine;
1111

1212
public sealed class CommandShell
@@ -117,11 +117,11 @@ public CommandShell(CommandHistory history)
117117
public IReadOnlyDictionary<string, CommandInfo> Commands => _commands;
118118
public IReadOnlyDictionary<string, CommandArg> Variables => _variables;
119119

120-
public ImmutableHashSet<string> AutoRegisteredCommands { get; private set; } =
121-
ImmutableHashSet<string>.Empty;
120+
public ReadOnlyHashSet<string> AutoRegisteredCommands { get; private set; } =
121+
ReadOnlyHashSet<string>.Empty;
122122

123-
public ImmutableHashSet<string> IgnoredCommands { get; private set; } =
124-
ImmutableHashSet<string>.Empty;
123+
public ReadOnlyHashSet<string> IgnoredCommands { get; private set; } =
124+
ReadOnlyHashSet<string>.Empty;
125125

126126
public bool IgnoringDefaultCommands { get; private set; }
127127

@@ -168,7 +168,7 @@ public int ClearAutoRegisteredCommands()
168168
}
169169

170170
_autoRegisteredCommands.Clear();
171-
AutoRegisteredCommands = ImmutableHashSet<string>.Empty;
171+
AutoRegisteredCommands = ReadOnlyHashSet<string>.Empty;
172172
return count;
173173
}
174174

@@ -186,7 +186,7 @@ public void InitializeAutoRegisteredCommands(
186186
_commands.Remove(ignoredCommand);
187187
}
188188

189-
IgnoredCommands = _ignoredCommands.ToImmutableHashSet(StringComparer.OrdinalIgnoreCase);
189+
IgnoredCommands = _ignoredCommands.ToReadOnlyHashSet(StringComparer.OrdinalIgnoreCase);
190190
_rejectedCommands.Clear();
191191

192192
foreach (
@@ -234,15 +234,16 @@ public void InitializeAutoRegisteredCommands(
234234
attribute.MinArgCount,
235235
attribute.MaxArgCount,
236236
attribute.Help,
237-
attribute.Hint
237+
attribute.Hint,
238+
attribute.AddToHistory
238239
);
239240
if (success)
240241
{
241242
_autoRegisteredCommands.Add(commandName);
242243
}
243244
}
244245

245-
AutoRegisteredCommands = _autoRegisteredCommands.ToImmutableHashSet(
246+
AutoRegisteredCommands = _autoRegisteredCommands.ToReadOnlyHashSet(
246247
StringComparer.OrdinalIgnoreCase
247248
);
248249

@@ -296,6 +297,7 @@ public bool RunCommand(string line)
296297

297298
if (_arguments.Count == 0)
298299
{
300+
// No command identified, unconditional push
299301
_history.Push(line, false, true);
300302
return false;
301303
}
@@ -360,6 +362,7 @@ public bool RunCommand(string commandName, CommandArg[] arguments)
360362
if (!_commands.TryGetValue(commandName, out CommandInfo command))
361363
{
362364
IssueErrorMessage($"Command {commandName} not found");
365+
// Unknown command, unconditional push
363366
_history.Push(line, false, false);
364367
return false;
365368
}
@@ -392,13 +395,21 @@ public bool RunCommand(string commandName, CommandArg[] arguments)
392395
}
393396

394397
_errorMessages.Enqueue(invalidMessage);
395-
_history.Push(line, false, false);
398+
// Known command with invalid arguments, respect addToHistory flag
399+
if (command.addToHistory)
400+
{
401+
_history.Push(line, false, false);
402+
}
396403
return false;
397404
}
398405

399406
int errorCount = _errorMessages.Count;
400407
command.proc?.Invoke(arguments);
401-
_history.Push(line, true, errorCount == _errorMessages.Count);
408+
// Known command executed, respect addToHistory flag
409+
if (command.addToHistory)
410+
{
411+
_history.Push(line, true, errorCount == _errorMessages.Count);
412+
}
402413
return true;
403414
}
404415

@@ -432,10 +443,11 @@ public bool AddCommand(
432443
int minArgs = 0,
433444
int maxArgs = -1,
434445
string help = "",
435-
string hint = null
446+
string hint = null,
447+
bool addToHistory = true
436448
)
437449
{
438-
CommandInfo info = new(proc, minArgs, maxArgs, help, hint);
450+
CommandInfo info = new(proc, minArgs, maxArgs, help, hint, addToHistory);
439451
return AddCommand(name, info);
440452
}
441453

Runtime/CommandTerminal/Input/TerminalKeyboardController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ protected virtual void OnValidate()
144144

145145
private void VerifyControlOrderIntegrity()
146146
{
147-
if (!_controlOrder.ToHashSet().SetEquals(ControlTypes))
147+
TerminalControlTypes[] missingControls = ControlTypes.Except(_controlOrder).ToArray();
148+
if (missingControls.Length > 0)
148149
{
149150
Debug.LogWarning(
150-
$"Control Order is missing the following controls: [{string.Join(", ", ControlTypes.Except(_controlOrder))}]. "
151+
$"Control Order is missing the following controls: [{string.Join(", ", missingControls)}]. "
151152
+ "Input for these will not be handled. Is this intentional?",
152153
this
153154
);

Runtime/CommandTerminal/UI/TerminalUI.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
using System.Runtime.CompilerServices;
2-
3-
[assembly: InternalsVisibleTo("WallstopStudios.DxCommandTerminal.Editor")]
4-
51
namespace WallstopStudios.DxCommandTerminal.UI
62
{
73
using System;

0 commit comments

Comments
 (0)