diff --git a/FluentTerminal.App/Services/ISettingsService.cs b/FluentTerminal.App/Services/ISettingsService.cs index 6d04c4da..64edb1a6 100644 --- a/FluentTerminal.App/Services/ISettingsService.cs +++ b/FluentTerminal.App/Services/ISettingsService.cs @@ -15,9 +15,9 @@ public interface ISettingsService TerminalOptions GetTerminalOptions(); void SaveTerminalOptions(TerminalOptions terminalOptions); - TerminalColors GetCurrentThemeColors(); + TerminalTheme GetCurrentTheme(); Guid GetCurrentThemeId(); - TerminalColors GetThemeColors(Guid id); + TerminalTheme GetTheme(Guid id); void SaveCurrentThemeId(Guid id); IEnumerable GetThemes(); diff --git a/FluentTerminal.App/Services/Implementation/DefaultValueProvider.cs b/FluentTerminal.App/Services/Implementation/DefaultValueProvider.cs index 0f5960f4..65dae8db 100644 --- a/FluentTerminal.App/Services/Implementation/DefaultValueProvider.cs +++ b/FluentTerminal.App/Services/Implementation/DefaultValueProvider.cs @@ -43,6 +43,7 @@ public IEnumerable GetPreInstalledThemes() Author = "xterm.js", Name = "Xterm.js Default", PreInstalled = true, + BackgroundOpacity = 0.8, Colors = new TerminalColors { Black = "#2e3436", @@ -75,6 +76,7 @@ public IEnumerable GetPreInstalledThemes() Author = "Microsoft", Name = "PowerShell", PreInstalled = true, + BackgroundOpacity = 0.8, Colors = new TerminalColors { Black = "#000000", diff --git a/FluentTerminal.App/Services/Implementation/SettingsService.cs b/FluentTerminal.App/Services/Implementation/SettingsService.cs index 7e312d92..f355388d 100644 --- a/FluentTerminal.App/Services/Implementation/SettingsService.cs +++ b/FluentTerminal.App/Services/Implementation/SettingsService.cs @@ -49,10 +49,10 @@ public void SaveShellConfiguration(ShellConfiguration shellConfiguration) _localSettings.WriteValueAsJson(nameof(ShellConfiguration), shellConfiguration); } - public TerminalColors GetCurrentThemeColors() + public TerminalTheme GetCurrentTheme() { var id = GetCurrentThemeId(); - return GetThemeColors(id); + return GetTheme(id); } public Guid GetCurrentThemeId() @@ -91,11 +91,9 @@ public IEnumerable GetThemes() return _themes.Values.Select(x => JsonConvert.DeserializeObject((string)x.Value)).ToList(); } - public TerminalColors GetThemeColors(Guid id) + public TerminalTheme GetTheme(Guid id) { - var theme = _themes.ReadValueFromJson(id.ToString(), default(TerminalTheme)); - - return theme.Colors; + return _themes.ReadValueFromJson(id.ToString(), default(TerminalTheme)); } public TerminalOptions GetTerminalOptions() diff --git a/FluentTerminal.App/ViewModels/MainViewModel.cs b/FluentTerminal.App/ViewModels/MainViewModel.cs index 7a89e49f..6d45e202 100644 --- a/FluentTerminal.App/ViewModels/MainViewModel.cs +++ b/FluentTerminal.App/ViewModels/MainViewModel.cs @@ -16,6 +16,7 @@ public class MainViewModel : ViewModelBase private readonly ITerminalService _terminalService; private readonly IDialogService _dialogService; private string _background; + private double _backgroundOpacity; private CoreDispatcher _dispatcher; private TerminalViewModel _selectedTerminal; private string _title; @@ -27,7 +28,10 @@ public MainViewModel(ISettingsService settingsService, ITerminalService terminal _terminalService = terminalService; _dialogService = dialogService; Title = FallbackTitle; - Background = _settingsService.GetCurrentThemeColors().Background; + + var currentTheme = _settingsService.GetCurrentTheme(); + Background = currentTheme.Colors.Background; + BackgroundOpacity = currentTheme.BackgroundOpacity; AddTerminalCommand = new RelayCommand(() => AddTerminal(null)); ShowSettingsCommand = new RelayCommand(async () => await ShowSettings()); @@ -37,6 +41,12 @@ public MainViewModel(ISettingsService settingsService, ITerminalService terminal public RelayCommand AddTerminalCommand { get; } + public double BackgroundOpacity + { + get => _backgroundOpacity; + set => Set(ref _backgroundOpacity, value); + } + public string Background { get => _background; @@ -85,7 +95,9 @@ private async void OnCurrentThemeChanged(object sender, System.EventArgs e) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { - Background = _settingsService.GetCurrentThemeColors().Background; + var currentTheme = _settingsService.GetCurrentTheme(); + Background = currentTheme.Colors.Background; + BackgroundOpacity = currentTheme.BackgroundOpacity; }); } diff --git a/FluentTerminal.App/ViewModels/SettingsViewModel.cs b/FluentTerminal.App/ViewModels/SettingsViewModel.cs index 87aad049..0778ca20 100644 --- a/FluentTerminal.App/ViewModels/SettingsViewModel.cs +++ b/FluentTerminal.App/ViewModels/SettingsViewModel.cs @@ -72,13 +72,14 @@ private void OnThemeActivated(object sender, EventArgs e) private void CreateTheme() { - var defaultColors = _settingsService.GetThemeColors(_defaultValueProvider.GetDefaultThemeId()); + var defaultTheme = _settingsService.GetTheme(_defaultValueProvider.GetDefaultThemeId()); var theme = new TerminalTheme { Id = Guid.NewGuid(), PreInstalled = false, Name = "New Theme", - Colors = new TerminalColors(defaultColors) + BackgroundOpacity = defaultTheme.BackgroundOpacity, + Colors = new TerminalColors(defaultTheme.Colors) }; _settingsService.SaveTheme(theme); diff --git a/FluentTerminal.App/ViewModels/TerminalViewModel.cs b/FluentTerminal.App/ViewModels/TerminalViewModel.cs index 081aae9f..d95ebbbf 100644 --- a/FluentTerminal.App/ViewModels/TerminalViewModel.cs +++ b/FluentTerminal.App/ViewModels/TerminalViewModel.cs @@ -77,9 +77,9 @@ public async Task OnViewIsReady(ITerminalView terminalView) _terminalView = terminalView; var options = _settingsService.GetTerminalOptions(); - var theme = _settingsService.GetCurrentThemeColors(); + var theme = _settingsService.GetCurrentTheme(); - var size = await _terminalView.CreateTerminal(options, theme); + var size = await _terminalView.CreateTerminal(options, theme.Colors); var configuration = _settingsService.GetShellConfiguration(); if (!string.IsNullOrWhiteSpace(_startupDirectory)) @@ -108,8 +108,8 @@ private async void OnCurrentThemeChanged(object sender, EventArgs e) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { - var currentColors = _settingsService.GetCurrentThemeColors(); - await _terminalView.ChangeTheme(currentColors); + var currentTheme = _settingsService.GetCurrentTheme(); + await _terminalView.ChangeTheme(currentTheme.Colors); }); } diff --git a/FluentTerminal.App/ViewModels/ThemeViewModel.cs b/FluentTerminal.App/ViewModels/ThemeViewModel.cs index fc226ccf..e6e31ac5 100644 --- a/FluentTerminal.App/ViewModels/ThemeViewModel.cs +++ b/FluentTerminal.App/ViewModels/ThemeViewModel.cs @@ -12,10 +12,11 @@ namespace FluentTerminal.App.ViewModels { public class ThemeViewModel : ViewModelBase { - private readonly ISettingsService _settingsService; private readonly IDialogService _dialogService; + private readonly ISettingsService _settingsService; private string _author; private Color _background; + private double _backgroundOpacity; private Color _black; private Color _blue; private Color _brightBlack; @@ -29,9 +30,10 @@ public class ThemeViewModel : ViewModelBase private Color _cursor; private Color _cursorAccent; private Color _cyan; + private string _fallBackAuthor; + private double _fallBackBackgroundOpacity; private TerminalColors _fallBackColors; private string _fallBackName; - private string _fallBackAuthor; private Color _foreground; private Color _green; private bool _inEditMode; @@ -49,9 +51,11 @@ public ThemeViewModel(TerminalTheme theme, ISettingsService settingsService, IDi _theme = theme; _settingsService = settingsService; _dialogService = dialogService; + Name = _theme.Name; Author = _theme.Author; Id = _theme.Id; + BackgroundOpacity = _theme.BackgroundOpacity; Black = _theme.Colors.Black.ToColor(); Red = _theme.Colors.Red.ToColor(); @@ -85,6 +89,7 @@ public ThemeViewModel(TerminalTheme theme, ISettingsService settingsService, IDi } public event EventHandler Activated; + public event EventHandler Deleted; public string Author @@ -99,6 +104,12 @@ public Color Background set => Set(ref _background, value); } + public double BackgroundOpacity + { + get => _backgroundOpacity; + set => Set(ref _backgroundOpacity, value); + } + public Color Black { get => _black; @@ -252,6 +263,7 @@ public void SaveChanges() { _theme.Name = Name; _theme.Author = Author; + _theme.BackgroundOpacity = BackgroundOpacity; _theme.Colors.Black = Black.ToColorString(false); _theme.Colors.Red = Red.ToColorString(false); @@ -314,6 +326,7 @@ private async Task CancelEdit() Name = _fallBackName; Author = _fallBackAuthor; + BackgroundOpacity = _fallBackBackgroundOpacity; InEditMode = false; } @@ -344,6 +357,7 @@ private void Edit() _fallBackColors = new TerminalColors(_theme.Colors); _fallBackName = Name; _fallBackAuthor = Author; + _fallBackBackgroundOpacity = BackgroundOpacity; InEditMode = true; } diff --git a/FluentTerminal.App/Views/MainPage.xaml b/FluentTerminal.App/Views/MainPage.xaml index c76ab1bf..ac023b56 100644 --- a/FluentTerminal.App/Views/MainPage.xaml +++ b/FluentTerminal.App/Views/MainPage.xaml @@ -14,9 +14,9 @@ + FallbackColor="{x:Bind ViewModel.Background, Mode=OneWay}" + TintColor="{x:Bind ViewModel.Background, Mode=OneWay}" + TintOpacity="{x:Bind ViewModel.BackgroundOpacity, Mode=OneWay}" /> diff --git a/FluentTerminal.App/Views/SettingsPages/ThemeSettings.xaml b/FluentTerminal.App/Views/SettingsPages/ThemeSettings.xaml index f1cb3cba..e4b438e3 100644 --- a/FluentTerminal.App/Views/SettingsPages/ThemeSettings.xaml +++ b/FluentTerminal.App/Views/SettingsPages/ThemeSettings.xaml @@ -20,7 +20,7 @@ BackgroundSource="HostBackdrop" FallbackColor="{x:Bind ViewModel.SelectedTheme.Background, Mode=OneWay}" TintColor="{x:Bind ViewModel.SelectedTheme.Background, Mode=OneWay}" - TintOpacity="0.8" /> + TintOpacity="{x:Bind ViewModel.SelectedTheme.BackgroundOpacity, Mode=OneWay}" /> @@ -289,6 +289,15 @@ Text="Click on a color to edit" Visibility="{x:Bind InEditMode, Mode=OneWay, Converter={StaticResource TrueToVisibleConverter}}" /> + diff --git a/FluentTerminal.Models/TerminalTheme.cs b/FluentTerminal.Models/TerminalTheme.cs index c651d101..b63af088 100644 --- a/FluentTerminal.Models/TerminalTheme.cs +++ b/FluentTerminal.Models/TerminalTheme.cs @@ -8,6 +8,7 @@ public class TerminalTheme public string Name { get; set; } public string Author { get; set; } public bool PreInstalled { get; set; } + public double BackgroundOpacity { get; set; } public TerminalColors Colors { get; set; } } }