Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Show a named Pause button, and say Pausing… once it is pressed (#555)

Fábio Soaresb002c5417f11
diff --git a/crates/ui-egui/src/chat.rs b/crates/ui-egui/src/chat.rs
index 72e1e4a2..367f853e 100644
--- a/crates/ui-egui/src/chat.rs
+++ b/crates/ui-egui/src/chat.rs
@@ -331,6 +331,7 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, dense: bool) {
rows: (1, if dense { 4 } else { 8 }),
attach: None,
stop_button: answering.then_some("Stop"),
+ stopping: false,
send: !answering,
recall: false,
history: Some(&history),
diff --git a/crates/ui-egui/src/fr.tsv b/crates/ui-egui/src/fr.tsv
index 9cf9419e..07ae79ab 100644
--- a/crates/ui-egui/src/fr.tsv
+++ b/crates/ui-egui/src/fr.tsv
@@ -591,6 +591,7 @@ Ask for a change, e.g. "make the header blue" or "add a contact form" Demandez u
Ask for a change Demander une modification
Attach pictures (or drop them here) Joindre des images (ou les déposer ici)
Pause Pause
+Pausing… Mise en pause…
Change it Modifier
Just ask Juste demander
or start with /btw to just ask ou commencez par /btw pour juste demander
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 92046294..fa4e8099 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -791,6 +791,7 @@ Paste your API key (kept in your system keychain) 粘贴 API 密钥 (保存在
Paste your {name} key 粘贴你的 {name} 密钥
Path 路径
Pause 暂停
+Pausing… 正在暂停…
Pause the build first, then delete the project. 请先暂停构建,再删除项目。
Pause the build first. 请先暂停构建。
Paused 已暂停
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 77ca43a2..cbdd2a5c 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -791,6 +791,7 @@ Paste your API key (kept in your system keychain) 貼上 API 金鑰 (儲存在
Paste your {name} key 貼上你的 {name} 金鑰
Path 路徑
Pause 暫停
+Pausing… 正在暫停…
Pause the build first, then delete the project. 請先暫停建置,再刪除專案。
Pause the build first. 請先暫停建置。
Paused 已暫停
diff --git a/crates/ui-egui/src/ja.tsv b/crates/ui-egui/src/ja.tsv
index 4da26e03..09bdb0a2 100644
--- a/crates/ui-egui/src/ja.tsv
+++ b/crates/ui-egui/src/ja.tsv
@@ -479,6 +479,7 @@ Paste your API key (kept in your system keychain) API キーを貼り付け(シ
Paste your {name} key {name} のキーを貼り付け
Path パス
Pause 一時停止
+Pausing… 一時停止しています…
Pause the build first, then delete the project. 先にビルドを一時停止してから、プロジェクトを削除してください。
Pause the build first. 先にビルドを一時停止してください。
Paused 一時停止
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 56b9fc2a..45fb954b 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -417,6 +417,8 @@ pub struct CraftApp {
next_consent: u64,
/// Projects whose build is waiting for the person's answer (a question or approval).
pub asking: std::collections::HashSet<PathBuf>,
+ /// Projects whose Pause was pressed and whose build hasn't stopped yet (#551).
+ pub pausing: std::collections::HashSet<PathBuf>,
/// A build asked something since the last frame: the taskbar flashes if the window is behind.
attention: bool,
/// Jobs whose result goes into the conversation (a first look, an answer without an AI):
@@ -481,6 +483,7 @@ impl CraftApp {
creating: None,
chat_jobs: Vec::new(),
asking: Default::default(),
+ pausing: Default::default(),
pending_consent: Default::default(),
next_consent: 1,
attention: false,
diff --git a/crates/ui-egui/src/make.rs b/crates/ui-egui/src/make.rs
index 061d1357..eae5576e 100644
--- a/crates/ui-egui/src/make.rs
+++ b/crates/ui-egui/src/make.rs
@@ -113,6 +113,7 @@ pub fn hero(app: &mut CraftApp, ui: &mut Ui, w: f32) {
rows: (3, 10),
attach: (!website).then_some("Add pictures of the original (optional: screenshots help it look right)"),
stop_button: None,
+ stopping: false,
send: false,
recall: false,
history: None,
diff --git a/crates/ui-egui/src/project.rs b/crates/ui-egui/src/project.rs
index 9fcf8343..248e988c 100644
--- a/crates/ui-egui/src/project.rs
+++ b/crates/ui-egui/src/project.rs
@@ -211,8 +211,12 @@ impl CraftApp {
pub fn pause(&mut self) {
let Some(root) = self.workspace.as_ref().map(|w| w.root.clone()) else { return };
- if self.runs.stop(&root) == Stopped::Unqueued {
- apply(&mut self.state.feed, &RunEvent::Finished { ok: false, message: "Paused.".into(), paused: true });
+ match self.runs.stop(&root) {
+ Stopped::Unqueued => apply(&mut self.state.feed, &RunEvent::Finished { ok: false, message: "Paused.".into(), paused: true }),
+ Stopped::Stopping => {
+ self.pausing.insert(root);
+ }
+ Stopped::Nothing => {}
}
}
@@ -1505,6 +1509,12 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, t: &Tokens) {
if let Some(id) = take_back {
app.unsend(id);
}
+ // Pause was pressed and the build hasn't stopped yet: the button says so until it does.
+ let open_root = app.workspace.as_ref().map(|w| w.root.clone());
+ if !running && let Some(root) = &open_root {
+ app.pausing.remove(root);
+ }
+ let pausing = running && open_root.is_some_and(|r| app.pausing.contains(&r));
let hint = if app.state.just_ask {
tr("Ask about the build, e.g. \"where are the latest files?\" Nothing changes and no build starts.")
} else if running {
@@ -1532,6 +1542,7 @@ fn composer(app: &mut CraftApp, ui: &mut Ui, width: f32, t: &Tokens) {
attach: Some("Attach pictures (or drop them here)"),
// The one way to pause (Continue picks up where it stopped).
stop_button: running.then_some("Pause"),
+ stopping: pausing,
send: true,
recall: !waiting.is_empty(),
history: Some(&history),
diff --git a/crates/ui-egui/src/prompt_box.rs b/crates/ui-egui/src/prompt_box.rs
index c4a6653c..2c3065be 100644
--- a/crates/ui-egui/src/prompt_box.rs
+++ b/crates/ui-egui/src/prompt_box.rs
@@ -22,6 +22,8 @@ pub struct PromptBox<'a> {
pub attach: Option<&'a str>,
/// A run or answer is in progress: a stop button beside Send, named this ("Stop", "Pause").
pub stop_button: Option<&'a str>,
+ /// The stop was asked for and hasn't finished: the button says so and ignores clicks (#551).
+ pub stopping: bool,
/// Show the send button (the Make screen has its own big Start button).
pub send: bool,
/// A sent message is still waiting and can be taken back: Up at the start of the box asks for it.
@@ -213,10 +215,12 @@ pub fn show(ui: &mut Ui, text: &mut String, attachments: &[PathBuf], b: PromptBo
out.send = true;
}
}
- if let Some(name) = b.stop_button
- && icons::button(ui, "circle-stop", 30.0, false, name).clicked()
- {
- out.stop = true;
+ // Named, not a bare icon: the hint says "press Pause", so the button says Pause.
+ if let Some(name) = b.stop_button {
+ let label = if b.stopping { "Pausing…" } else { name };
+ if widgets::secondary(ui, Some("circle-stop"), label).clicked() && !b.stopping {
+ out.stop = true;
+ }
}
});
});
@@ -328,4 +332,52 @@ mod tests {
assert_eq!(as_typed("First\nsecond line"), "First\nsecond line");
assert_eq!(as_typed("Use 3\ncolours"), "Use 3\ncolours");
}
+
+ /// #551: the hint says "press Pause", so a labelled Pause button is there; after it's pressed
+ /// the button says Pausing… and a second click does nothing.
+ #[test]
+ fn the_pause_button_is_named_and_says_when_it_was_pressed() {
+ use egui_kittest::Harness;
+ use egui_kittest::kittest::Queryable as _;
+ #[derive(Default)]
+ struct Screen {
+ stops: u32,
+ stopping: bool,
+ }
+ impl eframe::App for Screen {
+ fn ui(&mut self, ui: &mut egui::Ui, _: &mut eframe::Frame) {
+ egui::CentralPanel::default().show(ui, |ui| {
+ let b = PromptBox {
+ name: "Ask for a change",
+ hint: String::new(),
+ rows: (1, 8),
+ attach: None,
+ stop_button: Some("Pause"),
+ stopping: self.stopping,
+ send: true,
+ recall: false,
+ history: None,
+ font_size: 14.0,
+ };
+ if show(ui, &mut String::new(), &[], b).stop {
+ self.stops += 1;
+ }
+ });
+ }
+ }
+ let mut h = Harness::builder().with_size(egui::vec2(800.0, 400.0)).build_eframe(|cc| {
+ crate::CraftApp::setup_context(&cc.egui_ctx);
+ Screen::default()
+ });
+ h.run();
+ h.get_by_label("Pause").click();
+ h.run();
+ assert_eq!(h.state().stops, 1);
+ h.state_mut().stopping = true;
+ h.run();
+ assert!(h.query_by_label("Pause").is_none());
+ h.get_by_label("Pausing…").click();
+ h.run();
+ assert_eq!(h.state().stops, 1, "pressing it again changes nothing");
+ }
}