Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Its tests run against real repositories made with `git` in a temporary folder
- `start.rs` (open, clone and create), `ui.rs` (tabs and toolbar), `graph.rs`, `sidebar.rs`, `details.rs`,
`diff.rs`, `history.rs` (a file's history), `blame.rs` (who last changed each line),
`merge.rs` (a conflicted file) and `rebase.rs` (an interactive rebase) draw the views, and
`theme.rs` has the colours and how dates read. `settings.rs` has the settings, which egui keeps
`theme.rs` has the colours, for a dark and for a light background, and how dates read. `settings.rs` has the settings, which egui keeps
in its memory and eframe saves between runs, and the window to change them in. `syntax.rs` colours code with the grammar of its language, from
the top of the file, so a diff reads both versions of the file in the background to colour it.

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ GitCraft is young. This is what it does today; [ROADMAP.md](ROADMAP.md) has what
Escape goes back to the graph. While you type in a field, the field keeps its keys, apart from
Ctrl+Enter.
- **Settings**: Settings, at the right of the tabs, or Ctrl+, (Cmd+, on a Mac). Zoom everything
larger or smaller (Ctrl+Plus, Ctrl+Minus and Ctrl+0 do that anywhere), show dates as how long
ago or as the date and the time, and have Pull rebase rather than merge. They hold for every
repository and stay for the next run.
larger or smaller (Ctrl+Plus, Ctrl+Minus and Ctrl+0 do that anywhere), pick the dark or the
light theme or the one your system uses, show dates as how long ago or as the date and the time,
and have Pull rebase rather than merge. They hold for every repository and stay for the next
run.
- **Safe by default**: a hard reset, deleting a branch with commits no other branch or tag has, a
force push, dropping a stash and removing a remote all ask first, saying what will be lost.

Expand Down
7 changes: 4 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ drive it the way a user does, and keeps every benchmark as fast as before.
create in the palette
- [x] Settings, part 1: a settings window (also Ctrl+,) to zoom, to pick how dates read, and
whether Pull merges or rebases; they last between runs
- [x] Settings, part 2: a light theme beside the dark one, or the one the system uses; the
graph, diffs, code and conflicts take colours made for it

## Next

1. **Settings, part 2**: a light theme beside the dark one, or the one the system uses.
2. **Graph polish**: resizable columns, compact lanes, author avatars (optional, never by default
1. **Graph polish**: resizable columns, compact lanes, author avatars (optional, never by default
over the network).
3. **Packaging**: installers with the icon for Windows (MSI), macOS (.app in a .dmg) and Linux
2. **Packaging**: installers with the icon for Windows (MSI), macOS (.app in a .dmg) and Linux
(AppImage, .deb, Flatpak), signed where the platform expects it.

## After 1.0
Expand Down
18 changes: 12 additions & 6 deletions crates/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ pub enum Versions {
None,
/// A picture's.
Pictures([Version; 2]),
/// The lines of code, with their colours; none in a language without colours.
Code([Vec<syntax::Line>; 2]),
/// The lines of code, with their colours in a theme; none in a language without colours.
Code(egui::Theme, [Vec<syntax::Line>; 2]),
}

/// A version of a picture, or why it does not show; `None` when the version does not have the file.
Expand Down Expand Up @@ -258,15 +258,14 @@ impl OpenFile {
if binary && !format.is_ok_and(|format| format.reading_enabled()) || !binary && link {
return;
}
let (repo, source, context) = (repo.clone(), self.source.clone(), ctx.clone());
let (repo, source, context, theme) = (repo.clone(), self.source.clone(), ctx.clone(), ctx.theme());
self.reading = Some(read_in_background(ctx, move || {
let (versions, path) = (repo.versions(&source)?, source.path());
Ok(if binary {
Versions::Pictures(versions.map(|version| version.map(|bytes| picture(&context, path, &bytes))))
} else {
Versions::Code(
versions.map(|version| version.map_or_else(Vec::new, |code| syntax::colour(path, &code))),
)
let colour = |code: Vec<u8>| syntax::colour(path, &code, theme);
Versions::Code(theme, versions.map(|version| version.map_or_else(Vec::new, colour)))
})
}));
}
Expand Down Expand Up @@ -979,6 +978,13 @@ impl Workspace {
/// Takes in the result of the background job, once it is there, and starts the next.
pub fn poll(&mut self, ctx: &egui::Context) {
self.take_reading(ctx);
// Code is coloured for one theme: in another, it is coloured again.
if let Some(file) = &mut self.open_file
&& file.reading.is_none()
&& matches!(file.versions, Versions::Code(theme, _) if theme != ctx.theme())
{
file.read_versions(ctx, &self.repo);
}
let Some(job) = &self.job else { return };
let (failed, snapshot, watch) = match job.outcome.try_recv() {
Err(TryRecvError::Empty) => return,
Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn show(ui: &mut Ui, ws: &mut Workspace, actions: &mut Vec<Action>) {
/// One changed file: its kind of change, its path, and `buttons` on the right, right to left.
/// Returns the path.
fn file(ui: &mut Ui, change: Change, path: &str, open: bool, buttons: impl FnOnce(&mut Ui)) -> Response {
let (letter, colour) = theme::change(change);
let (letter, colour) = theme::colours(ui.ctx().theme()).change(change);
ui.horizontal(|ui| {
ui.with_layout(Layout::right_to_left(egui::Align::Center), |ui| {
buttons(ui);
Expand Down Expand Up @@ -193,7 +193,7 @@ fn commit(ui: &mut Ui, ws: &mut Workspace, id: ObjectId, actions: &mut Vec<Actio
let commit = match ws.commits.get(&ws.repo, id) {
Ok(commit) => commit.clone(),
Err(error) => {
ui.colored_label(theme::ERROR, error.to_string());
ui.colored_label(ui.visuals().error_fg_color, error.to_string());
return;
}
};
Expand Down
13 changes: 9 additions & 4 deletions crates/app/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,18 @@ fn line(
let line = &hunk.lines[l];
let numbers = [line.old, line.new];
let numbers = side.map_or(&numbers[..], |side| &numbers[side..=side]);
let palette = theme::colours(ui.ctx().theme());
let (background, word, marker) = match line.kind {
LineKind::Added => (theme::ADDED, theme::ADDED_WORD, "+ "),
LineKind::Removed => (theme::REMOVED, theme::REMOVED_WORD, "- "),
LineKind::Added => (palette.added, palette.added_word, "+ "),
LineKind::Removed => (palette.removed, palette.removed_word, "- "),
LineKind::Context | LineKind::NoNewline => (Color32::TRANSPARENT, Color32::TRANSPARENT, " "),
};
let painter = ui.painter_at(rect);
painter.rect_filled(rect, 0.0, if file.lines.contains(&(h, l)) { theme::PICKED } else { background });
painter.rect_filled(
rect,
0.0,
if file.lines.contains(&(h, l)) { ui.visuals().selection.bg_fill } else { background },
);
let at = |x: f32| rect.left_center() + Vec2::X * x;
let mut x = 0.0;
for n in numbers {
Expand All @@ -280,7 +285,7 @@ fn line(
let text = line.text.trim_end_matches('\r');
// The line's colours, as long as the version read has the same line there.
let colours = match &file.versions {
Versions::Code(code) => [line.old, line.new][version]
Versions::Code(_, code) => [line.old, line.new][version]
.and_then(|n| code[version].get((n as usize).checked_sub(1)?))
.filter(|coloured| coloured.text == text)
.map(|coloured| &coloured.colours[..]),
Expand Down
28 changes: 17 additions & 11 deletions crates/app/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn show(ui: &mut Ui, ws: &mut Workspace, actions: &mut Vec<Action>) {
let head = history.head == Some(index);
let merge = history.graph.parents(index).len() > 1;
paint_row(&painter.with_clip_rect(graph), row, lane_x, merge, (head, head && wip == 1 && index == 0));
let colour = theme::lane(row.lane);
let colour = theme::colours(ui.ctx().theme()).lane(row.lane);
paint_labels(&painter, rect.with_max_x(rect.left() + labels_width), labels, colour, current.as_deref());
match ws.commits.get(&ws.repo, id) {
Ok(commit) => {
Expand All @@ -111,7 +111,7 @@ pub fn show(ui: &mut Ui, ws: &mut Workspace, actions: &mut Vec<Action>) {
let date = Rect::from_x_y_ranges(rect.right() - date_width..=rect.right() - 8.0, rect.y_range());
put(ui, date, egui::RichText::new(dates.when(commit.time)).weak());
}
Err(error) => put(ui, text, egui::RichText::new(error.to_string()).color(theme::ERROR)),
Err(error) => put(ui, text, egui::RichText::new(error.to_string()).color(ui.visuals().error_fg_color)),
}
if response.clicked() {
actions.push(Action::Select(Selection::Commit(id)));
Expand Down Expand Up @@ -220,10 +220,11 @@ fn paint_row(
) {
let rect = painter.clip_rect();
let (top, mid, bottom) = (rect.top(), rect.center().y, rect.bottom());
let colours = theme::colours(painter.ctx().theme());
for edge in &row.edges {
let (y0, y1, colour) = match edge.half {
Half::Top => (top, mid, theme::lane(edge.from)),
Half::Bottom => (mid, bottom, theme::lane(edge.to)),
Half::Top => (top, mid, colours.lane(edge.from)),
Half::Bottom => (mid, bottom, colours.lane(edge.to)),
};
let (a, b) = (Pos2::new(lane_x(edge.from), y0), Pos2::new(lane_x(edge.to), y1));
let stroke = Stroke::new(2.0, colour);
Expand All @@ -235,9 +236,9 @@ fn paint_row(
}
}
let node = Pos2::new(lane_x(row.lane), mid);
painter.circle_filled(node, if merge { 4.0 } else { 6.0 }, theme::lane(row.lane));
painter.circle_filled(node, if merge { 4.0 } else { 6.0 }, colours.lane(row.lane));
if head {
painter.circle_stroke(node, 9.0, Stroke::new(1.5, Color32::WHITE));
painter.circle_stroke(node, 9.0, Stroke::new(1.5, strong(painter)));
}
if wip_above {
dashed(painter, Pos2::new(node.x, top), node - Vec2::Y * 9.0);
Expand All @@ -248,22 +249,27 @@ fn paint_row(
fn paint_labels(painter: &Painter, rect: Rect, labels: &[Ref], colour: Color32, current: Option<&str>) {
let Some(first) = labels.iter().find(|l| Some(l.name.as_str()) == current).or(labels.first()) else { return };
let more = if labels.len() > 1 { format!(" +{}", labels.len() - 1) } else { String::new() };
let font = FontId::proportional(12.0);
let galley = painter.layout_no_wrap(format!("{}{more}", first.name), font, Color32::WHITE);
let (font, text) = (FontId::proportional(12.0), strong(painter));
let galley = painter.layout_no_wrap(format!("{}{more}", first.name), font, text);
let size = galley.size() + Vec2::new(14.0, 6.0);
let pill = Rect::from_min_size(Pos2::new(rect.left() + 6.0, rect.center().y - size.y / 2.0), size);
let pill = pill.intersect(rect.shrink2(Vec2::new(4.0, 0.0)));
match first.kind {
RefKind::Local => painter.rect_filled(pill, 4.0, colour.gamma_multiply(0.55)),
RefKind::Remote => painter.rect_stroke(pill, 4.0, Stroke::new(1.0, colour), egui::StrokeKind::Inside),
RefKind::Tag => painter.rect_filled(pill, 0.0, Color32::from_gray(70)),
RefKind::Tag => painter.rect_filled(pill, 0.0, theme::colours(painter.ctx().theme()).tag),
};
if Some(first.name.as_str()) == current {
painter.rect_stroke(pill, 4.0, Stroke::new(1.5, Color32::WHITE), egui::StrokeKind::Outside);
painter.rect_stroke(pill, 4.0, Stroke::new(1.5, text), egui::StrokeKind::Outside);
}
let line = Pos2::new(pill.right(), rect.center().y);
painter.line_segment([line, Pos2::new(rect.right(), line.y)], Stroke::new(1.0, colour.gamma_multiply(0.6)));
painter.with_clip_rect(pill).galley(pill.min + Vec2::new(7.0, 3.0), galley, Color32::WHITE);
painter.with_clip_rect(pill).galley(pill.min + Vec2::new(7.0, 3.0), galley, text);
}

/// The colour of what stands out most, as the commit checked out: white on dark, black on light.
fn strong(painter: &Painter) -> Color32 {
painter.ctx().global_style().visuals.strong_text_color()
}

/// The right-click menu of a commit: what can be done with each branch and tag on it, then with
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn show(ui: &mut Ui, ws: &mut Workspace, actions: &mut Vec<Action>) {
let commit = match commits.get(repo, *id) {
Ok(commit) => commit,
Err(error) => {
put(ui, column(80.0, 8.0), RichText::new(error.to_string()).color(theme::ERROR));
put(ui, column(80.0, 8.0), RichText::new(error.to_string()).color(ui.visuals().error_fg_color));
continue;
}
};
Expand Down
13 changes: 7 additions & 6 deletions crates/app/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ pub fn show(ui: &mut Ui, merge: &mut Merge, actions: &mut Vec<Action>) {
columns[1].strong(format!("Theirs: {theirs}"));
});
let to = std::mem::take(&mut merge.scroll).then_some(at);
let visuals = ui.visuals();
let (visuals, colours) = (ui.visuals(), theme::colours(ui.ctx().theme()));
let (text, current, other) = (visuals.text_color(), visuals.selection.bg_fill, visuals.extreme_bg_color);
let error = visuals.error_fg_color;
ui.spacing_mut().item_spacing.y = 0.0;
let half = (ui.available_height() - 2.0 * LINE) / 2.0;
list(ui, "sides", &rows(merge, false), half, to, |ui, rect, response, row| {
Expand All @@ -157,9 +158,9 @@ pub fn show(ui: &mut Ui, merge: &mut Merge, actions: &mut Vec<Action>) {
Row::Lines(n, lines) => {
for (side, (cell, line)) in cells.into_iter().zip(lines).enumerate() {
let background = match merge.picks[n] {
None => theme::CONFLICT,
Some(pick) if pick.sides().contains(&side) => theme::ADDED,
Some(_) => theme::REMOVED,
None => colours.conflict,
Some(pick) if pick.sides().contains(&side) => colours.added,
Some(_) => colours.removed,
};
if let Some(line) = line {
paint(ui, cell, line, text, background);
Expand All @@ -173,9 +174,9 @@ pub fn show(ui: &mut Ui, merge: &mut Merge, actions: &mut Vec<Action>) {
ui.add_space(4.0);
list(ui, "result", &rows(merge, true), f32::INFINITY, to, |ui, rect, response, row| match row {
Row::Same(line) => paint(ui, rect, line, text, Color32::TRANSPARENT),
Row::Lines(_, [line, _]) => paint(ui, rect, line.unwrap_or_default(), text, theme::ADDED),
Row::Lines(_, [line, _]) => paint(ui, rect, line.unwrap_or_default(), text, colours.added),
Row::Conflict(n) => {
paint(ui, rect, &format!("Conflict {}: pick a side", n + 1), theme::ERROR, theme::CONFLICT);
paint(ui, rect, &format!("Conflict {}: pick a side", n + 1), error, colours.conflict);
if response.clicked() {
actions.push(Action::GoTo(n));
}
Expand Down
33 changes: 23 additions & 10 deletions crates/app/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use eframe::egui::gui_zoom::{
self,
kb_shortcuts::{ZOOM_IN, ZOOM_OUT, ZOOM_RESET},
};
use eframe::egui::{self, Button, Id, KeyboardShortcut, Ui};
use eframe::egui::{self, Button, Id, KeyboardShortcut, ThemePreference, Ui};

/// A setting that is on or off.
#[derive(Debug, Clone, Copy)]
Expand All @@ -33,15 +33,9 @@ impl Switch {

/// A choice between what it does off and on.
fn choice(self, ui: &mut Ui, what: &str, [off, on]: [&str; 2]) {
ui.horizontal(|ui| {
label(ui, what);
let mut value = self.on(ui.ctx());
let changed =
ui.radio_value(&mut value, false, off).changed() | ui.radio_value(&mut value, true, on).changed();
if changed {
self.set(ui.ctx(), value);
}
});
if let Some(value) = choice(ui, what, self.on(ui.ctx()), &[(false, off), (true, on)]) {
self.set(ui.ctx(), value);
}
}
}

Expand All @@ -57,13 +51,32 @@ pub fn show(ctx: &egui::Context) -> bool {
zoom(ui, "+", "Zoom in", ZOOM_IN, gui_zoom::zoom_in);
zoom(ui, "Reset", "Reset the zoom", ZOOM_RESET, |ctx| ctx.set_zoom_factor(1.0));
});
let themes =
[(ThemePreference::Dark, "Dark"), (ThemePreference::Light, "Light"), (ThemePreference::System, "System")];
if let Some(theme) = choice(ui, "Theme", ctx.options(|o| o.theme_preference), &themes) {
ctx.set_theme(theme);
}
FULL_DATES.choice(ui, "Dates", ["How long ago", "Date and time"]);
REBASE.choice(ui, "Pull", ["Merge", "Rebase"]);
close = ui.button("Close").clicked();
});
!(close || response.should_close())
}

/// A row to pick one of `picks` for what it is about, with `value` picked; the new pick, once the
/// user makes one.
fn choice<T: PartialEq + Copy>(ui: &mut Ui, what: &str, mut value: T, picks: &[(T, &str)]) -> Option<T> {
ui.horizontal(|ui| {
label(ui, what);
let mut changed = false;
for &(pick, name) in picks {
changed |= ui.radio_value(&mut value, pick, name).changed();
}
changed.then_some(value)
})
.inner
}

/// What a row of the settings is about, in a column of its own.
fn label(ui: &mut Ui, text: &str) {
let width = ui.label(text).rect.width();
Expand Down
5 changes: 2 additions & 3 deletions crates/app/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use eframe::egui::{self, Button, Key, ProgressBar, RichText, TextEdit, Ui};
use gitcraft_core::git::{self, Git};

use crate::app::Action;
use crate::theme;
use crate::ui::pick_folder;

/// The width of the dialog's fields.
Expand Down Expand Up @@ -67,7 +66,7 @@ impl Start {
}
}
if let Some(error) = &self.error {
ui.colored_label(theme::ERROR, error);
ui.colored_label(ui.visuals().error_fg_color, error);
}
if !recent.is_empty() {
ui.add_space(24.0);
Expand Down Expand Up @@ -210,7 +209,7 @@ impl Dialog {
(None, None) => {}
}
if let Some(error) = &self.error {
ui.colored_label(theme::ERROR, error);
ui.colored_label(ui.visuals().error_fg_color, error);
}
let idle = !self.busy();
let enter = ui.input(|i| i.key_pressed(Key::Enter));
Expand Down
Loading
Loading