1 //
2 // Copyright (c) 2010-2018 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using System;
9 using AntShell;
10 using System.IO;
11 using Antmicro.Renode.UserInterface.Commands;
12 using Antmicro.Renode.Utilities;
13 using AntShell.Terminal;
14 using System.Linq;
15 using Antmicro.Renode.Core;
16 
17 namespace Antmicro.Renode.UserInterface
18 {
19     public static class ShellProvider
20     {
GenerateShell(Monitor monitor, bool forceVCursor = false)21         public static Shell GenerateShell(Monitor monitor, bool forceVCursor = false)
22         {
23             var settings = new ShellSettings {
24                 NormalPrompt = new Prompt("(monitor) ", ConsoleColor.DarkRed),
25                 BannerProvider = () => Enumerable.Repeat(Environment.NewLine, NumberOfDummyLines).Aggregate(String.Empty, (x, y) => x + y) + EmulationManager.Instance.VersionString,
26                 PreprocessSuggestionsInput = Monitor.SanitizePathSeparator,
27                 UseBuiltinQuit = false,
28                 UseBuiltinHelp = false,
29                 UseBuiltinSave = false,
30                 ForceVirtualCursor = forceVCursor,
31                 ClearScreen = false,
32                 DirectorySeparator = '/',
33                 HistorySavePath = ConfigurationManager.Instance.Get("general", "history-path", Path.Combine(Emulator.UserDirectoryPath, "history"))
34             };
35 
36             var shell = new Shell(monitor, settings);
37 
38             var startupCommand = Environment.GetEnvironmentVariable(Monitor.StartupCommandEnv);
39             if(!string.IsNullOrEmpty(startupCommand) && shell != null)
40             {
41                 shell.StartupCommand = startupCommand;
42             }
43 
44             return shell;
45         }
46 
47         public static int NumberOfDummyLines;
48     }
49 }
50 
51