From fd63023cf59d7d51374680fda594075cde53638a Mon Sep 17 00:00:00 2001 From: ahaoboy <504595380@qq.com> Date: Thu, 26 Sep 2024 13:36:49 +0800 Subject: [PATCH 1/2] timings: use css variables --- src/cargo/core/compiler/timings.js | 45 ++++++++++++++++++-------- src/cargo/core/compiler/timings.rs | 52 +++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 26 deletions(-) diff --git a/src/cargo/core/compiler/timings.js b/src/cargo/core/compiler/timings.js index 1b7e29e019a..d9a0b53bd6c 100644 --- a/src/cargo/core/compiler/timings.js +++ b/src/cargo/core/compiler/timings.js @@ -22,6 +22,21 @@ let UNIT_COORDS = {}; // Map of unit index to the index it was unlocked by. let REVERSE_UNIT_DEPS = {}; let REVERSE_UNIT_RMETA_DEPS = {}; + +// Colors from css +const getCssColor = name => getComputedStyle(document.body).getPropertyValue(name); +const TEXT_COLOR = getCssColor('--text'); +const BG_COLOR = getCssColor('--background'); +const CANVAS_BG = getCssColor('--canvas-background'); +const AXES_COLOR = getCssColor('--canvas-axes'); +const GRID_COLOR = getCssColor('--canvas-grid'); +const BLOCK_COLOR = getCssColor('--canvas-block'); +const CUSTOM_BUILD_COLOR = getCssColor('--canvas-custom-build'); +const NOT_CUSTOM_BUILD_COLOR = getCssColor('--canvas-not-custom-build'); +const DEP_LINE_COLOR = getCssColor('--canvas-dep-line'); +const DEP_LINE_HIGHLIGHTED_COLOR = getCssColor('--canvas-dep-line-highlighted'); +const CPU_COLOR = getCssColor('--canvas-cpu'); + for (let n=0; n 1) { ctx.beginPath(); ctx.fillStyle = cpuFillStyle; @@ -245,8 +261,8 @@ function render_timing_graph() { ctx.save(); ctx.translate(canvas_width-200, MARGIN); // background - ctx.fillStyle = '#fff'; - ctx.strokeStyle = '#000'; + ctx.fillStyle = BG_COLOR; + ctx.strokeStyle = TEXT_COLOR; ctx.lineWidth = 1; ctx.textBaseline = 'middle' ctx.textAlign = 'start'; @@ -255,7 +271,7 @@ function render_timing_graph() { ctx.stroke(); ctx.fill(); - ctx.fillStyle = '#000' + ctx.fillStyle = TEXT_COLOR; ctx.beginPath(); ctx.lineWidth = 2; ctx.strokeStyle = 'red'; @@ -282,7 +298,7 @@ function render_timing_graph() { ctx.fillStyle = cpuFillStyle ctx.fillRect(15, 60, 30, 15); ctx.fill(); - ctx.fillStyle = 'black'; + ctx.fillStyle = TEXT_COLOR; ctx.fillText('CPU Usage', 54, 71); ctx.restore(); @@ -311,12 +327,13 @@ function draw_graph_axes(id, graph_height) { const canvas_width = Math.max(graph_width + X_LINE + 30, X_LINE + 250); const canvas_height = graph_height + MARGIN + Y_LINE; let ctx = setup_canvas(id, canvas_width, canvas_height); - ctx.fillStyle = '#f7f7f7'; + ctx.fillStyle = CANVAS_BG; ctx.fillRect(0, 0, canvas_width, canvas_height); ctx.lineWidth = 2; ctx.font = '16px sans-serif'; ctx.textAlign = 'center'; + ctx.strokeStyle = AXES_COLOR; // Draw main axes. ctx.beginPath(); @@ -327,7 +344,7 @@ function draw_graph_axes(id, graph_height) { // Draw X tick marks. const {step, tick_dist, num_ticks} = split_ticks(DURATION, px_per_sec, graph_width); - ctx.fillStyle = '#303030'; + ctx.fillStyle = AXES_COLOR; for (let n=0; nCargo Build Timings — {ROOTS} From 3401cb8fe2e863e760f0119c83dec45411620f31 Mon Sep 17 00:00:00 2001 From: ahaoboy <504595380@qq.com> Date: Thu, 26 Sep 2024 13:37:42 +0800 Subject: [PATCH 2/2] timings: add dark mode --- src/cargo/core/compiler/timings.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/cargo/core/compiler/timings.rs b/src/cargo/core/compiler/timings.rs index 6c25f886004..05d37632e5d 100644 --- a/src/cargo/core/compiler/timings.rs +++ b/src/cargo/core/compiler/timings.rs @@ -635,6 +635,34 @@ static HTML_TMPL: &str = r#" --canvas-cpu: rgba(250, 119, 0, 0.2); } +@media (prefers-color-scheme: dark) { + :root { + --error-text: #e80000; + --text: #fff; + --background: #121212; + --h1-border-bottom: #444; + --table-box-shadow: rgba(255, 255, 255, 0.1); + --table-th: #a0a0a0; + --table-th-background: #2c2c2c; + --table-th-border-bottom: #555; + --table-th-border-right: #444; + --table-tr-border-top: #333; + --table-tr-border-bottom: #333; + --table-tr-odd-background: #1e1e1e; + --table-td-background: #262626; + --table-td-border-right: #333; + --canvas-background: #1a1a1a; + --canvas-axes: #b0b0b0; + --canvas-grid: #333; + --canvas-block: #aa95e8; + --canvas-custom-build: #f0b165; + --canvas-not-custom-build: #95cce8; + --canvas-dep-line: #444; + --canvas-dep-line-highlighted: #fff; + --canvas-cpu: rgba(250, 119, 0, 0.2); + } +} + html { font-family: sans-serif; color: var(--text);