Skip to content

Commit

Permalink
Add font weight setting (#560)
Browse files Browse the repository at this point in the history
* Added font weight setting functionality

* Removed BoldText setting
  • Loading branch information
jenia90 authored and felixse committed Oct 30, 2019
1 parent 89a75ba commit 21631f5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public TerminalOptions GetDefaultTerminalOptions()
ScrollBarStyle = ScrollBarStyle.Hidden,
FontFamily = "Consolas",
FontSize = 13,
BoldText = false,
FontWeight = 400,
BackgroundOpacity = 0.8,
Padding = 12,
ScrollBackLimit = 1000,
Expand Down
30 changes: 15 additions & 15 deletions FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public string FontFamily
}
}

public int FontWeight
{
get => _terminalOptions.FontWeight;
set
{
if (_terminalOptions.FontWeight != value)
{
_terminalOptions.FontWeight = value;
_settingsService.SaveTerminalOptions(_terminalOptions);
RaisePropertyChanged();
}
}
}

public double BackgroundOpacity
{
get => _terminalOptions.BackgroundOpacity;
Expand Down Expand Up @@ -150,20 +164,6 @@ public string WordSeparator
}
}

public bool BoldText
{
get => _terminalOptions.BoldText;
set
{
if (_terminalOptions.BoldText != value)
{
_terminalOptions.BoldText = value;
_settingsService.SaveTerminalOptions(_terminalOptions);
RaisePropertyChanged();
}
}
}

public bool ShowTextCopied
{
get => _terminalOptions.ShowTextCopied;
Expand Down Expand Up @@ -238,7 +238,7 @@ private async Task RestoreDefaults()
ScrollBarStyle = defaults.ScrollBarStyle;
FontFamily = defaults.FontFamily;
FontSize = defaults.FontSize;
BoldText = defaults.BoldText;
FontWeight = defaults.FontWeight;
BackgroundOpacity = defaults.BackgroundOpacity;
ScrollBackLimit = defaults.ScrollBackLimit.ToString();
ShowTextCopied = defaults.ShowTextCopied;
Expand Down
13 changes: 9 additions & 4 deletions FluentTerminal.App/Views/SettingsPages/TerminalSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@
ItemsSource="{x:Bind ViewModel.Sizes}"
SelectedValue="{x:Bind ViewModel.FontSize, Mode=TwoWay}" />

<ToggleSwitch
x:Uid="BoldText"
<Slider
Width="200"
Margin="{StaticResource ItemMargin}"
Header="Bold text"
IsOn="{x:Bind ViewModel.BoldText, Mode=TwoWay}" />
HorizontalAlignment="Left"
x:Uid="FontWeight"
Header="Font Weight"
Maximum="900"
Minimum="100"
StepFrequency="100"
Value="{x:Bind ViewModel.FontWeight, Mode=TwoWay}" />

<Slider
Width="200"
Expand Down
14 changes: 9 additions & 5 deletions FluentTerminal.Client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Terminal, ITerminalOptions, ILinkMatcherOptions } from 'xterm';
import { Terminal, ITerminalOptions, ILinkMatcherOptions, FontWeight } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { SearchAddon } from 'xterm-addon-search';
import { WebLinksAddon } from 'xterm-addon-web-links';
Expand Down Expand Up @@ -62,8 +62,8 @@ window.createTerminal = (options, theme, keyBindings) => {
var terminalOptions: ITerminalOptions = {
fontFamily: options.fontFamily,
fontSize: options.fontSize,
fontWeight: options.boldText ? 'bold' : 'normal',
fontWeightBold: options.boldText ? '400' : 'bold',
fontWeight: options.fontWeight,
fontWeightBold: convertBoldText(options.fontWeight),
cursorStyle: options.cursorStyle,
cursorBlink: options.cursorBlink,
bellStyle: options.bellStyle,
Expand Down Expand Up @@ -222,8 +222,8 @@ window.changeOptions = (options) => {
term.setOption('cursorStyle', options.cursorStyle);
term.setOption('fontFamily', options.fontFamily);
term.setOption('fontSize', options.fontSize);
term.setOption('fontWeight', options.boldText ? 'bold' : 'normal');
term.setOption('fontWeightBold', options.boldText ? 'bolder' : 'bold');
term.setOption('fontWeight', options.fontWeight);
term.setOption('fontWeightBold', convertBoldText(options.fontWeight));
term.setOption('scrollback', options.scrollBackLimit);
term.setOption('wordSeparator', DecodeSpecialChars(options.wordSeparator));
setScrollBarStyle(options.scrollBarStyle);
Expand Down Expand Up @@ -259,3 +259,7 @@ window.findPrevious = (content: string) => {
document.oncontextmenu = function () {
return false;
};

function convertBoldText(fontWeight: FontWeight) : FontWeight {
return parseInt(fontWeight) > 600 ? '900' : 'bold';
}
2 changes: 1 addition & 1 deletion FluentTerminal.Models/TerminalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TerminalOptions

public int FontSize { get; set; }

public bool BoldText { get; set; }
public int FontWeight { get; set; }

public CursorStyle CursorStyle { get; set; }

Expand Down

0 comments on commit 21631f5

Please sign in to comment.