Fix 2265: close tui on success, custom tui subscriber (#2734)

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-07-31 10:49:51 -07:00
1 parent 189772a17b
commit 63e7aab4e8
10 files changed
+226 -54

No files matched your search

+3 -1
View File
@@ -14,7 +14,9 @@ mod fullstack;
mod prepare_html;
mod progress;
mod web;
pub use progress::{BuildMessage, MessageType, Stage, UpdateBuildProgress, UpdateStage};
pub use progress::{
BuildMessage, MessageSource, MessageType, Stage, UpdateBuildProgress, UpdateStage,
};
/// A request for a project to be built
pub struct BuildRequest {
+2 -1
View File
@@ -1,6 +1,7 @@
//! Build the HTML file to load a web application. The index.html file may be created from scratch or modified from the `index.html` file in the crate root.
use super::{BuildRequest, UpdateBuildProgress};
use crate::builder::progress::MessageSource;
use crate::builder::Stage;
use crate::Result;
use futures_channel::mpsc::UnboundedSender;
@@ -191,7 +192,7 @@ impl BuildRequest {
update: super::UpdateStage::AddMessage(super::BuildMessage {
level: Level::WARN,
message: super::MessageType::Text(message),
source: None,
source: MessageSource::Build,
}),
});
}
+32 -3
View File
@@ -3,6 +3,7 @@ use anyhow::Context;
use cargo_metadata::{diagnostic::Diagnostic, Message};
use futures_channel::mpsc::UnboundedSender;
use serde::Deserialize;
use std::fmt::Display;
use std::ops::Deref;
use std::path::PathBuf;
use std::process::Stdio;
@@ -83,7 +84,7 @@ pub enum UpdateStage {
pub struct BuildMessage {
pub level: Level,
pub message: MessageType,
pub source: Option<String>,
pub source: MessageSource,
}
#[derive(Debug, Clone, PartialEq)]
@@ -92,6 +93,34 @@ pub enum MessageType {
Text(String),
}
/// Represents the source of where a message came from.
///
/// The CLI will render a prefix according to the message type
/// but this prefix, [`MessageSource::to_string()`] shouldn't be used if a strict message source is required.
#[derive(Debug, Clone, PartialEq)]
pub enum MessageSource {
/// Represents any message from the running application. Renders `[app]`
App,
/// Represents any generic message from the CLI. Renders `[dev]`
///
/// Usage of Tracing inside of the CLI will be routed to this type.
Dev,
/// Represents a message from the build process. Renders `[bld]`
///
/// This is anything emitted from a build process such as cargo and optimizations.
Build,
}
impl Display for MessageSource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::App => write!(f, "app"),
Self::Dev => write!(f, "dev"),
Self::Build => write!(f, "bld"),
}
}
}
impl From<Diagnostic> for BuildMessage {
fn from(message: Diagnostic) -> Self {
Self {
@@ -104,7 +133,7 @@ impl From<Diagnostic> for BuildMessage {
cargo_metadata::diagnostic::DiagnosticLevel::Help => Level::DEBUG,
_ => Level::DEBUG,
},
source: Some("cargo".to_string()),
source: MessageSource::Build,
message: MessageType::Cargo(message),
}
}
@@ -206,7 +235,7 @@ pub(crate) async fn build_cargo(
update: UpdateStage::AddMessage(BuildMessage {
level: Level::DEBUG,
message: MessageType::Text(line),
source: None,
source: MessageSource::Build,
}),
});
}