use crate::ui::{Model, theme};
pub const NO_RUN: &str = "nobody has signed in to this row here";
pub const OPEN: &str = "open the sign-in page";
pub const OPEN_HELP: &str = "opens this sign-in's page in this desktop's browser";
pub const COPY: &str = "copy its address";
pub const COPY_HELP: &str = "copies the sign-in page's address, for a browser somewhere else";
pub const PASTE_HINT: &str = "paste what the sign-in page gave you";
pub const FINISH: &str = "finish the sign-in";
pub const FINISH_HELP: &str =
"sends what you pasted to the box that holds this provider, which checks it there";
pub const BY_HAND: &str = "run it by hand, on the box this workspace lives on:";
pub fn render(ui: &mut egui::Ui, model: &mut Model, name: &str) {
if model.following().as_deref() != Some(name) {
return;
}
let Some(run) = model.signin.clone() else {
return;
};
if run.lines.is_empty() && !run.settled() {
ui.label(NO_RUN);
return;
}
for line in &run.lines {
let ink = if line.err {
theme::NOTICE
} else {
theme::tone_ink(&crate::reply::convs::Tone::Plain)
};
ui.colored_label(ink, line.text.clone());
}
if let Some(url) = run.awaited() {
finish(ui, model, name, url);
}
if let Some(exit) = run.outcome {
ui.label(settled(exit));
}
if let Some(command) = &run.fallback {
ui.label(BY_HAND);
ui.colored_label(theme::tone_ink(&crate::reply::convs::Tone::Weak), command);
}
}
fn finish(ui: &mut egui::Ui, model: &mut Model, name: &str, url: &str) {
ui.horizontal_wrapped(|ui| {
if theme::paint::button(ui, OPEN, true, OPEN_HELP).clicked() {
ui.ctx().open_url(egui::OpenUrl::new_tab(url));
}
if theme::paint::button(ui, COPY, true, COPY_HELP).clicked() {
ui.ctx().copy_text(url.to_owned());
}
});
let sent = model.code_draft().is_some_and(|draft| {
ui.add(
egui::TextEdit::singleline(draft)
.desired_width(ui.available_width())
.hint_text(PASTE_HINT),
);
let send = theme::paint::button(ui, FINISH, !draft.trim().is_empty(), FINISH_HELP);
crate::ui::act::tag(&send, &[crate::verbs::LOGIN.word]);
send.clicked()
});
if sent {
model.post_code(name);
}
}
pub fn settled(exit: i32) -> String {
if exit == 0 {
"signed in".to_owned()
} else {
format!("the sign-in ended with status {exit}")
}
}
#[cfg(test)]
mod tests;