Skip to content

Commit

Permalink
Merge pull request #13 from pyrretsoftware/axellse-4
Browse files Browse the repository at this point in the history
better support for linux and a brand new pallete system
  • Loading branch information
axellse authored Feb 16, 2024
2 parents 8544981 + a56dff3 commit 66e99e0
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 34 deletions.
Binary file modified TerminalPilot/.vs/TerminalPilot/v17/.suo
Binary file not shown.
8 changes: 4 additions & 4 deletions TerminalPilot/Classes/DevAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public static void InitAuth(string command)
{
if (ConfigManager.GetUserToken() != String.Empty)
{
Console.WriteLine("You are already authenticated!".Pastel(Color.FromArgb(255, 115, 96, 223)));
Console.WriteLine("You are already authenticated!".Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Small1)));
return;
}
if (command.Split(' ').Length > 2)
{
if (command.Split(' ')[2] == "logout")
{
ConfigManager.SetUserToken(null);
Console.WriteLine("You have been logged out.".Pastel(Color.FromArgb(255, 115, 96, 223)));
Console.WriteLine("You have been logged out.".Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Small1)));
return;
}
}
Expand All @@ -81,12 +81,12 @@ public static void InitAuth(string command)
};
System.Diagnostics.Process.Start(psi);
Console.WriteLine();
Console.WriteLine("Head over to your browser window and complete the authentication.".Pastel(Color.FromArgb(255, 115, 96, 223)));
Console.WriteLine("Head over to your browser window and complete the authentication.".Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Large)));
var usertokenpromise = GetUserTokenLoop(exchangeToken);
usertokenpromise.Wait();
var usertoken = usertokenpromise.Result.UserToken;
Console.WriteLine();
Console.WriteLine("Authentication complete!".Pastel(Color.FromArgb(255, 115, 96, 223)));
Console.WriteLine("Authentication complete!".Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Large)));
//save the user token with the config manager
ConfigManager.SetUserToken(usertoken);
}
Expand Down
70 changes: 70 additions & 0 deletions TerminalPilot/Classes/Palletes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TerminalPilot.Enums;
using TerminalPilot.Parser;

namespace TerminalPilot.Classes
{
//base class
public class Palletes {
public class PalleteClass
{
public Color LargeColor { get; set; }
public Color SmallColor1 { get; set; }
public Color SmallColor2 { get; set; }
public Color SmallColor3 { get; set; }
}

public static string CurrentPallete = "NeonPurple";

public static Color GetCurrentPallete(PalleteType type)
{
PalleteClass currentpallete = IncludedPalletes[CurrentPallete];
if (type == PalleteType.Large)
{
return currentpallete.LargeColor;
}
else if (type == PalleteType.Small1)
{
return currentpallete.SmallColor1;
}
else if (type == PalleteType.Small2)
{
return currentpallete.SmallColor2;
}
else if (type == PalleteType.Small3)
{
return currentpallete.SmallColor3;
}
return Color.White;
}
public static void SetCurrentPallete(string pallete)
{
CurrentPallete = pallete;
}
public static Dictionary<string, PalleteClass> IncludedPalletes = new Dictionary<string, PalleteClass>()
{
//neon purple (defualt and my favorite)
{"NeonPurple", new PalleteClass()
{
LargeColor = Color.FromArgb(0, 101, 40, 247),
SmallColor1 = Color.FromArgb(0, 160, 118, 249),
SmallColor2 = Color.FromArgb(0, 215, 187, 245),
SmallColor3 = Color.FromArgb(0, 237, 228, 255),
}},
// sunset pastel
{"SunsetPastel", new PalleteClass()
{
LargeColor = Color.FromArgb(0, 101, 40, 247),
SmallColor1 = Color.FromArgb(0, 160, 118, 249),
SmallColor2 = Color.FromArgb(0, 215, 187, 245),
SmallColor3 = Color.FromArgb(0, 237, 228, 255),
}
}
};
}
}
2 changes: 1 addition & 1 deletion TerminalPilot/Classes/ParserConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ namespace TerminalPilot.Classes
{
public class ParserConfig
{
public string linefeed = "{PATH}" + ">".Pastel(Color.FromArgb(51, 255, 82));
public string linefeed = "{USERPATH}{AFTERUSERPATH}" + ">".Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Large));
}
}
11 changes: 11 additions & 0 deletions TerminalPilot/Enums/PalleteType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TerminalPilot.Enums
{
public enum PalleteType
{
Large,
Small1,
Small2,
Small3

}
}
40 changes: 40 additions & 0 deletions TerminalPilot/OSSupport/AutomaticConfigConfigurer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using TerminalPilot.Classes;

namespace TerminalPilot.OSSupport
{
public class AutomaticConfigConfigurer
{
public static void StartupConfigure()
{
//check if were on a unix system
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
//options are
// /bin/bash
// custom
ConfigManager.SetShell("/bin/bash", "-c \"{COMMAND}\"");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
//options are
// cmd
// powershell
// custom
ConfigManager.SetShell("cmd.exe", "/c \"{COMMAND}\"");
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
//options are
// zsh
// /bin/bash
// custom
ConfigManager.SetShell("/bin/zsh", "-c \"{COMMAND}\"");
}
}
}
}
33 changes: 16 additions & 17 deletions TerminalPilot/Parser/Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ public class Command
}
public class Interpreter
{

public static Command[] TerminalPilotCommands = new Command[] {
new Command() {
StartIdentifier = "serial",
Tip = "Use the command 'pilot serial [Port] [Baudrate]' to open a terminal serial connection.",
Example = "pilot serial COM10 9600"
},
new Command() {
StartIdentifier = "auth",
Tip = "Use the command 'pilot auth' to authenticate with your GitHub account, and get access to tons of cool features.",
Example = "pilot auth"
},
new Command() {
StartIdentifier = "config",
Tip = "use the command 'pilot config [Mode] [Key] [Value]' to set or get a config parameter.",
Example = "pilot config get Shell"
}
};
new Command() {
StartIdentifier = "serial",
Tip = "Use the command 'pilot serial [Port] [Baudrate]' to open a terminal serial connection.",
Example = "pilot serial COM10 9600"
},
new Command() {
StartIdentifier = "auth",
Tip = "Use the command 'pilot auth' to authenticate with your GitHub account, and get access to tons of cool features.",
Example = "pilot auth"
},
new Command() {
StartIdentifier = "config",
Tip = "use the command 'pilot config [Mode] [Key] [Value]' to set or get a config parameter.",
Example = "pilot config get Shell"
}
};
public static InputType DetermineInputType(string startcommand, TerminalInstance instance)
{
if ("pilot" == startcommand.Split(' ')[0])
Expand Down
28 changes: 21 additions & 7 deletions TerminalPilot/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ public static void NewLine(TerminalInstance instance)
{
ParserConfig config = new ParserConfig();
Console.WriteLine();
Console.Write(config.linefeed.Replace("{PATH}", instance.Workingdirectory.FullName));
string AfterUserPath = instance.Workingdirectory.FullName.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "");
string UserPathAndBefore = instance.Workingdirectory.FullName.Replace(AfterUserPath, "");
Console.Write(config.linefeed.Replace("{PATH}", UserPathAndBefore.Pastel(Palletes.GetCurrentPallete(PalleteType.Small1))) + AfterUserPath.Pastel(Palletes.GetCurrentPallete(PalleteType.Large)));
}
public static string GetNewLine(TerminalInstance instance)
{
ParserConfig config = new ParserConfig();
string AfterUserPath = instance.Workingdirectory.FullName.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "");
string UserPathAndBefore = instance.Workingdirectory.FullName.Replace(AfterUserPath, "");
return config.linefeed.Replace("{USERPATH}", UserPathAndBefore.Pastel(Palletes.GetCurrentPallete(PalleteType.Large))).Replace("{AFTERUSERPATH}", AfterUserPath.Pastel(Palletes.GetCurrentPallete(PalleteType.Small1)));
}
public void StartParse(TerminalInstance instance)
{
Expand Down Expand Up @@ -76,7 +85,9 @@ void messagetip(string message)
string _tempflag_pathbeforedireditor = "";
string _tempflag_linecursorleft = "";
Console.WriteLine();
Console.Write(parseconfig.linefeed.Replace("{PATH}", instance.Workingdirectory.FullName));
string AfterUserPath = instance.Workingdirectory.FullName.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "");
string UserPathAndBefore = instance.Workingdirectory.FullName.Replace(AfterUserPath, "");
Console.Write(GetNewLine(instance));
_tempflag_deletelimit = Console.CursorLeft;
_tempflag_deletelimity = Console.CursorTop;
while (instance.alive == true)
Expand All @@ -99,7 +110,7 @@ void messagetip(string message)
Console.WriteLine();
Interpreter.InterpreteCommand(_tempflag_commandwinput, instance);
_tempflag_commandwinput = "";
Console.Write(parseconfig.linefeed.Replace("{PATH}", instance.Workingdirectory.FullName));
Console.Write(GetNewLine(instance));
_tempflag_deletelimit = Console.CursorLeft;
_tempflag_deletelimity = Console.CursorTop;

Expand All @@ -117,7 +128,10 @@ void messagetip(string message)

instance.Workingdirectory = instance.Workingdirectory.Parent;
RemoveConsoleLine(Console.CursorTop);
Console.Write(parseconfig.linefeed.Replace("{PATH}", instance.Workingdirectory.FullName).Replace(">", OsDirectoryManager.GetOsBackSpaceString()));
Console.WriteLine();
AfterUserPath = instance.Workingdirectory.FullName.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "");
UserPathAndBefore = instance.Workingdirectory.FullName.Replace(AfterUserPath, "");
Console.Write(GetNewLine(instance).Replace(">", OsDirectoryManager.GetOsBackSpaceString()));
_tempflag_deletelimit = Console.CursorLeft;
_tempflag_deletelimity = Console.CursorTop;

Expand All @@ -131,7 +145,7 @@ void messagetip(string message)
//enter dir editor
messagetip("You are in directory editor. to exit, press tab.");
RemoveConsoleLine(Console.CursorTop);
Console.Write(parseconfig.linefeed.Replace("{PATH}", instance.Workingdirectory.FullName).Replace(">", @""));
Console.Write(GetNewLine(instance).Replace(">", @""));
Console.CursorLeft = _disposableflag_cursorpos - 1;

}
Expand Down Expand Up @@ -204,15 +218,15 @@ void messagetip(string message)
{
_grammarflag_plural = " directories";
}
Console.WriteLine("Successfully created " + _disposableflag_dirscreated.ToString().Pastel(Color.Aqua) + _grammarflag_plural);
Console.WriteLine("Successfully created " + _disposableflag_dirscreated.ToString().Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Small1)) + _grammarflag_plural);
instance.Workingdirectory = dirinf;
}
}
else
{
instance.Workingdirectory = dirinf;
}
Console.Write(parseconfig.linefeed.Replace("{PATH}", instance.Workingdirectory.FullName));
Console.Write(GetNewLine(instance));
_tempflag_deletelimit = Console.CursorLeft;
}
else
Expand Down
13 changes: 10 additions & 3 deletions TerminalPilot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Pastel;
using TerminalPilot.Classes;
using TerminalPilot.OSSupport;
namespace TerminalPilot
{
internal class Program
Expand All @@ -22,18 +23,24 @@ static void Main(string[] args)
Configuration config = new Configuration();
OSVariables os = new OSVariables();

if (ConfigManager.GetShell() == "")
{
AutomaticConfigConfigurer.StartupConfigure();
instance.Shell = ConfigManager.GetShell();
instance.ShellCommandArgument = ConfigManager.GetShellArgument();
}
//handle defualt shell


instance.Workingdirectory = new DirectoryInfo(config.StartUpPath);
ConfigManager.StartUp();
Console.Clear();
instance.alive = true;
instance.name = "Terminal";
Console.WriteLine("TerminalPilot".Pastel(Color.Aqua) + ", Version " + Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine("TerminalPilot".Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Large)) + ", Version " + Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine("From pyrret, Under MIT License.");
Console.WriteLine();
Console.WriteLine("Current Shell: " + instance.Shell.Pastel(Color.Aqua));
Console.WriteLine("Current Shell: " + instance.Shell.Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Small1)) + ". You can change it with " + "'pilot shell'".Pastel(Palletes.GetCurrentPallete(Enums.PalleteType.Small1)));
Parser.Parser parser = new Parser.Parser();
parser.StartParse(instance);

Expand Down
4 changes: 2 additions & 2 deletions TerminalPilot/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<add key="SpecialColor2" value="R,G,B" /><!--Used mainly for success messages, beutiful and vibrant colors are good-->
<add key="SpecialColor3" value="R,G,B" /><!--Used mainly for stuff related to terminalpilot, beutiful and vibrant colors are good-->
<!--Shell-->
<add key="Shell" value="Cmd.exe" />
<add key="ShellArgument" value=" /c &quot;{COMMAND}&quot;" />
<add key="Shell" value="" />
<add key="ShellArgument" value="" />
<!--Authentication-->
<add key="UserToken" value="" />
</appSettings>
Expand Down

0 comments on commit 66e99e0

Please sign in to comment.