Skip to content

Commit

Permalink
Make background opacity configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
felixse committed Feb 15, 2018
1 parent 37518cf commit 7dcd8e1
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 22 deletions.
4 changes: 2 additions & 2 deletions FluentTerminal.App/Services/ISettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TerminalTheme> GetThemes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public IEnumerable<TerminalTheme> GetPreInstalledThemes()
Author = "xterm.js",
Name = "Xterm.js Default",
PreInstalled = true,
BackgroundOpacity = 0.8,
Colors = new TerminalColors
{
Black = "#2e3436",
Expand Down Expand Up @@ -75,6 +76,7 @@ public IEnumerable<TerminalTheme> GetPreInstalledThemes()
Author = "Microsoft",
Name = "PowerShell",
PreInstalled = true,
BackgroundOpacity = 0.8,
Colors = new TerminalColors
{
Black = "#000000",
Expand Down
10 changes: 4 additions & 6 deletions FluentTerminal.App/Services/Implementation/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -91,11 +91,9 @@ public IEnumerable<TerminalTheme> GetThemes()
return _themes.Values.Select(x => JsonConvert.DeserializeObject<TerminalTheme>((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()
Expand Down
16 changes: 14 additions & 2 deletions FluentTerminal.App/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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;
Expand Down Expand Up @@ -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;
});
}

Expand Down
5 changes: 3 additions & 2 deletions FluentTerminal.App/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions FluentTerminal.App/ViewModels/TerminalViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
});
}

Expand Down
18 changes: 16 additions & 2 deletions FluentTerminal.App/ViewModels/ThemeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -85,6 +89,7 @@ public ThemeViewModel(TerminalTheme theme, ISettingsService settingsService, IDi
}

public event EventHandler Activated;

public event EventHandler Deleted;

public string Author
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -314,6 +326,7 @@ private async Task CancelEdit()

Name = _fallBackName;
Author = _fallBackAuthor;
BackgroundOpacity = _fallBackBackgroundOpacity;

InEditMode = false;
}
Expand Down Expand Up @@ -344,6 +357,7 @@ private void Edit()
_fallBackColors = new TerminalColors(_theme.Colors);
_fallBackName = Name;
_fallBackAuthor = Author;
_fallBackBackgroundOpacity = BackgroundOpacity;
InEditMode = true;
}

Expand Down
6 changes: 3 additions & 3 deletions FluentTerminal.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<Grid.Background>
<AcrylicBrush
BackgroundSource="HostBackdrop"
FallbackColor="{Binding ViewModel.Background, Mode=OneWay}"
TintColor="{Binding ViewModel.Background, Mode=OneWay}"
TintOpacity="0.8" />
FallbackColor="{x:Bind ViewModel.Background, Mode=OneWay}"
TintColor="{x:Bind ViewModel.Background, Mode=OneWay}"
TintOpacity="{x:Bind ViewModel.BackgroundOpacity, Mode=OneWay}" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down
11 changes: 10 additions & 1 deletion FluentTerminal.App/Views/SettingsPages/ThemeSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}" />
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="160" />
Expand Down Expand Up @@ -289,6 +289,15 @@
Text="Click on a color to edit"
Visibility="{x:Bind InEditMode, Mode=OneWay, Converter={StaticResource TrueToVisibleConverter}}" />
</Grid>
<Slider
Margin="0,24,0,0"
Header="Background Opacity"
Maximum="1"
Minimum="0"
RequestedTheme="Dark"
StepFrequency="0.01"
Visibility="{x:Bind InEditMode, Mode=OneWay, Converter={StaticResource TrueToVisibleConverter}}"
Value="{x:Bind BackgroundOpacity, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</ContentControl.ContentTemplate>
Expand Down
1 change: 1 addition & 0 deletions FluentTerminal.Models/TerminalTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}

0 comments on commit 7dcd8e1

Please sign in to comment.