Skip to content

A visual git client, simple to use yet powerful. Light, fast and debloated.

Rust

feat: gitcraft 0.3.1 - tab icons and colours, checkout and pull, GitKraken-style graph lines

Iván9e5e66d38a5e
diff --git a/Cargo.lock b/Cargo.lock
index f397d02..916096b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1447,7 +1447,7 @@ dependencies = [
[[package]]
name = "gitcraft"
-version = "0.3.0"
+version = "0.3.1"
dependencies = [
"eframe",
"egui",
diff --git a/Cargo.toml b/Cargo.toml
index 3b6839f..189cfbb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "gitcraft"
-version = "0.3.0"
+version = "0.3.1"
edition = "2024"
rust-version = "1.95"
license = "MIT OR Apache-2.0"
diff --git a/README.md b/README.md
index a730b14..b7c79de 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# gitcraft
-A visual git client: a simplified take yet powerful on the usual graph-based git GUIs.
+A visual git client: a simplified yet powerful take on the usual graph-based git GUIs.
Rust + [egui/eframe](https://github.com/emilk/egui), the same technical stack of the ArtCraft suite, so it builds on Windows, Linux and macOS and stays light and fast. It drives the installed `git` command line,
so your config, credentials and hooks apply as usual.
@@ -106,7 +106,7 @@ so your config, credentials and hooks apply as usual.
Cached on disk; can be turned off.
- Settings: zoom, branch column width, graph columns, avatars, notifications, update check,
background fetch, editor command, default shell and terminal font size, saved identities.
-- Checks GitHub once a day for a newer release and shows a pill to download it (can be turned
+- Checks GitHub every 12 hours for a newer release and shows a pill to download it (can be turned
off).
- Toasts, and a desktop notification when a long operation ends while the window is in the
background.
@@ -160,6 +160,7 @@ cargo run --example ui_shot -- path/to/repo /tmp/shot click:500,266 shot key:Esc
Steps: `click:x,y`, `dclick:x,y`, `rclick:x,y`, `cclick:x,y` (with Ctrl / Cmd), `sclick:x,y`
(with Shift), `drag:x1,y1,x2,y2`, `hover:x,y`, `wheel:x,y,dy` (negative scrolls down), `leave`,
+`open:path` (another repository in a new tab),
`key:Name`, `ckey:Name` (with Ctrl / Cmd), `type:text`, `wait:ms`, `shot`. The README screenshot
was made this way, on a demo repository.
diff --git a/assets/icons/code.svg b/assets/icons/code.svg
new file mode 100644
index 0000000..da0f522
--- /dev/null
+++ b/assets/icons/code.svg
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <polyline points="16 18 22 12 16 6" />
+ <polyline points="8 6 2 12 8 18" />
+</svg>
diff --git a/assets/icons/database.svg b/assets/icons/database.svg
new file mode 100644
index 0000000..f95db0e
--- /dev/null
+++ b/assets/icons/database.svg
@@ -0,0 +1,15 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <ellipse cx="12" cy="5" rx="9" ry="3" />
+ <path d="M3 5V19A9 3 0 0 0 21 19V5" />
+ <path d="M3 12A9 3 0 0 0 21 12" />
+</svg>
diff --git a/assets/icons/flask-conical.svg b/assets/icons/flask-conical.svg
new file mode 100644
index 0000000..f069951
--- /dev/null
+++ b/assets/icons/flask-conical.svg
@@ -0,0 +1,15 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <path d="M10 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2" />
+ <path d="M8.5 2h7" />
+ <path d="M7 16h10" />
+</svg>
diff --git a/assets/icons/gamepad-2.svg b/assets/icons/gamepad-2.svg
new file mode 100644
index 0000000..bc7f08c
--- /dev/null
+++ b/assets/icons/gamepad-2.svg
@@ -0,0 +1,17 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <line x1="6" x2="10" y1="11" y2="11" />
+ <line x1="8" x2="8" y1="9" y2="13" />
+ <line x1="15" x2="15.01" y1="12" y2="12" />
+ <line x1="18" x2="18.01" y1="10" y2="10" />
+ <path d="M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258-.007-.05-.011-.1-.017-.151A4 4 0 0 0 17.32 5z" />
+</svg>
diff --git a/assets/icons/globe.svg b/assets/icons/globe.svg
new file mode 100644
index 0000000..53c80ee
--- /dev/null
+++ b/assets/icons/globe.svg
@@ -0,0 +1,15 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <circle cx="12" cy="12" r="10" />
+ <path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" />
+ <path d="M2 12h20" />
+</svg>
diff --git a/assets/icons/heart.svg b/assets/icons/heart.svg
new file mode 100644
index 0000000..6541864
--- /dev/null
+++ b/assets/icons/heart.svg
@@ -0,0 +1,13 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <path d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z" />
+</svg>
diff --git a/assets/icons/package.svg b/assets/icons/package.svg
new file mode 100644
index 0000000..ccfdc52
--- /dev/null
+++ b/assets/icons/package.svg
@@ -0,0 +1,16 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <path d="M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z" />
+ <path d="M12 22V12" />
+ <path d="m3.3 7 7.703 4.734a2 2 0 0 0 1.994 0L20.7 7" />
+ <path d="m7.5 4.27 9 5.15" />
+</svg>
diff --git a/assets/icons/rocket.svg b/assets/icons/rocket.svg
new file mode 100644
index 0000000..4ca5ac0
--- /dev/null
+++ b/assets/icons/rocket.svg
@@ -0,0 +1,16 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <path d="M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z" />
+ <path d="m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z" />
+ <path d="M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0" />
+ <path d="M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5" />
+</svg>
diff --git a/assets/icons/server.svg b/assets/icons/server.svg
new file mode 100644
index 0000000..a8b6ad9
--- /dev/null
+++ b/assets/icons/server.svg
@@ -0,0 +1,16 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <rect width="20" height="8" x="2" y="2" rx="2" ry="2" />
+ <rect width="20" height="8" x="2" y="14" rx="2" ry="2" />
+ <line x1="6" x2="6.01" y1="6" y2="6" />
+ <line x1="6" x2="6.01" y1="18" y2="18" />
+</svg>
diff --git a/assets/icons/smartphone.svg b/assets/icons/smartphone.svg
new file mode 100644
index 0000000..fc84017
--- /dev/null
+++ b/assets/icons/smartphone.svg
@@ -0,0 +1,14 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <rect width="14" height="20" x="5" y="2" rx="2" ry="2" />
+ <path d="M12 18h.01" />
+</svg>
diff --git a/assets/icons/star.svg b/assets/icons/star.svg
new file mode 100644
index 0000000..47e496c
--- /dev/null
+++ b/assets/icons/star.svg
@@ -0,0 +1,13 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
+</svg>
diff --git a/assets/icons/wrench.svg b/assets/icons/wrench.svg
new file mode 100644
index 0000000..7a3c0e0
--- /dev/null
+++ b/assets/icons/wrench.svg
@@ -0,0 +1,13 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z" />
+</svg>
diff --git a/docs/screenshot.png b/docs/screenshot.png
index 8305250..c974749 100644
Binary files a/docs/screenshot.png and b/docs/screenshot.png differ
diff --git a/examples/ui_shot.rs b/examples/ui_shot.rs
index 2afb889..cd78491 100644
--- a/examples/ui_shot.rs
+++ b/examples/ui_shot.rs
@@ -4,7 +4,7 @@
//! `cargo run --example ui_shot -- <repo> <out-prefix> [step]...`
//!
//! Steps (coordinates in points, window is 1400×860):
-//! `click:x,y`, `dclick:x,y`, `rclick:x,y`, `hover:x,y`, `drag:x1,y1,x2,y2`, `leave` (pointer off the window), `key:Escape`, `ckey:P` (Ctrl/Cmd+key), `type:text`, `wait:ms`, `shot`.
+//! `click:x,y`, `dclick:x,y`, `rclick:x,y`, `hover:x,y`, `drag:x1,y1,x2,y2`, `leave` (pointer off the window), `open:path` (a repository in a new tab), `key:Escape`, `ckey:P` (Ctrl/Cmd+key), `type:text`, `wait:ms`, `shot`.
//! Each `shot` writes `<out-prefix>-<n>.png`.
use std::time::{Duration, Instant};
@@ -80,6 +80,14 @@ fn main() {
}
settle(&mut harness, 600);
}
+ // `open:path`: another repository, in a new tab.
+ "open" => {
+ let ctx = harness.ctx.clone();
+ harness
+ .state_mut()
+ .open_tab(std::path::Path::new(arg), &ctx);
+ settle(&mut harness, 1500);
+ }
"leave" => {
harness.remove_cursor();
settle(&mut harness, 200);
diff --git a/src/app.rs b/src/app.rs
index e267ced..d1e2345 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,21 +1,23 @@
//! Window shell: git check, browser-like tabs, the start page and cloning.
+use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{Receiver, channel};
-use egui::{Align2, CornerRadius, Key, Rect, RichText, Sense, Stroke, Ui, pos2, vec2};
+use egui::{Align2, Key, Rect, RichText, Sense, Stroke, Ui, pos2, vec2};
use serde::{Deserialize, Serialize};
use crate::git;
use crate::icons;
use crate::repo::RepoTab;
use crate::settings::Settings;
+use crate::tab_look::{self, TabLook};
use crate::theme::{self, ThemeKind, Tokens};
use crate::update;
const MAX_RECENT: usize = 12;
-const TAB_H: f32 = 34.0;
+const TAB_H: f32 = 40.0;
/// Set by `main` when the window was closed maximized: it opens restored and is maximized once
/// it shows its first frame. Created maximized, winit shows the hidden window for an instant
@@ -36,6 +38,8 @@ struct Saved {
update_checked: i64,
/// A release the user chose to skip.
skipped_version: String,
+ /// Repository tabs given their own icon or colour.
+ tab_looks: BTreeMap<PathBuf, TabLook>,
}
enum Tab {
@@ -77,6 +81,7 @@ pub struct App {
update_rx: Option<Receiver<Result<update::Release, String>>>,
update_checked: i64,
skipped_version: String,
+ tab_looks: BTreeMap<PathBuf, TabLook>,
settings: Settings,
settings_open: bool,
manual_open: bool,
@@ -149,6 +154,7 @@ impl App {
update_rx: None,
update_checked: saved.update_checked,
skipped_version: saved.skipped_version,
+ tab_looks: saved.tab_looks,
};
if saved.settings.check_updates && git::now() - saved.update_checked > update::INTERVAL {
let (tx, rx) = channel();
@@ -178,6 +184,11 @@ impl App {
app
}
+ /// Opens `path` as the start page's "Open" button does (for `examples/ui_shot.rs`).
+ pub fn open_tab(&mut self, path: &Path, ctx: &egui::Context) {
+ self.open_repo(path, ctx);
+ }
+
/// Opens `path` in the active tab if it's a start page, otherwise in a new tab.
fn open_repo(&mut self, path: &Path, ctx: &egui::Context) {
let root = match git::toplevel(path) {
@@ -299,6 +310,8 @@ impl App {
let mut select = None;
let mut close = None;
let mut add = false;
+ let mut restyle = None;
+ let default_look = TabLook::default();
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 1.0;
for (i, tab) in self.tabs.iter().enumerate() {
@@ -321,37 +334,44 @@ impl App {
let w = (galley.size().x + 66.0).clamp(110.0, 260.0);
let (rect, resp) = ui.allocate_exact_size(vec2(w, TAB_H), Sense::click());
let hovered = resp.hovered();
- let p = ui.painter();
- let shape = CornerRadius {
- nw: t.radius as u8,
- ne: t.radius as u8,
- sw: 0,
- se: 0,
+ let look = match tab {
+ Tab::Repo(r) => self.tab_looks.get(&r.path).unwrap_or(&default_look),
+ Tab::Home => &default_look,
};
+ let accent = look.color.color(&t);
+ let p = ui.painter();
if active {
- p.rect_filled(rect, shape, t.chrome);
+ p.rect_filled(rect, 0.0, t.chrome);
p.line_segment(
[
- rect.left_top() + vec2(2.0, 0.5),
- rect.right_top() + vec2(-2.0, 0.5),
+ rect.left_top() + vec2(0.0, 1.0),
+ rect.right_top() + vec2(0.0, 1.0),
],
- Stroke::new(2.0, t.accent),
+ Stroke::new(2.0, accent),
);
} else if hovered {
- p.rect_filled(rect, shape, t.hover.gamma_multiply(0.6));
+ p.rect_filled(rect, 0.0, t.hover.gamma_multiply(0.6));
}
let y = rect.center().y;
let icon = if matches!(tab, Tab::Home) {
"plus"
} else {
- "folder-git-2"
+ look.icon()
+ };
+ // A chosen colour also marks the tab when it is in the background.
+ let icon_tint = if active {
+ accent
+ } else if look.color != tab_look::TabColor::default() {
+ accent.gamma_multiply(0.75)
+ } else {
+ t.text_faint
};
icons::paint(
ui,
Rect::from_center_size(pos2(rect.left() + 18.0, y), vec2(16.0, 16.0)),
icon,
14.0,
- if active { t.accent } else { t.text_faint },
+ icon_tint,
);
let text_clip = Rect::from_min_max(
pos2(rect.left() + 32.0, rect.top()),
@@ -384,6 +404,15 @@ impl App {
}
c.on_hover_text("Close tab (Ctrl+W)");
}
+ if let Tab::Repo(r) = tab {
+ egui::Popup::context_menu(&resp)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ if let Some(new) = tab_look::menu(ui, look) {
+ restyle = Some((r.path.clone(), new));
+ }
+ });
+ }
let resp = resp.on_hover_text(tooltip);
if resp.clicked() && close.is_none() {
select = Some(i);
@@ -461,6 +490,13 @@ impl App {
if let Some(i) = select {
self.active = i;
}
+ if let Some((path, look)) = restyle {
+ if look == TabLook::default() {
+ self.tab_looks.remove(&path);
+ } else {
+ self.tab_looks.insert(path, look);
+ }
+ }
if let Some(i) = close {
self.close_tab(i);
}
@@ -877,7 +913,7 @@ impl eframe::App for App {
.inner_margin(egui::Margin {
left: 6,
right: 6,
- top: 6,
+ top: 0,
bottom: 0,
}),
)
@@ -951,6 +987,7 @@ impl eframe::App for App {
settings: self.settings.clone(),
update_checked: self.update_checked,
skipped_version: self.skipped_version.clone(),
+ tab_looks: self.tab_looks.clone(),
};
eframe::set_value(storage, eframe::APP_KEY, &saved);
}
@@ -1424,7 +1461,43 @@ fn notify(text: &str) {
#[cfg(test)]
mod tests {
- use super::{fuzzy, window_icon};
+ use super::{Saved, fuzzy, window_icon};
+ use crate::tab_look::{TabColor, TabLook};
+
+ /// A storage that keeps strings in memory, as eframe's own does on disk.
+ #[derive(Default)]
+ struct Memory(std::collections::HashMap<String, String>);
+
+ impl eframe::Storage for Memory {
+ fn get_string(&self, key: &str) -> Option<String> {
+ self.0.get(key).cloned()
+ }
+ fn set_string(&mut self, key: &str, value: String) {
+ self.0.insert(key.to_owned(), value);
+ }
+ fn remove_string(&mut self, key: &str) {
+ self.0.remove(key);
+ }
+ fn flush(&mut self) {}
+ }
+
+ #[test]
+ fn tab_looks_survive_a_restart() {
+ let look = TabLook {
+ icon: Some("rocket".to_owned()),
+ color: TabColor::Purple,
+ };
+ let mut saved = Saved::default();
+ saved.tab_looks.insert("C:/code/app".into(), look.clone());
+ let mut storage = Memory::default();
+ eframe::set_value(&mut storage, eframe::APP_KEY, &saved);
+ let back: Option<Saved> = eframe::get_value(&storage, eframe::APP_KEY);
+ assert!(
+ back.is_some_and(
+ |b| b.tab_looks.get(std::path::Path::new("C:/code/app")) == Some(&look)
+ )
+ );
+ }
#[test]
fn window_icon_decodes() {
diff --git a/src/icons.rs b/src/icons.rs
index 141bbf8..edce0a4 100644
--- a/src/icons.rs
+++ b/src/icons.rs
@@ -29,35 +29,47 @@ const SOURCES: &[(&str, &str)] = icons![
"circle-alert",
"cloud",
"cloud-download",
+ "code",
"columns-2",
"command",
"copy",
+ "database",
"external-link",
"file-diff",
+ "flask-conical",
"folder-git-2",
"folder-open",
"folder-plus",
"folder-tree",
+ "gamepad-2",
"git-branch",
"git-branch-plus",
"git-merge",
"git-pull-request",
+ "globe",
+ "heart",
"history",
"laptop",
"log-in",
"minus",
+ "package",
"palette",
"pilcrow",
"plus",
"redo-2",
"refresh-cw",
+ "rocket",
"rows-2",
"search",
+ "server",
"settings",
+ "smartphone",
"square-terminal",
+ "star",
"tag",
"undo-2",
"user-round",
+ "wrench",
"x",
];
diff --git a/src/lib.rs b/src/lib.rs
index f96f07c..e510d38 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,6 +11,7 @@ mod manual;
mod repo;
mod settings;
mod shell_path;
+mod tab_look;
mod terminal;
mod theme;
mod update;
diff --git a/src/manual.rs b/src/manual.rs
index 2396d6d..61888cd 100644
--- a/src/manual.rs
+++ b/src/manual.rs
@@ -20,13 +20,14 @@ const FEATURES: &[(&str, &[&str])] = &[
&[
"Open, create or clone a repository from the start page; recent ones are listed there.",
"One tab per repository. Changes made elsewhere (editor, terminal) show up by themselves.",
+ "Right-click a tab to give it its own icon and highlight colour.",
],
),
(
"Graph",
&[
"Every branch with its pill on its latest commit: solid for the checked-out one, a laptop when it is local, a cloud when a remote has it.",
- "Double-click a pill to check that branch out; hover +N to see every branch of the commit.",
+ "Double-click a pill to check that branch out (and pull it when its remote is ahead); hover +N to see every branch of the commit, and right-click any of them.",
"Right-click a commit or a pill for branches, tags, merge, rebase, cherry-pick, revert, reset and more.",
"Search messages, authors and hashes, or switch to Code to find the commits that added or removed some text.",
"Interactive rebase: reorder, reword, squash, fix up or drop commits, then start it.",
diff --git a/src/repo/graph_view.rs b/src/repo/graph_view.rs
index 9c8ea14..3a213a6 100644
--- a/src/repo/graph_view.rs
+++ b/src/repo/graph_view.rs
@@ -2,8 +2,7 @@
//! older history loaded as you scroll.
use egui::{
- Align2, Color32, CornerRadius, FontId, Key, Pos2, Rect, Response, Sense, Stroke, Ui,
- epaint::CubicBezierShape, pos2, vec2,
+ Align2, Color32, CornerRadius, FontId, Key, Pos2, Rect, Response, Sense, Stroke, Ui, pos2, vec2,
};
use super::widgets;
@@ -17,7 +16,13 @@ use crate::settings::Settings;
use crate::theme::{self, Tokens};
const ROW_H: f32 = 28.0;
+/// Space between rows, which the graph's lines cross.
+const ROW_GAP: f32 = 2.0;
+/// From one row to the next.
+const ROW_PITCH: f32 = ROW_H + ROW_GAP;
const LANE_W: f32 = 16.0;
+/// Radius of the corner where a line from a dot turns into another lane.
+const CORNER_R: f32 = 7.0;
const MAX_LANES_SHOWN: usize = 24;
/// How much darker the pills that are not checked out are (0 = same colour, 1 = black).
const DIMMED: f32 = 0.4;
@@ -142,28 +147,28 @@ impl RepoTab {
let offset_id = ui.id().with("graph_offset");
if let Some(row) = self.scroll_to.take() {
let view_h = ui.available_height();
- let top = row as f32 * ROW_H;
+ let top = row as f32 * ROW_PITCH;
// Only scroll if the row is outside the visible part.
let offset = ui.data(|d| d.get_temp::<f32>(offset_id)).unwrap_or(0.0);
- if top < offset || top + ROW_H > offset + view_h {
+ if top < offset || top + ROW_PITCH > offset + view_h {
scroll = scroll.vertical_scroll_offset((top - view_h / 2.0).max(0.0));
}
}
- // `show_rows` sizes rows as ROW_H + item spacing, so the spacing must be zero here.
+ // `show_rows` sizes rows as ROW_PITCH + item spacing, so the spacing must be zero here.
ui.spacing_mut().item_spacing.y = 0.0;
let idle = self.busy_op.is_none();
let now = git::now();
let total = self.commits.len() + usize::from(self.has_more);
- let out = scroll.show_rows(ui, ROW_H, total, |ui, range| {
+ let out = scroll.show_rows(ui, ROW_PITCH, total, |ui, range| {
// Near the end: fetch the next page of history.
if range.end + 40 >= self.commits.len() && self.has_more && !self.loading_more {
acts.push(Action::LoadMore);
}
for i in range {
if i >= self.commits.len() {
- let (rect, _) =
- ui.allocate_exact_size(vec2(ui.available_width(), ROW_H), Sense::hover());
+ let (rect, _) = ui
+ .allocate_exact_size(vec2(ui.available_width(), ROW_PITCH), Sense::hover());
ui.painter().text(
rect.center(),
Align2::CENTER_CENTER,
@@ -249,6 +254,29 @@ impl RepoTab {
/// Right-click menu of a commit row.
fn commit_menu(&self, resp: &Response, i: usize, idle: bool, acts: &mut Vec<Action>) {
+ let Some(commit) = self.commits.get(i) else {
+ return;
+ };
+ // The branch whose pill was right-clicked, if any.
+ let pill: Option<String> = resp
+ .ctx
+ .data(|d| d.get_temp::<Option<String>>(pill_menu_id(&commit.hash)))
+ .flatten();
+ egui::Popup::context_menu(resp)
+ .style(crate::theme::menu_style)
+ .show(|ui| self.commit_menu_items(ui, i, pill, idle, acts));
+ }
+
+ /// The entries of a commit's menu; `pill` is the branch whose pill was right-clicked, whose
+ /// actions go on top.
+ fn commit_menu_items(
+ &self,
+ ui: &mut Ui,
+ i: usize,
+ pill: Option<String>,
+ idle: bool,
+ acts: &mut Vec<Action>,
+ ) {
let Some(commit) = self.commits.get(i) else {
return;
};
@@ -263,11 +291,7 @@ impl RepoTab {
.iter()
.filter(|b| b.target == hash)
.collect();
- // The branch whose pill was right-clicked, else the commit's first branch for copying.
- let pill: Option<String> = resp
- .ctx
- .data(|d| d.get_temp::<Option<String>>(pill_menu_id(&hash)))
- .flatten();
+ // The right-clicked branch, else the commit's first branch, for copying.
let branch_name = pill.clone().or_else(|| {
badges(&commit.refs, &self.refs)
.into_iter()
@@ -279,165 +303,166 @@ impl RepoTab {
.current
.clone()
.unwrap_or_else(|| "HEAD".to_owned());
- egui::Popup::context_menu(resp).style(crate::theme::menu_style).show(|ui| {
- if let Some(branch) = &pill
- && self.refs.current.as_deref() != Some(branch.as_str())
+ if let Some(branch) = &pill
+ && self.refs.current.as_deref() != Some(branch.as_str())
+ {
+ if ui
+ .add_enabled(idle, egui::Button::new(format!("Check out {branch}")))
+ .clicked()
{
+ let local = self.refs.local.iter().any(|b| &b.name == branch);
+ acts.push(if local {
+ Action::Checkout(branch.clone())
+ } else {
+ Action::CheckoutRemote(branch.clone())
+ });
+ }
+ if let Some(current) = self.refs.current.as_deref() {
if ui
- .add_enabled(idle, egui::Button::new(format!("Check out {branch}")))
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Fast-forward {current} to {branch}")),
+ )
.clicked()
{
- let local = self.refs.local.iter().any(|b| &b.name == branch);
- acts.push(if local {
- Action::Checkout(branch.clone())
- } else {
- Action::CheckoutRemote(branch.clone())
- });
+ acts.push(fast_forward_action(branch, current));
}
- if let Some(current) = self.refs.current.as_deref() {
- if ui
- .add_enabled(
- idle,
- egui::Button::new(format!("Fast-forward {current} to {branch}")),
- )
- .clicked()
- {
- acts.push(fast_forward_action(branch, current));
- }
- if ui
- .add_enabled(
- idle,
- egui::Button::new(format!("Merge {branch} into {current}")),
- )
- .clicked()
- {
- acts.push(merge_action(branch, current));
- }
- if ui
- .add_enabled(
- idle,
- egui::Button::new(format!("Rebase {current} onto {branch}")),
- )
- .clicked()
- {
- acts.push(rebase_action(branch, current));
- }
- if ui
- .add_enabled(
- idle,
- egui::Button::new(format!(
- "Interactive rebase {current} onto {branch}…"
- )),
- )
- .clicked()
- {
- acts.push(Action::InteractiveRebase {
- onto: branch.clone(),
- label: branch.clone(),
- });
- }
- ui.separator();
- compare_items(ui, acts, branch, current);
+ if ui
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Merge {branch} into {current}")),
+ )
+ .clicked()
+ {
+ acts.push(merge_action(branch, current));
}
- ui.separator();
- }
- for b in &here {
- ui.menu_button(format!("Branch {}", b.name), |ui| {
- self.branch_menu_items(ui, acts, b, idle);
- });
- }
- if !here.is_empty() {
- ui.separator();
- }
- if ui.button("Create branch here…").clicked() {
- acts.push(Action::Dialog(Dialog::create_branch(&hash, &short)));
- }
- if ui.button("Create tag here…").clicked() {
- acts.push(Action::Dialog(Dialog::tag(&hash, &short, self.default_remote())));
- }
- if ui
- .add_enabled(
- idle && !is_head,
- egui::Button::new("Check out this commit (detached)"),
- )
- .clicked()
- {
- acts.push(Action::Checkout(hash.clone()));
- }
- ui.separator();
- if let Some(compare) = self
- .selected
- .filter(|&s| s != i)
- .and_then(|s| self.compare_rows(s, i))
- {
- let other = self
- .selected
- .and_then(|s| self.commits.get(s))
- .map(|c| {
- if c.hash == WIP_HASH {
- "the working tree".to_owned()
- } else {
- super::short(&c.hash).to_owned()
- }
- })
- .unwrap_or_default();
if ui
- .button(format!("Compare with {other}"))
- .on_hover_text("Also Ctrl+click on a commit")
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Rebase {current} onto {branch}")),
+ )
.clicked()
{
- acts.push(compare);
+ acts.push(rebase_action(branch, current));
}
- }
- if ui.button("Compare with the working tree").clicked() {
- acts.push(Action::Compare {
- base: hash.clone(),
- base_label: short.clone(),
- target: None,
- target_label: "working tree".to_owned(),
- since_fork: false,
- });
+ if ui
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Interactive rebase {current} onto {branch}…")),
+ )
+ .clicked()
+ {
+ acts.push(Action::InteractiveRebase {
+ onto: branch.clone(),
+ label: branch.clone(),
+ });
+ }
+ ui.separator();
+ compare_items(ui, acts, branch, current);
}
ui.separator();
+ }
+ for b in &here {
+ ui.menu_button(format!("Branch {}", b.name), |ui| {
+ self.branch_menu_items(ui, acts, b, idle);
+ });
+ }
+ if !here.is_empty() {
+ ui.separator();
+ }
+ if ui.button("Create branch here…").clicked() {
+ acts.push(Action::Dialog(Dialog::create_branch(&hash, &short)));
+ }
+ if ui.button("Create tag here…").clicked() {
+ acts.push(Action::Dialog(Dialog::tag(
+ &hash,
+ &short,
+ self.default_remote(),
+ )));
+ }
+ if ui
+ .add_enabled(
+ idle && !is_head,
+ egui::Button::new("Check out this commit (detached)"),
+ )
+ .clicked()
+ {
+ acts.push(Action::Checkout(hash.clone()));
+ }
+ ui.separator();
+ if let Some(compare) = self
+ .selected
+ .filter(|&s| s != i)
+ .and_then(|s| self.compare_rows(s, i))
+ {
+ let other = self
+ .selected
+ .and_then(|s| self.commits.get(s))
+ .map(|c| {
+ if c.hash == WIP_HASH {
+ "the working tree".to_owned()
+ } else {
+ super::short(&c.hash).to_owned()
+ }
+ })
+ .unwrap_or_default();
if ui
- .add_enabled(
- idle && !is_head,
- egui::Button::new(format!("Interactive rebase {target} onto this commit…")),
- )
- .on_hover_text("Reorder, reword, squash or drop the commits after this one")
- .clicked()
- {
- acts.push(Action::InteractiveRebase {
- onto: hash.clone(),
- label: short.clone(),
- });
- }
- if ui
- .add_enabled(
- idle && !is_head,
- egui::Button::new("Cherry-pick onto current branch"),
- )
- .clicked()
- {
- acts.push(Action::UndoableOps {
- label: format!("Cherry-pick {short}"),
- ops: ops(&[&["cherry-pick", &hash]]),
- refresh: Refresh::All,
- undo: Undo::HeadMove { mode: "--keep" },
- });
- }
- if ui
- .add_enabled(idle, egui::Button::new("Revert commit"))
+ .button(format!("Compare with {other}"))
+ .on_hover_text("Also Ctrl+click on a commit")
.clicked()
{
- acts.push(Action::UndoableOps {
- label: format!("Revert {short}"),
- ops: ops(&[&["revert", "--no-edit", &hash]]),
- refresh: Refresh::All,
- undo: Undo::HeadMove { mode: "--keep" },
- });
+ acts.push(compare);
}
- ui.add_enabled_ui(idle && !is_head, |ui| {
+ }
+ if ui.button("Compare with the working tree").clicked() {
+ acts.push(Action::Compare {
+ base: hash.clone(),
+ base_label: short.clone(),
+ target: None,
+ target_label: "working tree".to_owned(),
+ since_fork: false,
+ });
+ }
+ ui.separator();
+ if ui
+ .add_enabled(
+ idle && !is_head,
+ egui::Button::new(format!("Interactive rebase {target} onto this commit…")),
+ )
+ .on_hover_text("Reorder, reword, squash or drop the commits after this one")
+ .clicked()
+ {
+ acts.push(Action::InteractiveRebase {
+ onto: hash.clone(),
+ label: short.clone(),
+ });
+ }
+ if ui
+ .add_enabled(
+ idle && !is_head,
+ egui::Button::new("Cherry-pick onto current branch"),
+ )
+ .clicked()
+ {
+ acts.push(Action::UndoableOps {
+ label: format!("Cherry-pick {short}"),
+ ops: ops(&[&["cherry-pick", &hash]]),
+ refresh: Refresh::All,
+ undo: Undo::HeadMove { mode: "--keep" },
+ });
+ }
+ if ui
+ .add_enabled(idle, egui::Button::new("Revert commit"))
+ .clicked()
+ {
+ acts.push(Action::UndoableOps {
+ label: format!("Revert {short}"),
+ ops: ops(&[&["revert", "--no-edit", &hash]]),
+ refresh: Refresh::All,
+ undo: Undo::HeadMove { mode: "--keep" },
+ });
+ }
+ ui.add_enabled_ui(idle && !is_head, |ui| {
ui.menu_button(format!("Reset {target} to here"), |ui| {
for (mode, undo_mode, label, explain) in [
("--soft", "--soft", "Soft", "Keeps every change, staged."),
@@ -459,29 +484,41 @@ impl RepoTab {
}
});
});
- ui.separator();
- if ui.button("Copy commit hash").clicked() {
- ui.ctx().copy_text(hash.clone());
- }
- if ui.button("Copy message").clicked() {
- ui.ctx().copy_text(summary.clone());
- }
- if let Some(name) = &branch_name
- && ui.button(format!("Copy branch name ({name})")).clicked()
- {
- ui.ctx().copy_text(name.clone());
- }
- });
+ ui.separator();
+ if ui.button("Copy commit hash").clicked() {
+ ui.ctx().copy_text(hash.clone());
+ }
+ if ui.button("Copy message").clicked() {
+ ui.ctx().copy_text(summary.clone());
+ }
+ if let Some(name) = &branch_name
+ && ui.button(format!("Copy branch name ({name})")).clicked()
+ {
+ ui.ctx().copy_text(name.clone());
+ }
}
/// What double-clicking a pill does: check out that branch (a tracking branch for one only on
- /// a remote) or tag. Nothing for the checked-out one or while an operation runs.
+ /// a remote, and pulling a local one behind its upstream) or tag. Nothing for the checked-out
+ /// one or while an operation runs.
fn pill_checkout(&self, badge: &Badge) -> Option<Action> {
if badge.head || self.busy_op.is_some() {
return None;
}
match badge.kind {
- BadgeKind::Branch if badge.local => Some(Action::Checkout(badge.label.clone())),
+ BadgeKind::Branch if badge.local => {
+ let behind = self
+ .refs
+ .local
+ .iter()
+ .find(|b| b.name == badge.label)
+ .is_some_and(|b| matches!(b.ahead_behind(), (0, behind) if behind > 0));
+ Some(if behind {
+ Action::CheckoutPull(badge.label.clone())
+ } else {
+ Action::Checkout(badge.label.clone())
+ })
+ }
BadgeKind::Branch => badge
.remotes
.first()
@@ -508,10 +545,14 @@ impl RepoTab {
let t = Tokens::get(ui.ctx());
let id = ui.id().with(("ref_stack", i));
let last: Option<Rect> = ui.data(|d| d.get_temp(id));
- let open = ui
- .ctx()
- .pointer_hover_pos()
- .is_some_and(|p| more.contains(p) || last.is_some_and(|r| r.expand(2.0).contains(p)));
+ let slot_id = |n: usize| id.with(("slot", n));
+ // A pill's menu keeps the list up while the pointer is on the menu.
+ let menu_open =
+ (0..badges.len()).any(|n| egui::Popup::is_id_open(ui.ctx(), slot_id(n).with("popup")));
+ let open = menu_open
+ || ui.ctx().pointer_hover_pos().is_some_and(|p| {
+ more.contains(p) || last.is_some_and(|r| r.expand(2.0).contains(p))
+ });
if !open {
ui.data_mut(|d| d.remove::<Rect>(id));
return false;
@@ -525,10 +566,14 @@ impl RepoTab {
.inner_margin(egui::Margin::same(6))
.show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 4.0;
- for b in badges {
- let (slot, resp) =
- ui.allocate_exact_size(vec2(slot_w, 20.0), Sense::click());
- if resp.hovered() {
+ for (n, b) in badges.iter().enumerate() {
+ let (slot, _) =
+ ui.allocate_exact_size(vec2(slot_w, 20.0), Sense::hover());
+ let resp = ui.interact(slot, slot_id(n), Sense::click());
+ if resp.hovered()
+ || menu_open
+ && egui::Popup::is_id_open(ui.ctx(), slot_id(n).with("popup"))
+ {
ui.painter().rect_filled(
slot.expand(2.0),
CornerRadius::same(t.radius as u8),
@@ -551,6 +596,19 @@ impl RepoTab {
} else if resp.clicked() {
acts.push(Action::Select(i));
}
+ // The same menu as right-clicking the row's own pill.
+ let branch = (b.kind == BadgeKind::Branch).then(|| b.git_ref());
+ egui::Popup::context_menu(&resp)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ self.commit_menu_items(
+ ui,
+ i,
+ branch,
+ self.busy_op.is_none(),
+ acts,
+ )
+ });
}
});
});
@@ -658,24 +716,26 @@ impl RepoTab {
) -> Response {
let t = Tokens::get(ui.ctx());
let (rect, resp) =
- ui.allocate_exact_size(vec2(ui.available_width(), ROW_H), Sense::click());
+ ui.allocate_exact_size(vec2(ui.available_width(), ROW_PITCH), Sense::click());
let Some(commit) = self.commits.get(i) else {
return resp;
};
let painter = ui.painter_at(rect);
let is_wip = commit.hash == WIP_HASH;
let is_match = self.search.matches.contains(&commit.hash);
+ // The row's own band, without the gap.
+ let band = rect.shrink2(vec2(0.0, ROW_GAP / 2.0));
if self.selected == Some(i) {
- painter.rect_filled(rect, 0.0, t.row_selected);
+ painter.rect_filled(band, 0.0, t.row_selected);
} else if resp.hovered() {
- painter.rect_filled(rect, 0.0, t.hover);
+ painter.rect_filled(band, 0.0, t.hover);
} else if is_match {
- painter.rect_filled(rect, 0.0, t.warning.gamma_multiply(0.10));
+ painter.rect_filled(band, 0.0, t.warning.gamma_multiply(0.10));
}
if is_match {
painter.rect_filled(
- Rect::from_min_size(rect.min, vec2(3.0, ROW_H)),
+ Rect::from_min_size(band.min, vec2(3.0, ROW_H)),
0.0,
t.warning,
);
@@ -692,7 +752,7 @@ impl RepoTab {
});
if compared {
painter.rect_stroke(
- rect.shrink(1.0),
+ band.shrink(1.0),
0.0,
Stroke::new(1.0, t.accent),
egui::StrokeKind::Inside,
@@ -814,9 +874,10 @@ impl RepoTab {
// Graph.
if let Some(row) = self.graph.rows.get(i) {
- let gp = painter.with_clip_rect(
- rect.intersect(Rect::from_min_size(pos2(gx, top), vec2(cols.graph, ROW_H))),
- );
+ let gp = painter.with_clip_rect(rect.intersect(Rect::from_min_size(
+ pos2(gx, top),
+ vec2(cols.graph, rect.height()),
+ )));
let node = pos2(x(row.col), mid);
let width = 2.0;
@@ -829,11 +890,11 @@ impl RepoTab {
}
}
for &lane in &row.incoming {
- curve(&gp, pos2(x(lane), top), node, t.lane(lane), width);
+ edge(&gp, node, pos2(x(lane), top), t.lane(lane), width);
}
for &lane in &row.outgoing {
let color = if is_wip { t.text_faint } else { t.lane(lane) };
- curve(&gp, node, pos2(x(lane), bottom), color, width);
+ edge(&gp, node, pos2(x(lane), bottom), color, width);
}
if is_wip {
@@ -1237,18 +1298,28 @@ fn circle_points(center: Pos2, radius: f32, n: usize) -> Vec<Pos2> {
.collect()
}
-fn curve(p: &egui::Painter, from: Pos2, to: Pos2, color: Color32, width: f32) {
- if (from.x - to.x).abs() < 0.5 {
- p.line_segment([from, to], Stroke::new(width, color));
- } else {
- let midy = (from.y + to.y) / 2.0;
- p.add(CubicBezierShape::from_points_stroke(
- [from, pos2(from.x, midy), pos2(to.x, midy), to],
- false,
- Color32::TRANSPARENT,
- Stroke::new(width, color),
- ));
+/// Joins a commit's dot to another lane at `end` (the row's top or bottom): straight across
+/// the row from the dot, a small rounded corner, then straight along the lane.
+fn edge(p: &egui::Painter, node: Pos2, end: Pos2, color: Color32, width: f32) {
+ let stroke = Stroke::new(width, color);
+ let dx = end.x - node.x;
+ if dx.abs() < 0.5 {
+ p.line_segment([node, end], stroke);
+ return;
+ }
+ let dy = end.y - node.y;
+ let r = CORNER_R.min(dx.abs()).min(dy.abs());
+ let (sx, sy) = (dx.signum(), dy.signum());
+ // The corner's centre: inside the turn, `r` before the lane and `r` past the dot's row.
+ let c = pos2(end.x - sx * r, node.y + sy * r);
+ let mut points = vec![node];
+ const STEPS: usize = 8;
+ for k in 0..=STEPS {
+ let a = k as f32 / STEPS as f32 * std::f32::consts::FRAC_PI_2;
+ points.push(c + vec2(sx * r * a.sin(), -sy * r * a.cos()));
}
+ points.push(end);
+ p.add(egui::Shape::line(points, stroke));
}
#[cfg(test)]
diff --git a/src/repo/mod.rs b/src/repo/mod.rs
index c44001c..ccba7c1 100644
--- a/src/repo/mod.rs
+++ b/src/repo/mod.rs
@@ -239,6 +239,8 @@ pub(crate) enum Action {
undo: Undo,
},
Checkout(String),
+ /// Checks out a local branch behind its upstream, then fast-forwards it.
+ CheckoutPull(String),
CheckoutRemote(String),
Dialog(Dialog),
Commit,
@@ -1020,6 +1022,40 @@ impl RepoTab {
);
}
+ /// Checkout and `pull --ff-only`; undoing goes back and puts the branch where it was.
+ fn checkout_pull(&mut self, branch: &str, ctx: &egui::Context) {
+ let previous = self
+ .refs
+ .current
+ .clone()
+ .unwrap_or_else(|| self.refs.head.clone());
+ let Some(was) = self
+ .refs
+ .local
+ .iter()
+ .find(|b| b.name == branch)
+ .map(|b| b.target.clone())
+ else {
+ return self.checkout(branch, ctx);
+ };
+ let run = ops(&[&["checkout", branch], &["pull", "--ff-only"]]);
+ let undo = if previous.is_empty() {
+ Undo::None
+ } else {
+ Undo::Custom {
+ undo: ops(&[&["checkout", &previous], &["branch", "-f", branch, &was]]),
+ redo: run.clone(),
+ }
+ };
+ self.run_undoable(
+ &format!("Checkout and pull {branch}"),
+ run,
+ Refresh::All,
+ undo,
+ ctx,
+ );
+ }
+
fn checkout_remote(&mut self, remote_branch: &str, ctx: &egui::Context) {
// `origin/feature` → local `feature` tracking it (or just switch if it exists).
let local = remote_branch
@@ -1609,6 +1645,7 @@ impl RepoTab {
undo,
} => self.run_undoable(&label, ops, refresh, undo, ctx),
Action::Checkout(name) => self.checkout(&name, ctx),
+ Action::CheckoutPull(name) => self.checkout_pull(&name, ctx),
Action::CheckoutRemote(name) => self.checkout_remote(&name, ctx),
Action::Dialog(dialog) => self.dialog = Some(dialog),
Action::Commit => self.commit(ctx),
diff --git a/src/repo/sidebar.rs b/src/repo/sidebar.rs
index d0213a2..2392466 100644
--- a/src/repo/sidebar.rs
+++ b/src/repo/sidebar.rs
@@ -3,7 +3,7 @@
use egui::{Align2, Rect, Response, Sense, Ui, pos2, vec2};
-use super::widgets::{self, ROW_H};
+use super::widgets;
use super::{
Action, Dialog, Refresh, RepoTab, Undo, compare_action, fast_forward_action, merge_action, ops,
rebase_action,
@@ -12,6 +12,9 @@ use crate::git::{self, Branch};
use crate::icons;
use crate::theme::{self, Tokens};
+/// The pane's rows: a little taller than the file lists', 2 px more above and below.
+const ROW_H: f32 = widgets::ROW_H + 4.0;
+
impl RepoTab {
pub(super) fn sidebar(&mut self, ui: &mut Ui, acts: &mut Vec<Action>) {
let t = Tokens::get(ui.ctx());
diff --git a/src/settings.rs b/src/settings.rs
index 6185f75..e41974a 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -36,7 +36,7 @@ pub struct Settings {
pub editor: String,
/// Desktop notifications when a long operation ends while the window is in the background.
pub notifications: bool,
- /// Ask GitHub once a day whether a newer release exists.
+ /// Ask GitHub every 12 hours whether a newer release exists.
pub check_updates: bool,
/// Colour code in diffs and blame with VS Code's current theme, when it has one.
pub vscode_colors: bool,
@@ -152,7 +152,7 @@ impl Settings {
ui.end_row();
}
ui.label("Updates");
- ui.checkbox(&mut self.check_updates, "Check GitHub for a new version once a day");
+ ui.checkbox(&mut self.check_updates, "Check GitHub for a new version every 12 hours");
ui.end_row();
});
diff --git a/src/tab_look.rs b/src/tab_look.rs
new file mode 100644
index 0000000..06c7b60
--- /dev/null
+++ b/src/tab_look.rs
@@ -0,0 +1,184 @@
+//! A repository tab's own icon and highlight colour, picked from the tab's right-click menu.
+
+use egui::{Color32, Rect, RichText, Sense, Stroke, Ui, vec2};
+use serde::{Deserialize, Serialize};
+
+use crate::icons;
+use crate::theme::{self, Tokens};
+
+/// The icons a tab can wear: (icon, what it suggests). The first is the default.
+pub const ICONS: &[(&str, &str)] = &[
+ ("folder-git-2", "Repository"),
+ ("code", "Code"),
+ ("globe", "Web"),
+ ("smartphone", "Mobile"),
+ ("server", "Server"),
+ ("database", "Database"),
+ ("package", "Library"),
+ ("square-terminal", "Tool"),
+ ("rocket", "Launch"),
+ ("gamepad-2", "Game"),
+ ("flask-conical", "Experiment"),
+ ("book-open", "Docs"),
+ ("palette", "Design"),
+ ("wrench", "Config"),
+ ("star", "Favourite"),
+ ("heart", "Personal"),
+];
+
+#[derive(Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub enum TabColor {
+ #[default]
+ Blue,
+ Teal,
+ Green,
+ Yellow,
+ Orange,
+ Red,
+ Pink,
+ Purple,
+ Gray,
+}
+
+impl TabColor {
+ pub const ALL: [TabColor; 9] = [
+ TabColor::Blue,
+ TabColor::Teal,
+ TabColor::Green,
+ TabColor::Yellow,
+ TabColor::Orange,
+ TabColor::Red,
+ TabColor::Pink,
+ TabColor::Purple,
+ TabColor::Gray,
+ ];
+
+ pub fn label(self) -> &'static str {
+ match self {
+ TabColor::Blue => "Blue",
+ TabColor::Teal => "Teal",
+ TabColor::Green => "Green",
+ TabColor::Yellow => "Yellow",
+ TabColor::Orange => "Orange",
+ TabColor::Red => "Red",
+ TabColor::Pink => "Pink",
+ TabColor::Purple => "Purple",
+ TabColor::Gray => "Gray",
+ }
+ }
+
+ /// Blue is the theme's accent; the others are the same in every theme.
+ pub fn color(self, t: &Tokens) -> Color32 {
+ match self {
+ TabColor::Blue => t.accent,
+ TabColor::Teal => Color32::from_rgb(20, 178, 160),
+ TabColor::Green => Color32::from_rgb(64, 180, 96),
+ TabColor::Yellow => Color32::from_rgb(230, 178, 20),
+ TabColor::Orange => Color32::from_rgb(240, 128, 40),
+ TabColor::Red => Color32::from_rgb(230, 72, 72),
+ TabColor::Pink => Color32::from_rgb(232, 80, 156),
+ TabColor::Purple => Color32::from_rgb(150, 104, 236),
+ TabColor::Gray => Color32::from_rgb(140, 142, 152),
+ }
+ }
+}
+
+/// How a repository's tab looks.
+#[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(default)]
+pub struct TabLook {
+ /// One of [`ICONS`]; `None` for the default.
+ pub icon: Option<String>,
+ pub color: TabColor,
+}
+
+impl TabLook {
+ pub fn icon(&self) -> &str {
+ self.icon.as_deref().unwrap_or(ICONS[0].0)
+ }
+}
+
+/// The menu's icon grid and colour swatches; returns the look picked, if any.
+pub fn menu(ui: &mut Ui, look: &TabLook) -> Option<TabLook> {
+ let t = Tokens::get(ui.ctx());
+ let accent = look.color.color(&t);
+ let mut picked = None;
+ let heading = |ui: &mut Ui, text: &str| {
+ ui.label(
+ RichText::new(text)
+ .font(theme::semibold(10.5))
+ .color(t.text_faint),
+ );
+ };
+
+ // Menus have no side margin of their own (their buttons pad themselves); the grids get one.
+ egui::Frame::new()
+ .inner_margin(egui::Margin::symmetric(14, 8))
+ .show(ui, |ui| {
+ heading(ui, "ICON");
+ for row in ICONS.chunks(8) {
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 2.0;
+ for &(name, what) in row {
+ let (rect, resp) = ui.allocate_exact_size(vec2(28.0, 28.0), Sense::click());
+ let current = look.icon() == name;
+ if current {
+ ui.painter().rect_filled(
+ rect,
+ t.radius_sm,
+ accent.gamma_multiply(0.22),
+ );
+ } else if resp.hovered() {
+ ui.painter().rect_filled(rect, t.radius_sm, t.hover);
+ }
+ let tint = if current { accent } else { t.text_dim };
+ icons::paint(
+ ui,
+ Rect::from_center_size(rect.center(), vec2(16.0, 16.0)),
+ name,
+ 15.0,
+ tint,
+ );
+ if resp.on_hover_text(what).clicked() {
+ picked = Some(TabLook {
+ icon: (name != ICONS[0].0).then(|| name.to_owned()),
+ ..look.clone()
+ });
+ }
+ }
+ });
+ }
+
+ ui.add_space(6.0);
+ heading(ui, "HIGHLIGHT");
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 2.0;
+ for color in TabColor::ALL {
+ let (rect, resp) = ui.allocate_exact_size(vec2(25.0, 25.0), Sense::click());
+ let c = rect.center();
+ if color == look.color {
+ ui.painter()
+ .circle_stroke(c, 10.0, Stroke::new(1.5, t.text));
+ } else if resp.hovered() {
+ ui.painter()
+ .circle_stroke(c, 10.0, Stroke::new(1.5, t.text_faint));
+ }
+ ui.painter().circle_filled(c, 7.0, color.color(&t));
+ if resp.on_hover_text(color.label()).clicked() {
+ picked = Some(TabLook {
+ color,
+ ..look.clone()
+ });
+ }
+ }
+ });
+ });
+
+ if *look != TabLook::default() {
+ ui.separator();
+ if ui.button("Reset to the default look").clicked() {
+ picked = Some(TabLook::default());
+ }
+ }
+ picked
+}
diff --git a/src/update.rs b/src/update.rs
index 4c0c4bc..b776c36 100644
--- a/src/update.rs
+++ b/src/update.rs
@@ -1,4 +1,4 @@
-//! Asks GitHub whether a newer gitcraft release exists (at most once a day, can be turned off).
+//! Asks GitHub whether a newer gitcraft release exists (at most every 12 hours, can be turned off).
use std::time::Duration;
@@ -9,7 +9,7 @@ pub const CURRENT: &str = env!("CARGO_PKG_VERSION");
/// (VPNs, offices) use up.
const LATEST: &str = "https://github.com/Vancete/gitcraft/releases/latest";
/// Seconds between two checks.
-pub const INTERVAL: i64 = 24 * 3600;
+pub const INTERVAL: i64 = 12 * 3600;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Release {