Skip to content

Commit ba1d00f

Browse files
committed
All - CmdOptions For Color Changing
Fixes #137
1 parent 45ec4ad commit ba1d00f

5 files changed

Lines changed: 50 additions & 9 deletions

File tree

NickvisionCavalier.GNOME/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public Program(string[] args)
3434
_mainWindowController = new MainWindowController(args);
3535
_mainWindowController.AppInfo.Changelog =
3636
@"* The wave box drawing mode now draws smoother bezier curves (Thanks @OggyP)
37+
* Users can now specify `--fg aarrggbb` or `--bg aarrggbb` command line arguments to change the foreground and background color of the running Cavalier instance respectively
3738
* Updated translations (Thanks everyone on Weblate!)";
3839
_application.OnActivate += OnActivate;
3940
if (File.Exists(Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) + "/org.nickvision.cavalier.gresource"))

NickvisionCavalier.GNOME/Views/PreferencesDialog.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,18 +1107,14 @@ private void UpdateColorsGrid()
11071107
}
11081108
for (var i = 0; i < _controller.ColorProfiles[_controller.ActiveProfile].FgColors.Count; i++)
11091109
{
1110-
var colorButton = new ColorBox(
1111-
_controller.ColorProfiles[_controller.ActiveProfile].FgColors[i],
1112-
ColorType.Foreground, i, i != 0);
1110+
var colorButton = new ColorBox(_controller.ColorProfiles[_controller.ActiveProfile].FgColors[i], ColorType.Foreground, i, i != 0);
11131111
colorButton.OnEdit += OnEditColor;
11141112
colorButton.OnDelete += OnDeleteColor;
11151113
_colorsGrid.Attach(colorButton, 0, i + 1, 1, 1);
11161114
}
11171115
for (var i = 0; i < _controller.ColorProfiles[_controller.ActiveProfile].BgColors.Count; i++)
11181116
{
1119-
var colorButton = new ColorBox(
1120-
_controller.ColorProfiles[_controller.ActiveProfile].BgColors[i],
1121-
ColorType.Background, i, i != 0);
1117+
var colorButton = new ColorBox(_controller.ColorProfiles[_controller.ActiveProfile].BgColors[i], ColorType.Background, i, i != 0);
11221118
colorButton.OnEdit += OnEditColor;
11231119
colorButton.OnDelete += OnDeleteColor;
11241120
_colorsGrid.Attach(colorButton, 1, i + 1, 1, 1);

NickvisionCavalier.Shared/Controllers/PreferencesViewController.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CommandLine;
22
using CommandLine.Text;
3+
using Markdig.Helpers;
34
using Nickvision.Aura;
45
using NickvisionCavalier.Shared.Models;
56
using System;
@@ -532,6 +533,22 @@ public void HandleCommandLine(object? sender, string[] args)
532533
updateCavalier = true;
533534
}
534535
}
536+
if (!string.IsNullOrEmpty(o.BgColor) && (o.BgColor!.Length == 6 || o.BgColor!.Length == 8))
537+
{
538+
if(o.BgColor.Length == 6)
539+
{
540+
o.BgColor = $"ff{o.BgColor}";
541+
}
542+
foreach (var c in o.BgColor)
543+
{
544+
if (!c.IsDigit() && c < 'a' && c > 'f') //hex can be any digit or a-f
545+
{
546+
return;
547+
}
548+
}
549+
EditColor(ColorType.Background, 0, $"#{o.BgColor}");
550+
updateCavalier = true;
551+
}
535552
if (o.BgImageIndex.HasValue)
536553
{
537554
if (o.BgImageIndex.Value > -1 && o.BgImageIndex.Value <= ImagesList.Count)
@@ -550,6 +567,22 @@ public void HandleCommandLine(object? sender, string[] args)
550567
BgImageAlpha = Math.Max(0.1f, Math.Min(o.BgImageAlpha.Value / 100f, 1f));
551568
updateCavalier = true;
552569
}
570+
if (!string.IsNullOrEmpty(o.FgColor) && (o.FgColor!.Length == 6 || o.FgColor!.Length == 8))
571+
{
572+
if (o.FgColor.Length == 6)
573+
{
574+
o.FgColor = $"ff{o.FgColor}";
575+
}
576+
foreach (var c in o.FgColor) //hex can be any digit or a-f
577+
{
578+
if (!c.IsDigit() && (c < 'a' || c > 'f'))
579+
{
580+
return;
581+
}
582+
}
583+
EditColor(ColorType.Foreground, 0, $"#{o.FgColor}");
584+
updateCavalier = true;
585+
}
553586
if (o.FgImageIndex.HasValue)
554587
{
555588
if (o.FgImageIndex.Value > -1 && o.FgImageIndex.Value <= ImagesList.Count)

NickvisionCavalier.Shared/Linux/org.nickvision.cavalier.metainfo.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<release version="2024.1.0-next" date="2024-01-01">
5151
<description translatable="no">
5252
<p>- The wave box drawing mode now draws smoother bezier curves (Thanks @OggyP)</p>
53+
<p>- Users can now specify `--fg aarrggbb` or `--bg aarrggbb` command line arguments to change the foreground and background color of the running Cavalier instance respectively</p>
5354
<p>- Updated translations (Thanks everyone on Weblate!)</p>
5455
</description>
5556
</release>

NickvisionCavalier.Shared/Models/CmdOptions.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public class CmdOptions
103103
[Option('p', "profile", Required = false, HelpText = "Zero-based index of profile to activate")]
104104
public uint? ActiveProfile { get; set; }
105105
/// <summary>
106+
/// Active background color
107+
/// </summary>
108+
[Option("bg", Required = false, HelpText = "Background color, hex format: aarrbbgg or rrbbgg")]
109+
public string? BgColor { get; set; }
110+
/// <summary>
106111
/// Index of a background image to load (0 to not load anything)
107112
/// </summary>
108113
[Option("bg-index", Required = false, HelpText = "Index of background image to draw (0 for no image)")]
@@ -118,14 +123,19 @@ public class CmdOptions
118123
[Option("bg-alpha", Required = false, HelpText = "Background image alpha in percent (10-100)")]
119124
public uint? BgImageAlpha { get; set; }
120125
/// <summary>
121-
/// Index of a background image to load (0 to not load anything)
126+
/// Active forground color
127+
/// </summary>
128+
[Option("fg", Required = false, HelpText = "Foreground color, hex format: aarrbbgg or rrbbgg")]
129+
public string? FgColor { get; set; }
130+
/// <summary>
131+
/// Index of a foreground image to load (0 to not load anything)
122132
/// </summary>
123133
[Option("fg-index", Required = false, HelpText = "Index of foreground image to draw (0 for no image)")]
124134
public int? FgImageIndex { get; set; }
125135
/// <summary>
126-
/// Background image scale (10-100, 100 - fill the window)
136+
/// Foreground image scale (10-100, 100 - fill the window)
127137
/// </summary>
128-
[Option("fg-scale", Required = false, HelpText = "Background image scale in percent (10-100)")]
138+
[Option("fg-scale", Required = false, HelpText = "Foreground image scale in percent (10-100)")]
129139
public uint? FgImageScale { get; set; }
130140
/// <summary>
131141
/// Foreground image transparency (10-100, 100 - fully opaque)

0 commit comments

Comments
 (0)