Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
banner.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
16
18#include "shambase/string.hpp"
19#include "sham/term/tty.hpp"
20#include "shamcomm/logs.hpp"
22#include "shamrock/version.hpp"
23#include <cstdlib>
24#include <filesystem>
25#include <random>
26#include <sstream>
27#include <string>
28
29// start allow utf-8
30inline std::string shamrock_title_bar_big = "\n\
31 █████████ █████ █████ █████████ ██████ ██████ ███████████ ███████ █████████ █████ ████\n\
32 ███░░░░░███░░███ ░░███ ███░░░░░███ ░░██████ ██████ ░░███░░░░░███ ███░░░░░███ ███░░░░░███░░███ ███░ \n\
33░███ ░░░ ░███ ░███ ░███ ░███ ░███░█████░███ ░███ ░███ ███ ░░███ ███ ░░░ ░███ ███ \n\
34░░█████████ ░███████████ ░███████████ ░███░░███ ░███ ░██████████ ░███ ░███░███ ░███████ \n\
35 ░░░░░░░░███ ░███░░░░░███ ░███░░░░░███ ░███ ░░░ ░███ ░███░░░░░███ ░███ ░███░███ ░███░░███ \n\
36 ███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░███ ░░███ ███ ░░███ ███ ░███ ░░███ \n\
37░░█████████ █████ █████ █████ █████ █████ █████ █████ █████ ░░░███████░ ░░█████████ █████ ░░████\n\
38 ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░ ░░░░░░░░░ ░░░░░ ░░░░ \n\
39";
40// end allow utf-8
41
42// start allow utf-8
43inline std::string very_rare_title_bar = "\n\
44█▀▀▀▀▀█ ▀▄▄███▄▀ █▄ ▀ █▀▀▀▀▀█\n\
45█ ███ █ ▄▄▀▄█ ▀▀██▀▀ █▄▀ █ ███ █\n\
46█ ▀▀▀ █ ██▄ ▄ ▄▀█ ▀▄██▄▄ █ ▀▀▀ █\n\
47▀▀▀▀▀▀▀ █ ▀▄▀ █ ▀▄█▄█▄▀ █ ▀▀▀▀▀▀▀\n\
48▀▄ ▀▄▀█▀ █▄▀ █▄█▄ ▀███ █▀▀▀█▄ █\n\
49▀ █ █▀▀█▀ ▄ ▄█▀▀▄ ▀▄▄ ▄▀▄█▄ ▀ ▀ \n\
50█ ██▄▄▀▄▀ █▄▀▀▄ ▀▄▄▄▄ ▀▀█▄▀█ ▀▄ ▀\n\
51▄▄█▄█▀▀▄ ██▀▄██▄██ ▀█ █▀██▄▀ ▀ \n\
52██ ▀██▀▄██▄ ▀ ▄▄▀█▀█▀█▄█ ▀ ▀█▄█ \n\
53▀▄█▀█ ▀█ █ ██ █▀█▄ ██▀▀██▄█ ▀ █ \n\
54█ ▀▄ █▀▀ ▀ ▀▄▀▀ ▄▄▀█▀ ▄ █▀▀█▄▄ \n\
55 ▄██▀█▄ ▄▀▀▄▀ ▀▄██▄█▄▀▀█▄ ▄▄▀█▄\n\
56▀▀▀ ▀ ▀▀▄ ██ █████ ▀██▄█▀▀▀█▀▄▀ \n\
57█▀▀▀▀▀█ ▀▀▀▄ ██▄ ▀▄ ▄ █ ▀ █▀ ▄\n\
58█ ███ █ ▀▄▄▀██▀ ▀ ▄█▄ ▀▄▀▀████▄▄▀\n\
59█ ▀▀▀ █ ▀ ▄█▄▀█▄▄█ ▀█ ▄▄▀█▀▀▀ \n\
60▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀ ▀ ▀\n\
61";
62// end allow utf-8
63
64namespace {
65
66 std::optional<std::string> get_banner_pic_path() {
67 constexpr const char *kitty_banner_path
68 = "../doc/mkdocs/docs/assets/no_background_nocolor.png";
69 if (std::filesystem::exists(kitty_banner_path)) {
70 return kitty_banner_path;
71 }
72 return std::nullopt;
73 }
74
75 bool try_print_picture() {
76 if (!sham::term::is_a_tty()) {
77 return false;
78 }
79
80 const char *term = std::getenv("TERM");
81 if (term == nullptr || std::string(term) != "xterm-kitty") {
82 return false;
83 }
84
85 if (std::optional<std::string> banner_path = get_banner_pic_path()) {
86 std::system(("kitten icat " + *banner_path).c_str());
87 return true;
88 }
89
90 return false;
91 }
92
93 void print_standard_title_bar() {
94 // if (!try_print_picture()) { // need more testing on the kitty banner picture
95 logger::raw_ln(shamrock_title_bar_big);
96 // }
97 }
98
99} // namespace
100
101namespace shamrock {
102
103 std::string get_date_hour_string() {
104 auto now = std::chrono::system_clock::now();
105 auto in_time_t = std::chrono::system_clock::to_time_t(now);
106 std::stringstream ss;
107 ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %H:%M:%S");
108 return ss.str();
109 }
110
111 u64 pure_random_number() { return std::random_device{}(); }
112
113 void print_title_bar() {
114 if (pure_random_number() % 100 == 0) {
115 logger::raw_ln(very_rare_title_bar);
116 } else {
117 print_standard_title_bar();
118 }
119
120 logger::raw_ln(
121 shambase::term_colors::col8b_cyan()
122 + "Copyright (c) 2021-2026 Timothée David--Cléris (tim.shamrock@proton.me)"
123 + shambase::term_colors::reset());
124 logger::raw_ln(
125 shambase::term_colors::col8b_cyan() + "SPDX-License-Identifier"
126 + shambase::term_colors::reset() + " : CeCILL Free Software License Agreement v2.1");
127 logger::raw_ln(
128 shambase::term_colors::col8b_cyan() + "Start time" + shambase::term_colors::reset()
129 + " : " + get_date_hour_string());
130
131 logger::print_faint_row();
132
133 logger::raw_ln(
134 "\n" + shambase::term_colors::col8b_cyan() + "Shamrock version "
135 + shambase::term_colors::reset() + ": " + version_string + "\n");
136
137 if (is_git) {
138 logger::raw_ln(
139 shambase::term_colors::col8b_cyan() + "Git infos " + shambase::term_colors::reset()
140 + ":\n" + shambase::trunc_str(git_info_str, 512));
141 }
142 }
143
144 void code_init_done_log() {
145
146 // start allow utf-8
147 auto lines = std::vector<std::string>{
148 // Someone that coded too much here
149 "Now it's time to " + shambase::term_colors::col8b_cyan()
151 "Shamrock rolls - no time for moss.", // Rolling stone gathers no moss.
152 "Shamrock's live - go with the flow.",
153 "Shamrock - as solid as a rock.",
154 "Shamrock's stable and steady as a rock.",
155 "Shamrock initialized - no cracks in this rock.",
156 "Shamrock is ready to eat cheese (melted) and bread.",
157 "Are you sure you want to work today?",
158 "No holidays for the Shamrock ... (yeah, this was a PhD at some point)",
159 "-[--->+<]>--.>+[----->+++<]>+.-------.++++++++++++.+++++.---.------------.++++++++.",
160 "CPU hours to burn? We don't do such thing here.",
161 "Are you burning GPUs or CPUs today?",
162 R"=(
163While you wait for this simulation to run, give that cat a hug!
164
165 |\__/,| (`\
166_.|o o |_ ) )
167-(((---(((--------
168 )=",
169
170 // Someone that started on oumuamua
171 "Shamrock your way to a brighter day!",
172 "Node hours to burn? Leaf it to me.",
173 "Ready for some shamazing simulations?",
174 "SHAMROCKがきれいですね ~",
175 "シャムロック",
176
177 // by the coagulator
178 "We're not here to make seagulls laugh",
179
180 // in places
181 "日本でも使ている", // used in japan
182 "Pretty sure Aussies use that too, mate."};
183 // end allow utf-8
184
185 auto get_sentence = [&]() {
187 u64 idx = static_cast<u64>(std::floor(
188 t * 2503'09713 // you wont guess what this stands for
189 ))
190 % lines.size();
191 return lines[idx];
192 };
193
194 if (shamcomm::world_rank() == 0) {
195 logger::print_faint_row();
196 logger::raw_ln(
197 " - Code init:",
198 shambase::term_colors::col8b_green() + "DONE" + shambase::term_colors::reset()
199 + ".",
200 get_sentence());
201 logger::print_faint_row();
202 }
203 }
204
205} // namespace shamrock
double f64
Alias for double.
std::uint64_t u64
64 bit unsigned integer
std::string trunc_str(std::string s, u32 max_len)
Truncate a string to a specified length, adding an ellipsis if necessary.
Definition string.hpp:138
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:41
namespace for the main framework
Definition __init__.py:1
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:89
This file contains the definition for the stacktrace related functionality.
f64 get_wtime()
Returns the current wall clock time in seconds.
const std::string reset()
Get the reset terminal escape char.
const std::string blink()
Get the blink terminal escape char.
const std::string col8b_cyan()
Get the cyan terminal escape char.
This file contains tty info getters.
bool is_a_tty()
Test if current terminal is a tty.
Definition tty.cpp:45
typedefs and macros
Functions related to the MPI communicator.