🎨 IImprove the printing of banner on app startup

This commit is contained in:
Manuel Cillero 2023-08-01 20:13:45 +02:00
parent dd93cfb9c8
commit 117416a429
3 changed files with 19 additions and 16 deletions

View file

@ -1,6 +1,6 @@
[app] [app]
name = "PageTop Application" name = "PageTop Application"
description = "Developed with the amazing PageTop framework." description = "Developed with the awesome PageTop framework."
# Tema predeterminado. # Tema predeterminado.
theme = "Default" theme = "Default"
# Idioma (localización) predeterminado. # Idioma (localización) predeterminado.

View file

@ -6,7 +6,7 @@ use crate::core::{module, module::ModuleRef};
use crate::html::Markup; use crate::html::Markup;
use crate::response::fatal_error::FatalError; use crate::response::fatal_error::FatalError;
use crate::response::page::ResultPage; use crate::response::page::ResultPage;
use crate::{config, locale, service, trace, LazyStatic}; use crate::{concat_string, config, locale, service, trace, LazyStatic};
#[cfg(feature = "database")] #[cfg(feature = "database")]
use crate::db; use crate::db;
@ -94,26 +94,29 @@ impl Application {
fn print_on_startup() { fn print_on_startup() {
if config::SETTINGS.app.startup_banner.to_lowercase() != "off" { 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 let Some((term_width, _)) = term_size::dimensions() {
if term_width >= 80 { if term_width >= 80 {
let maxlen = (term_width / 10) - 2; let maxlen = (term_width / 10) - 2;
let mut app = config::SETTINGS.app.name.substring(0, maxlen).to_owned(); let mut app = app_name.substring(0, maxlen).to_owned();
if config::SETTINGS.app.name.len() > maxlen { if app_name.len() > maxlen {
app = format!("{}...", app); app = format!("{}...", app);
} }
println!( app_name = figfont::FIGFONT.convert(&app).unwrap().to_string();
"\n{} {}\n\n Powered by PageTop {}\n",
figfont::FIGFONT.convert(&app).unwrap(),
&config::SETTINGS.app.description,
env!("CARGO_PKG_VERSION")
);
return;
} }
} }
// 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!( println!(
"\n{}\n{}\n\nPowered by PageTop {}\n", "\n{}{}\n\nPowered by PageTop {}\n",
&config::SETTINGS.app.name, app_name,
&config::SETTINGS.app.description, app_description,
env!("CARGO_PKG_VERSION") env!("CARGO_PKG_VERSION")
); );
} }

View file

@ -179,7 +179,7 @@ pub struct App {
/// Por defecto: *"PageTop App"*. /// Por defecto: *"PageTop App"*.
pub name: String, pub name: String,
/// Una descripción breve de la aplicación. /// 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, pub description: String,
/// Tema predeterminado. /// Tema predeterminado.
/// Por defecto: *"Default"*. /// Por defecto: *"Default"*.
@ -283,7 +283,7 @@ pub struct Server {
default_settings!( default_settings!(
// [app] // [app]
"app.name" => "PageTop 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.theme" => "Default",
"app.language" => "en-US", "app.language" => "en-US",
"app.direction" => "ltr", "app.direction" => "ltr",