-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicReplContext.cs
More file actions
46 lines (37 loc) · 1.6 KB
/
BasicReplContext.cs
File metadata and controls
46 lines (37 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.CommandLine.Invocation;
using System.CommandLine;
using ClifferBasic.Services;
using Cliffer;
using System.Reflection;
namespace ClifferBasic;
internal class BasicReplContext(Command currentCommand) : Cliffer.DefaultReplContext(currentCommand) {
private readonly CommandSplitter _splitter = Utility.GetService<CommandSplitter>()!;
private readonly ProgramService _programService = Utility.GetService<ProgramService>()!;
public override string TitleMessage {
get {
Assembly assembly = Assembly.GetExecutingAssembly();
Version? version = assembly.GetName().Version;
string versionString = version?.ToString() ?? "Unknown";
return $"Cliffer Basic v{versionString}";
}
}
public override string GetPrompt(Command command, InvocationContext context) => "> ";
public override string[] ExitCommands => ["bye", "exit", "goodbye"];
public override string[] PopCommands => [];
public override void OnEntry() {
base.OnEntry();
}
public override string[] SplitCommandLine(string input) {
return _splitter.Split(input).ToArray();
}
public override Task<int> RunAsync(Command command, string[] args) {
if (args.Length > 1) {
if (int.TryParse(args[0], out int lineNumber)) {
_programService.SetLine(lineNumber, args.Skip(1).ToArray());
return Task.FromResult(Result.Success);
}
}
ClifferEventHandler.PreprocessArgs(args);
return base.RunAsync(command, args);
}
}