Consolix
Toggle main menu visibility
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
11
namespace
consolix
{
12
20
class
TitleComponent
:
public
IAppComponent
{
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
() {
54
return
get_file_name
(
get_exec_path
());
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
consolix::IAppComponent
Interface for defining application components.
Definition
IAppComponent.hpp:19
consolix::TitleComponent::process
void process() override
Executes the component (no-op).
Definition
TitleComponent.hpp:68
consolix::TitleComponent::is_initialized
bool is_initialized() const override
Checks if the component is initialized.
Definition
TitleComponent.hpp:63
consolix::TitleComponent::get_title
std::string get_title() const
Gets the last set console title.
Definition
TitleComponent.hpp:47
consolix::TitleComponent::m_title
std::string m_title
Stores the last set title.
Definition
TitleComponent.hpp:71
consolix::TitleComponent::set_title
void set_title(const std::string &title)
Sets the console window title.
Definition
TitleComponent.hpp:35
consolix::TitleComponent::~TitleComponent
virtual ~TitleComponent() override=default
Virtual destructor.
consolix::TitleComponent::TitleComponent
TitleComponent(const std::string &title=std::string())
Constructs the component and optionally sets the console title.
Definition
TitleComponent.hpp:24
consolix::TitleComponent::get_executable_name
static std::string get_executable_name()
Retrieves the executable name.
Definition
TitleComponent.hpp:53
consolix::TitleComponent::initialize
bool initialize() override
Initializes the component (no-op).
Definition
TitleComponent.hpp:58
consolix
< Utility modules and helpers.
Definition
BaseLoopComponent.hpp:13
consolix::get_exec_path
std::string get_exec_path()
Retrieves the full path of the executable.
Definition
path_utils.hpp:21
consolix::get_file_name
std::string get_file_name(const std::string &file_path)
Extracts the file name from a full file path.
Definition
path_utils.hpp:59
include
consolix
components
TitleComponent.hpp
Generated by
1.17.0