Files
FluentTerminal/FluentTerminal.Models/ShellProfile.cs
T
Aleksandar Pesic 4ec9f0a5a6 Implementing remote SSH profiles, 2nd attempt (#395)
* Implementing remote SSH profiles.

* Fixing async terminal adds.

* Improving behavior when new window is requested.

* Minor changes.

* Move ssh profiles to roaming, rename sshshellprofile to sshprofile
2019-06-07 00:22:45 +02:00

101 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using FluentTerminal.Models.Enums;
using System.Linq;
namespace FluentTerminal.Models
{
public class ShellProfile
{
/// <summary>
/// Replace all instances of anything resembling a newline, treating pairs of \r\n in either order as a single linebreak.
/// </summary>
public static Regex NewlinePattern = new Regex(@"\n\r|\r\n|\r|\n", RegexOptions.Compiled);
public ShellProfile()
{
}
public ShellProfile(ShellProfile other)
{
Id = other.Id;
PreInstalled = other.PreInstalled;
Name = other.Name;
Arguments = other.Arguments;
Location = other.Location;
WorkingDirectory = other.WorkingDirectory;
TabThemeId = other.TabThemeId;
TerminalThemeId = other.TerminalThemeId;
LineEndingTranslation = other.LineEndingTranslation;
UseConPty = other.UseConPty;
KeyBindings = other.KeyBindings.Select(x => new KeyBinding(x)).ToList();
}
public Guid Id { get; set; }
public bool PreInstalled { get; set; }
public string Name { get; set; }
public string Arguments { get; set; }
public string Location { get; set; }
public string WorkingDirectory { get; set; }
public int TabThemeId { get; set; }
public LineEndingStyle LineEndingTranslation { get; set; }
public Dictionary<string, string> EnvironmentVariables { get; } = new Dictionary<string, string>();
public bool UseConPty { get; set; }
public string TranslateLineEndings(string content)
{
switch (LineEndingTranslation)
{
case LineEndingStyle.ToCR:
return NewlinePattern.Replace(content, "\r");
case LineEndingStyle.ToCRLF:
return NewlinePattern.Replace(content, "\r\n");
case LineEndingStyle.ToLF:
return NewlinePattern.Replace(content, "\n");
case LineEndingStyle.DoNotModify:
default:
return content;
}
}
public Guid TerminalThemeId { get; set; }
public ICollection<KeyBinding> KeyBindings { get; set; } = new List<KeyBinding>();
public virtual bool EqualTo(ShellProfile other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return other.Id.Equals(Id)
&& other.PreInstalled.Equals(PreInstalled)
&& other.Name.Equals(Name)
&& other.Arguments.Equals(Arguments)
&& other.Location.Equals(Location)
&& other.WorkingDirectory.Equals(WorkingDirectory)
&& other.TabThemeId.Equals(TabThemeId)
&& other.TerminalThemeId.Equals(TerminalThemeId)
&& other.LineEndingTranslation == LineEndingTranslation
&& other.UseConPty == UseConPty
&& other.KeyBindings.SequenceEqual(KeyBindings);
}
/// <summary>
/// Checks the profile for errors and returns string describing the found errors, if any.
/// Returns null if no errors found.
/// </summary>
public virtual string ValidateAndGetErrors()
{
return null;
}
}
}