Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly skip printing version header with --no-header #89679

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

enetheru
Copy link
Contributor

Check engine::_print_header before actually printing header info to the console.

@enetheru enetheru requested a review from a team as a code owner March 19, 2024 13:41
@AThousandShips
Copy link
Member

AThousandShips commented Mar 19, 2024

As I suggested on the other PR I think this should be handled in Engine not here, so like:

diff --git a/core/config/engine.cpp b/core/config/engine.cpp
index d714ec42c2..9f4bff3779 100644
--- a/core/config/engine.cpp
+++ b/core/config/engine.cpp
@@ -266,6 +266,12 @@ void Engine::print_header(const String &p_string) const {
        }
 }

+void Engine::print_header_rich(const String &p_string) const {
+       if (_print_header) {
+               print_line_rich(p_string);
+       }
+}
+
 void Engine::add_singleton(const Singleton &p_singleton) {
        ERR_FAIL_COND_MSG(singleton_ptrs.has(p_singleton.name), vformat("Can't register singleton '%s' because it already exists.", p_singleton.name));
        singletons.push_back(p_singleton);
diff --git a/core/config/engine.h b/core/config/engine.h
index be7cd62f66..d1495b36c2 100644
--- a/core/config/engine.h
+++ b/core/config/engine.h
@@ -126,6 +126,7 @@ public:
        void set_print_error_messages(bool p_enabled);
        bool is_printing_error_messages() const;
        void print_header(const String &p_string) const;
+       void print_header_rich(const String &p_string) const;

        void set_frame_delay(uint32_t p_msec);
        uint32_t get_frame_delay() const;
diff --git a/main/main.cpp b/main/main.cpp
index 9215f2e848..1b8a079d70 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -398,15 +398,15 @@ void Main::print_header(bool p_rich) {
        if (VERSION_TIMESTAMP > 0) {
                // Version timestamp available.
                if (p_rich) {
-                       print_line_rich("\u001b[38;5;39m" + String(VERSION_NAME) + "\u001b[0m v" + get_full_version_string() + " (" + Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC) - \u001b[4m" + String(VERSION_WEBSITE));
+                       Engine::get_singleton()->print_header_rich("\u001b[38;5;39m" + String(VERSION_NAME) + "\u001b[0m v" + get_full_version_string() + " (" + Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC) - \u001b[4m" + String(VERSION_WEBSITE));
                } else {
-                       print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " (" + Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC) - " + String(VERSION_WEBSITE));
+                       Engine::get_singleton()->print_header(String(VERSION_NAME) + " v" + get_full_version_string() + " (" + Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC) - " + String(VERSION_WEBSITE));
                }
        } else {
                if (p_rich) {
-                       print_line_rich("\u001b[38;5;39m" + String(VERSION_NAME) + "\u001b[0m v" + get_full_version_string() + " - \u001b[4m" + String(VERSION_WEBSITE));
+                       Engine::get_singleton()->print_header_rich("\u001b[38;5;39m" + String(VERSION_NAME) + "\u001b[0m v" + get_full_version_string() + " - \u001b[4m" + String(VERSION_WEBSITE));
                } else {
-                       print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
+                       Engine::get_singleton()->print_header(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
                }
        }
 }

But this might be sufficient, but I don't like accessing this value directly, it makes it so we depend on how this internal details is implemented, which is error prone (I'd personally prefer if we didn't even set the variable directly but used a method for it)

@AThousandShips AThousandShips added this to the 4.x milestone Mar 19, 2024
@akien-mga akien-mga changed the title Simple check for _print_header before printing anything Properly skip printing version header with --no-header Mar 25, 2024
@akien-mga
Copy link
Member

Updated with @AThousandShips' suggested improvement.

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Mar 25, 2024
@akien-mga
Copy link
Member

For the record, this was implemented properly in #79179, but it was broken when rebasing #59247.

@akien-mga akien-mga added bug and removed enhancement labels Mar 25, 2024
@AThousandShips
Copy link
Member

I was wondering why it wasn't used, that explains it

main/main.cpp Outdated Show resolved Hide resolved
@akien-mga akien-mga merged commit f371913 into godotengine:master Mar 26, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@enetheru enetheru deleted the patch-3 branch June 25, 2024 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants