From ce121cbf232ee2f166c41be491a501d8bb99ae04 Mon Sep 17 00:00:00 2001 From: Luke Harding Date: Thu, 2 May 2024 19:33:47 -0400 Subject: [PATCH] Print copyright and server message on startup --- server/Cargo.lock | 17 +++++++++++++++++ server/Cargo.toml | 1 + server/src/main.rs | 11 ++++++++++- server/src/util.rs | 9 +++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 server/src/util.rs diff --git a/server/Cargo.lock b/server/Cargo.lock index eccf688..4c4d4be 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -328,6 +328,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -591,6 +601,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.154" @@ -724,6 +740,7 @@ name = "personal-tracker-server" version = "0.1.0" dependencies = [ "actix-web", + "colored", ] [[package]] diff --git a/server/Cargo.toml b/server/Cargo.toml index a9c41c4..48ac010 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -6,3 +6,4 @@ license = "GPL-3.0-only" [dependencies] actix-web = "4.5.1" +colored = "2.1.0" diff --git a/server/src/main.rs b/server/src/main.rs index e8a9cdc..781782f 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,9 +1,18 @@ use actix_web::{App, get, HttpResponse, HttpServer, Responder}; +mod util; + #[actix_web::main] async fn main() -> std::io::Result<()> { + util::print_copyright_notice(); + + let port = 8000; + let bind_addr = "127.0.0.1"; + + util::notice_println(format!("Starting server on {}:{}", bind_addr, port)); + HttpServer::new(|| App::new().service(hello)) - .bind(("127.0.0.1", 8000))? + .bind((bind_addr, port))? .run() .await } diff --git a/server/src/util.rs b/server/src/util.rs new file mode 100644 index 0000000..df4747b --- /dev/null +++ b/server/src/util.rs @@ -0,0 +1,9 @@ +use colored::Colorize; + +pub fn print_copyright_notice() { + println!("{}", "Personal Tracker Server Copyright (C) 2024 Luke Harding \nThis program comes with ABSOLUTELY NO WARRANTY\nThis is free software, and you are welcome to redistribute it under certain conditions\n".italic()); +} + +pub fn notice_println(msg: impl Into) { + println!("{}", msg.into().green().bold()); +}