The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Add an Omarchy colour palette that follows the system theme
bubu-dudu408d8f9a862f
diff --git a/desktop/lib/settings/appearance/palette_section.dart b/desktop/lib/settings/appearance/palette_section.dartindex 41be81cd6..42b0ba1c9 100644--- a/desktop/lib/settings/appearance/palette_section.dart+++ b/desktop/lib/settings/appearance/palette_section.dart@@ -36,14 +36,19 @@ class PaletteSection extends StatelessWidget {spacing: 12,runSpacing: 12,children: [- for (final palette in HarnessPalette.values)+ for (final palette in HarnessPalette.offered)SizedBox(width: width,child: _PaletteChoice(palette: palette,selected: prefs.palette == palette,- onChoose: () =>- unawaited(preferences.setPalette(palette)),+ onChoose: () {+ // Re-read the Omarchy theme file so a theme switch shows on pick.+ if (palette == HarnessPalette.omarchy) {+ OmarchyLivePalette.refresh();+ }+ unawaited(preferences.setPalette(palette));+ },),),],diff --git a/desktop/lib/shared/theme/color_palette.dart b/desktop/lib/shared/theme/color_palette.dartindex 59ea94b6e..19cf244b0 100644--- a/desktop/lib/shared/theme/color_palette.dart+++ b/desktop/lib/shared/theme/color_palette.dart@@ -2,6 +2,8 @@ import 'dart:ui' show Brightness;import 'package:flutter/painting.dart';+import '../../theme/omarchy_theme.dart';+/// Coordinated workspace colors. These feed the existing design-system tokens,/// native tabs/search, and terminal defaults; they do not change agent state.///@@ -81,6 +83,20 @@ enum HarnessPalette {search: Color(0xff3c3129),accent: Color(0xffe6c39e),),+ // Follows the Omarchy theme on this computer (theme/omarchy_theme.dart; first written by Fred Nix+ // in the nixfred fork). These constants are Graphite's, the fallback for a missing file or key.+ omarchy(+ 'Omarchy',+ 'Follows your Omarchy theme',+ background: Color(0xff181818),+ panel: Color(0xff141414),+ card: Color(0xff1e1e1e),+ hover: Color(0xff252525),+ workspace: Color(0xff282828),+ tabBar: Color(0xff1c1c1c),+ search: Color(0xff2c2c2c),+ accent: Color(0xffbdcbdc),+ ),// The light palettes mirror the dark ones' layering: the workspace gutter and// tab bar sit a step darker than the terminal ground, cards a step lighter.// Their accents are deep rather than pale, since an accent is drawn as text,@@ -118,23 +134,43 @@ enum HarnessPalette {this.label,this.description, {this.brightness = Brightness.dark,- this.foreground = const Color(0xfff5f5f5),- required this.background,- required this.panel,- required this.card,- required this.hover,- required this.workspace,- required this.tabBar,- required this.search,- required this.accent,+ this._foreground = const Color(0xfff5f5f5),+ required this._background,+ required this._panel,+ required this._card,+ required this._hover,+ required this._workspace,+ required this._tabBar,+ required this._search,+ required this._accent,});final String label, description;final Brightness brightness;- final Color foreground;- final Color background, panel, card, hover, workspace, tabBar, search, accent;+ final Color _foreground;+ final Color _background, _panel, _card, _hover, _workspace, _tabBar, _search, _accent;++ // Every preset answers with its own constants; `omarchy` answers from the live Omarchy theme file,+ // falling back to its constants when the file is missing or a key is absent.+ Color _live(String key, Color fallback) =>+ this == omarchy ? (OmarchyLivePalette.color(key) ?? fallback) : fallback;+ Color get foreground => _live('foreground', _foreground);+ Color get background => _live('background', _background);+ Color get panel => _live('darker_background', _panel);+ Color get card => _live('lighter_background', _card);+ Color get hover => _live('lighter_background', _hover);+ Color get workspace => _live('dark_background', _workspace);+ Color get tabBar => _live('darker_background', _tabBar);+ Color get search => _live('lighter_background', _search);+ Color get accent => _live('accent', _accent);bool get isDark => brightness == Brightness.dark;+ /// The palettes the picker offers here: Omarchy only where there is a theme to follow.+ static List<HarnessPalette> get offered => [+ for (final palette in values)+ if (palette != omarchy || omarchyInstalled()) palette,+ ];+static HarnessPalette fromId(String? id) =>values.where((palette) => palette.name == id).firstOrNull ?? graphite;@@ -149,3 +185,11 @@ enum HarnessPalette {'dark': isDark ? 1 : 0,};}++/// The Omarchy theme's colours, read once and on demand. `refresh()` re-reads the file (the palette+/// picker calls it when Omarchy is chosen, so a theme switch shows on the next pick).+abstract final class OmarchyLivePalette {+ static Map<String, Color>? _colors;+ static Color? color(String key) => (_colors ??= readOmarchyColors())[key];+ static void refresh() => _colors = readOmarchyColors();+}diff --git a/desktop/lib/theme/omarchy_theme.dart b/desktop/lib/theme/omarchy_theme.dartnew file mode 100644index 000000000..27b484e7f--- /dev/null+++ b/desktop/lib/theme/omarchy_theme.dart@@ -0,0 +1,49 @@+// Originally written by Fred Nix (@nixfred) in github.com/nixfred/openharness (MIT).+//+// Omarchy theme following for the Harness desktop app. Reads+// ~/.local/state/omarchy/current/theme/colors.toml, a flat file of `key = "#rrggbb"` lines+// (blue, yellow, red, green, background, foreground, accent and friends). The `omarchy` palette+// (shared/theme/color_palette.dart) answers from it; nothing of Omarchy's is bundled.++import 'dart:io';++import 'package:flutter/painting.dart';++const String omarchyColorsPath = '.local/state/omarchy/current/theme/colors.toml';++/// Parse `key = "#hex"` lines. Six or eight hex digits, quotes and the hash optional.+Map<String, Color> parseOmarchyColors(String text) {+ final out = <String, Color>{};+ final re = RegExp(r'^\s*([A-Za-z0-9_]+)\s*=\s*"?#?([0-9a-fA-F]{6}|[0-9a-fA-F]{8})"?', multiLine: true);+ for (final m in re.allMatches(text)) {+ final hex = m.group(2)!;+ final argb = hex.length == 6 ? int.parse('ff$hex', radix: 16) : int.parse(hex, radix: 16);+ out[m.group(1)!.toLowerCase()] = Color(argb);+ }+ return out;+}++/// Read the current theme file, or an empty map when Omarchy is not installed.+Map<String, Color> readOmarchyColors({String? home}) {+ final h = home ?? Platform.environment['HOME'];+ if (h == null) return const {};+ final f = File('$h/$omarchyColorsPath');+ try {+ if (!f.existsSync()) return const {};+ return parseOmarchyColors(f.readAsStringSync());+ } catch (_) {+ return const {};+ }+}++/// Whether this computer runs Omarchy, judged by its theme file. The palette picker only offers the+/// Omarchy palette where there is a theme to follow.+bool omarchyInstalled({String? home}) {+ final h = home ?? Platform.environment['HOME'];+ if (h == null) return false;+ try {+ return File('$h/$omarchyColorsPath').existsSync();+ } catch (_) {+ return false;+ }+}diff --git a/desktop/test/omarchy_palette_test.dart b/desktop/test/omarchy_palette_test.dartnew file mode 100644index 000000000..c828ddc93--- /dev/null+++ b/desktop/test/omarchy_palette_test.dart@@ -0,0 +1,49 @@+// Originally written by Fred Nix (@nixfred) in github.com/nixfred/openharness (MIT).++import 'dart:io';++import 'package:flutter/painting.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/shared/theme/color_palette.dart';+import 'package:harness/theme/omarchy_theme.dart';++void main() {+ test('presets keep their own constants', () {+ expect(HarnessPalette.graphite.accent, const Color(0xffbdcbdc));+ expect(HarnessPalette.midnight.background, const Color(0xff171b29));+ expect(HarnessPalette.fromId('omarchy'), HarnessPalette.omarchy);+ });++ test('parses an Omarchy colors.toml and the omarchy palette falls back to Graphite when empty', () {+ final c = parseOmarchyColors('mode = "dark"\naccent = "#82FB9C"\nbackground = "#0b0f14"\n');+ expect(c['accent'], const Color(0xff82fb9c));+ expect(c['background'], const Color(0xff0b0f14));+ final home = Directory.systemTemp.createTempSync('no-omarchy-');+ expect(readOmarchyColors(home: home.path), isEmpty);+ home.deleteSync(recursive: true);+ });++ test('the omarchy palette answers from the live theme file', () {+ OmarchyLivePalette.refresh();+ final live = readOmarchyColors();+ if (live.isEmpty) {+ expect(HarnessPalette.omarchy.accent, HarnessPalette.graphite.accent);+ } else {+ expect(HarnessPalette.omarchy.accent, live['accent'] ?? HarnessPalette.graphite.accent);+ expect(HarnessPalette.omarchy.background, live['background'] ?? HarnessPalette.graphite.background);+ }+ expect(HarnessPalette.omarchy.label, 'Omarchy');+ });++ test('the picker offers Omarchy only where a theme file exists', () {+ final home = Directory.systemTemp.createTempSync('omarchy-home-');+ expect(omarchyInstalled(home: home.path), isFalse);+ File('${home.path}/$omarchyColorsPath')+ ..createSync(recursive: true)+ ..writeAsStringSync('accent = "#82FB9C"\n');+ expect(omarchyInstalled(home: home.path), isTrue);+ home.deleteSync(recursive: true);+ expect(HarnessPalette.offered.contains(HarnessPalette.omarchy), omarchyInstalled());+ expect(HarnessPalette.offered, containsAll(HarnessPalette.values.where((p) => p != HarnessPalette.omarchy)));+ });+}