1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! Internal macros shared across all GUI feature modules.
/// Build an `iced::Task<Message>` that runs blocking git work on a background
/// thread via a `futures` oneshot channel.
///
/// # Arguments
///
/// * `$msg` – the `Message` constructor passed to `Task::perform` as the
/// mapping function (e.g. `Message::BranchCheckedOut`).
/// * `$body` – an expression evaluated inside the spawned thread that must
/// return `Result<T, String>`. Use an IIFE `(|| { … })()` when the
/// `?`-operator is needed, or a plain function call when a single fallible
/// call suffices.
///
/// # Example
///
/// ```ignore
/// git_task!(Message::BranchCheckedOut, (|| {
/// let repo = open_repo(&path)?;
/// checkout_branch(&repo, &name).map_err(|e| e.to_string())
/// })())
/// ```
/// Guard an update-handler arm behind the active tab's `repo_path`.
///
/// Reads `$state.active_tab().repo_path`, returns `Task::none()` when it is
/// `None`, and evaluates `$cmd` with `repo_path: PathBuf` in scope when it is
/// `Some`.
///
/// Two forms:
///
/// * **Plain** – sets only `status_message`, then evaluates `$cmd`:
/// ```ignore
/// with_repo!(state, "Staging…".into(), |repo_path|
/// commands::stage_file(repo_path, f))
/// ```
///
/// * **Loading** – additionally sets `is_loading = true` before `$cmd`:
/// ```ignore
/// with_repo!(state, loading, "Checking out…".into(), |repo_path|
/// commands::checkout_branch(repo_path, name))
/// ```
///
/// The `|$ident|` token before `$cmd` names the `PathBuf` variable that is
/// bound from `repo_path` and made available inside `$cmd`. Passing the name
/// as a macro parameter avoids Rust's `macro_rules!` hygiene restriction that
/// would otherwise hide a macro-internal binding from call-site expressions.
///
/// Extra tab mutations can be performed inside a block `$cmd`; the
/// `is_loading` / `status_message` mutable borrow has already been dropped.
/// Create a Bootstrap icon text widget.
///
/// Two forms: 3-arg `icon!(CHAR, SIZE, COLOR)` or 2-arg `icon!(CHAR, SIZE)`.
/// Open a git repository at the given path, mapping the error to `String`.
///
/// Shorthand for `gitkraft_core::features::repo::open_repo($path).map_err(|e| e.to_string())?`.
/// Used inside `git_task!` closures where the `?` operator is available.