83e2bed432
- add truncateString utility for long notification titles - improve notification table alignment - remove unnecessary heading spacing in notification preferences - add application-level exception handling in UserInterface::run() Fixes #1777
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
/*
|
|
* File: OutputHelper.h
|
|
* Description: Provides functions to help with console output.
|
|
* Author: Trenser
|
|
* Created: 18-May-2026
|
|
*/
|
|
|
|
#pragma once
|
|
#include <iostream>
|
|
|
|
namespace util
|
|
{
|
|
/*
|
|
* Function: clear
|
|
* Description: Clears the console screen output.
|
|
* Parameters: None
|
|
* Returns:
|
|
* void - no return value
|
|
*/
|
|
inline void clear()
|
|
{
|
|
std::cout << "\x1B[2J\x1B[H" << std::flush;
|
|
}
|
|
|
|
/*
|
|
Function: truncateString
|
|
Description:
|
|
Truncates a string if its length exceeds the given maximum length.
|
|
The truncated string ends with "..." to indicate omitted characters.
|
|
Parameters:
|
|
- text: const std::string&, input string to truncate
|
|
- maxLength: size_t, maximum allowed length of the returned string
|
|
Returns:
|
|
- std::string: Original string if within limit, otherwise truncated string with "..."
|
|
*/
|
|
inline std::string truncateString(const std::string& text, size_t maxLength)
|
|
{
|
|
if (text.length() <= maxLength)
|
|
{
|
|
return text;
|
|
}
|
|
if (maxLength <= 3)
|
|
{
|
|
return std::string(maxLength, '.');
|
|
}
|
|
return text.substr(0, maxLength - 3) + "...";
|
|
}
|
|
} |