Skip to content

Commit 11ca2f0

Browse files
author
LoneWandererProductions
committed
fix some small fry in my interpreter and prepare it to be used in my CoreConsole.
1 parent adcfffe commit 11ca2f0

9 files changed

Lines changed: 73 additions & 22 deletions

File tree

0 Bytes
Loading
0 Bytes
Loading

CoreConsole/ConResources.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,36 @@ internal static class ConResources
8484
}
8585
};
8686

87+
/// <summary>
88+
/// For commands that need your feedback
89+
/// </summary>
90+
internal static readonly Dictionary<int, UserFeedback> Feedback = new() { { 1, ReplaceFeedback } };
91+
92+
internal static readonly Dictionary<int, InCommand> ExtensionCommands = new()
93+
{
94+
{
95+
Header, new InCommand
96+
{
97+
Command = "dryrun",
98+
ParameterCount = 0,
99+
FeedbackId =1,
100+
Description =
101+
"Show results and optional run commands"
102+
}
103+
}
104+
};
105+
106+
private static readonly UserFeedback ReplaceFeedback = new()
107+
{
108+
Before = true,
109+
Message = "Do you want to commit the following changes?",
110+
Options = new Dictionary<AvailableFeedback, string>
111+
{
112+
{ AvailableFeedback.Yes, "If you want to execute the Command type yes" },
113+
{ AvailableFeedback.No, " If you want to stop executing the Command type no." }
114+
}
115+
};
116+
87117
/// <summary>
88118
/// The resource1
89119
/// </summary>

InterpreteTests/FeedbackTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ public sealed class FeedbackTests
2929
/// </summary>
3030
private static OutCommand _outCommand;
3131

32-
/// <summary>
33-
/// The user feedback
34-
/// </summary>
35-
private readonly Dictionary<int, UserFeedback> _userFeedback = new();
36-
3732
/// <summary>
3833
/// Feedback and extension test.
3934
/// </summary>

Interpreter/ExtensionCommands.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public sealed class ExtensionCommands
3434
/// Gets or sets the parameter.
3535
/// </summary>
3636
public List<string> ExtensionParameter { get; internal set; }
37+
/// <summary>
38+
/// Gets the feedback identifier.
39+
/// Define the feedback id
40+
/// </summary>
41+
/// <value>
42+
/// The feedback identifier.
43+
/// </value>
44+
public int FeedBackId { get; internal set; }
3745

3846
/// <summary>
3947
/// Gets or sets the base command.

Interpreter/IrtConst.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ internal static class IrtConst
298298
/// </summary>
299299
internal const char AdvancedOpen = '{';
300300

301-
302301
/// <summary>
303302
/// The close Clause, Standard is')'
304303
/// </summary>
@@ -394,7 +393,7 @@ internal static class IrtConst
394393
Options = new Dictionary<AvailableFeedback, string>
395394
{
396395
{ AvailableFeedback.Yes, "If you want to execute the Command type yes" },
397-
{ AvailableFeedback.No, " if you want to stop executing the Command." }
396+
{ AvailableFeedback.No, " If you want to stop executing the Command type no." }
398397
}
399398
};
400399

@@ -582,7 +581,6 @@ internal static class IrtConst
582581
}
583582
};
584583

585-
586584
/// <summary>
587585
/// Basic internal Help
588586
/// </summary>
@@ -627,6 +625,7 @@ private static string HelpInfo()
627625
);
628626
}
629627

628+
//TODO build everthing as a query with goto and if else
630629
//TODO add repeat as internal replacement for while
631630
//TODO add while
632631
//TODO add void Sub Procedure.

Interpreter/IrtExtension.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ private static (ExtensionCommands Extension, int Status) ProcessExtension(string
9292
// Check for parameter overload
9393
var overloadCheck = IrtKernel.CheckOverload(extensionCommands[commandKey].Command, parameters.Count,
9494
extensionCommands);
95+
9596
if (overloadCheck == null)
9697
{
9798
return (null, IrtConst.ParameterMismatch);
@@ -104,6 +105,8 @@ private static (ExtensionCommands Extension, int Status) ProcessExtension(string
104105
exCommand.ExtensionNameSpace = nameSpace;
105106
exCommand.ExtensionCommand = commandKey;
106107
exCommand.ExtensionParameter = parameters;
108+
//get the feedback id
109+
exCommand.FeedBackId = extensionCommands[commandKey].FeedbackId;
107110
exCommand.BaseCommand = baseCommand;
108111

109112
return (exCommand, IrtConst.ExtensionFound);

Interpreter/IrtHandleExtensionInternal.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ internal sealed class IrtHandleExtensionInternal : IDisposable
2929
/// </summary>
3030
private Dictionary<int, InCommand> _commands;
3131

32+
/// <summary>
33+
/// The user feedback, only for external extensions.
34+
/// </summary>
35+
private Dictionary<int, UserFeedback> _userFeedback;
36+
3237
/// <summary>
3338
/// Indicates whether the object has been disposed.
3439
/// </summary>
@@ -57,18 +62,20 @@ private IrtHandleExtensionInternal()
5762
}
5863

5964
/// <summary>
60-
/// Initializes a new instance of the <see cref="IrtHandleExtensionInternal" /> class with specified parameters.
65+
/// Initializes a new instance of the <see cref="IrtHandleExtensionInternal" /> class with specified parameters.
6166
/// </summary>
6267
/// <param name="irtPrompt">Instance of IrtParser.</param>
6368
/// <param name="commands">Dictionary of commands.</param>
6469
/// <param name="prompt">Instance of Prompt.</param>
6570
/// <param name="irtInternal">Instance of IrtHandleInternal.</param>
71+
/// <param name="userFeedback">The user feedback.</param>
6672
public IrtHandleExtensionInternal(IrtParserInput irtPrompt, Dictionary<int, InCommand> commands, Prompt prompt,
67-
IrtHandleInternal irtInternal)
73+
IrtHandleInternal irtInternal, Dictionary<int, UserFeedback> userFeedback = null)
6874
{
6975
_irtHandlePrompt = irtPrompt;
7076
_commands = commands;
7177
_prompt = prompt;
78+
_userFeedback = userFeedback;
7279
_prompt.HandleFeedback += HandleFeedback;
7380
_myRequestId = Guid.NewGuid().ToString();
7481
_irtHandleInternal = irtInternal;
@@ -119,13 +126,14 @@ internal void ProcessExtensionInternal(ExtensionCommands extension)
119126
private void ProcessHelpCommand(ExtensionCommands extension)
120127
{
121128
var key = IrtKernel.CheckForKeyWord(extension.BaseCommand, IrtConst.InternCommands);
129+
122130
if (key != IrtConst.Error)
123131
{
124132
HandleInternalCommand(extension, key);
125133
}
126134
else
127135
{
128-
HandleExternalCommand(extension);
136+
HandleExternalCommand(extension, _userFeedback);
129137
}
130138
}
131139

@@ -144,28 +152,36 @@ private void HandleInternalCommand(ExtensionCommands extension, int key)
144152
irtInternal.ProcessInput(IrtConst.InternalHelpWithParameter, command.Command);
145153
}
146154

147-
var feedback = IrtConst.InternalFeedback[-1];
148-
var feedbackReceiver = new IrtFeedback
155+
//if none is avaiable use the standard one from Internal
156+
//if not we use the provided one
157+
if (_userFeedback?.TryGetValue(extension.FeedBackId, out var feedback) != true)
149158
{
150-
RequestId = _myRequestId,
151-
Feedback = feedback,
152-
BranchId = 11,
153-
Key = key,
154-
Command = extension.BaseCommand
155-
};
159+
feedback = IrtConst.InternalFeedback[-1];
160+
}
161+
162+
var feedbackReceiver = new IrtFeedback
163+
{
164+
RequestId = _myRequestId,
165+
Feedback = feedback,
166+
BranchId = 11,
167+
Key = key,
168+
Command = extension.BaseCommand
169+
};
170+
156171
_prompt.RequestFeedback(feedbackReceiver);
157172
}
158173

159174
/// <summary>
160175
/// Handles external commands.
161176
/// </summary>
162177
/// <param name="extension">The extension command.</param>
163-
private void HandleExternalCommand(ExtensionCommands extension)
178+
private void HandleExternalCommand(ExtensionCommands extension, Dictionary<int, UserFeedback> userFeedback)
164179
{
165180
var com = _irtHandlePrompt.ProcessInput(extension.BaseCommand);
166181
var command = _commands[com.Command];
167182
_irtHandleInternal.ProcessInput(IrtConst.InternalHelpWithParameter, command.Command);
168183

184+
//TODO completly wrong here
169185
var feedback = IrtConst.InternalFeedback[-1];
170186

171187
var feedbackReceiver = new IrtFeedback

Interpreter/IrtParserInput.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal sealed class IrtParserInput : IDisposable
3434
/// <summary>
3535
/// Extension Command Register
3636
/// </summary>
37-
private static Dictionary<int, InCommand> _extension;
37+
private static Dictionary<int, InCommand>? _extension;
3838

3939
/// <summary>
4040
/// My request identifier
@@ -125,7 +125,7 @@ internal void Initiate(UserSpace use)
125125
_irtExtension = new IrtExtension();
126126
_irtHandleInternal = new IrtHandleInternal(use.Commands, use.UserSpaceName, _prompt);
127127
_irtHandleExtensionInternal =
128-
new IrtHandleExtensionInternal(this, use.Commands, _prompt, _irtHandleInternal);
128+
new IrtHandleExtensionInternal(this, use.Commands, _prompt, _irtHandleInternal, _userFeedback);
129129

130130
// Notify log about loading up
131131
var log = Logging.SetLastError(IrtConst.InformationStartup, 2);

0 commit comments

Comments
 (0)