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