Consolix
Loading...
Searching...
No Matches
TitleComponent.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _CONSOLIX_TITLE_COMPONENT_HPP_INCLUDED
3#define _CONSOLIX_TITLE_COMPONENT_HPP_INCLUDED
4
8
9#include <string>
10
11namespace consolix {
12
21 public:
24 explicit TitleComponent(const std::string& title = std::string()) {
25 if (!title.empty()) {
26 set_title(title);
27 }
28 }
29
31 virtual ~TitleComponent() override = default;
32
35 void set_title(const std::string& title) {
36 m_title = title;
37# if defined(_WIN32) || defined(_WIN64)
38 std::wstring wtitle = utf8_to_utf16(title);
39 SetConsoleTitleW(wtitle.c_str());
40# else
41 std::cout << "\033]0;" << title << "\007";
42# endif
43 }
44
47 std::string get_title() const {
48 return m_title;
49 }
50
53 static std::string get_executable_name() {
55 }
56
58 bool initialize() override {
59 return true;
60 }
61
63 bool is_initialized() const override {
64 return true;
65 }
66
68 void process() override {}
69
70 private:
71 std::string m_title;
72 };
73
74};
75
76#endif // _CONSOLIX_TITLE_COMPONENT_HPP_INCLUDED
Interface for defining application components.
void process() override
Executes the component (no-op).
bool is_initialized() const override
Checks if the component is initialized.
std::string get_title() const
Gets the last set console title.
std::string m_title
Stores the last set title.
void set_title(const std::string &title)
Sets the console window title.
virtual ~TitleComponent() override=default
Virtual destructor.
TitleComponent(const std::string &title=std::string())
Constructs the component and optionally sets the console title.
static std::string get_executable_name()
Retrieves the executable name.
bool initialize() override
Initializes the component (no-op).
< Utility modules and helpers.
std::string get_exec_path()
Retrieves the full path of the executable.
std::string get_file_name(const std::string &file_path)
Extracts the file name from a full file path.