From 117416a4293f94a9b263cc445ace793c2566fceb Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Tue, 1 Aug 2023 20:13:45 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20IImprove=20the=20printing=20of?= =?UTF-8?q?=20banner=20on=20app=20startup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/config/settings.predefined.toml | 2 +- pagetop/src/app.rs | 29 ++++++++++++++----------- pagetop/src/config.rs | 4 ++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pagetop/config/settings.predefined.toml b/pagetop/config/settings.predefined.toml index cfdbfd75..ca1c39f9 100644 --- a/pagetop/config/settings.predefined.toml +++ b/pagetop/config/settings.predefined.toml @@ -1,6 +1,6 @@ [app] name = "PageTop Application" -description = "Developed with the amazing PageTop framework." +description = "Developed with the awesome PageTop framework." # Tema predeterminado. theme = "Default" # Idioma (localización) predeterminado. diff --git a/pagetop/src/app.rs b/pagetop/src/app.rs index ae1d3b42..762b5ae7 100644 --- a/pagetop/src/app.rs +++ b/pagetop/src/app.rs @@ -6,7 +6,7 @@ use crate::core::{module, module::ModuleRef}; use crate::html::Markup; use crate::response::fatal_error::FatalError; use crate::response::page::ResultPage; -use crate::{config, locale, service, trace, LazyStatic}; +use crate::{concat_string, config, locale, service, trace, LazyStatic}; #[cfg(feature = "database")] use crate::db; @@ -94,26 +94,29 @@ impl Application { fn print_on_startup() { if config::SETTINGS.app.startup_banner.to_lowercase() != "off" { + // Application name. + let mut app_name = config::SETTINGS.app.name.to_string(); if let Some((term_width, _)) = term_size::dimensions() { if term_width >= 80 { let maxlen = (term_width / 10) - 2; - let mut app = config::SETTINGS.app.name.substring(0, maxlen).to_owned(); - if config::SETTINGS.app.name.len() > maxlen { + let mut app = app_name.substring(0, maxlen).to_owned(); + if app_name.len() > maxlen { app = format!("{}...", app); } - println!( - "\n{} {}\n\n Powered by PageTop {}\n", - figfont::FIGFONT.convert(&app).unwrap(), - &config::SETTINGS.app.description, - env!("CARGO_PKG_VERSION") - ); - return; + app_name = figfont::FIGFONT.convert(&app).unwrap().to_string(); } } + // Application description. + let app_description = if !config::SETTINGS.app.description.is_empty() { + concat_string!("\n", config::SETTINGS.app.description) + } else { + "".to_string() + }; + // Print banner. println!( - "\n{}\n{}\n\nPowered by PageTop {}\n", - &config::SETTINGS.app.name, - &config::SETTINGS.app.description, + "\n{}{}\n\nPowered by PageTop {}\n", + app_name, + app_description, env!("CARGO_PKG_VERSION") ); } diff --git a/pagetop/src/config.rs b/pagetop/src/config.rs index 53533905..376dcd06 100644 --- a/pagetop/src/config.rs +++ b/pagetop/src/config.rs @@ -179,7 +179,7 @@ pub struct App { /// Por defecto: *"PageTop App"*. pub name: String, /// Una descripción breve de la aplicación. - /// Por defecto: *"Modular web solutions made simple with PageTop."*. + /// Por defecto: *"Developed with the awesome PageTop framework."*. pub description: String, /// Tema predeterminado. /// Por defecto: *"Default"*. @@ -283,7 +283,7 @@ pub struct Server { default_settings!( // [app] "app.name" => "PageTop App", - "app.description" => "Modular web solutions made simple with PageTop.", + "app.description" => "Developed with the awesome PageTop framework.", "app.theme" => "Default", "app.language" => "en-US", "app.direction" => "ltr",