Fix: improve notification display formatting and add global exception handling
- 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
This commit is contained in:
@@ -21,4 +21,28 @@ namespace util
|
|||||||
{
|
{
|
||||||
std::cout << "\x1B[2J\x1B[H" << std::flush;
|
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) + "...";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -553,9 +553,9 @@ inline const Notification* selectNotification(const util::Vector<const Notificat
|
|||||||
{
|
{
|
||||||
util::Map<int, const Notification*> indexedNotifications;
|
util::Map<int, const Notification*> indexedNotifications;
|
||||||
std::cout << std::left
|
std::cout << std::left
|
||||||
<< std::setw(6) << "Index"
|
<< std::setw(10) << "Index"
|
||||||
<< std::setw(15) << "ID"
|
<< std::setw(15) << "ID"
|
||||||
<< std::setw(30) << "Title"
|
<< std::setw(35) << "Title"
|
||||||
<< std::setw(25) << "Timestamp"
|
<< std::setw(25) << "Timestamp"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
int currentIndex = 1;
|
int currentIndex = 1;
|
||||||
@@ -565,9 +565,9 @@ inline const Notification* selectNotification(const util::Vector<const Notificat
|
|||||||
if (currentNotification)
|
if (currentNotification)
|
||||||
{
|
{
|
||||||
std::cout << std::left
|
std::cout << std::left
|
||||||
<< std::setw(6) << currentIndex
|
<< std::setw(10) << currentIndex
|
||||||
<< std::setw(15) << currentNotification->getId()
|
<< std::setw(15) << currentNotification->getId()
|
||||||
<< std::setw(35) << currentNotification->getTitle()
|
<< std::setw(35) << util::truncateString(currentNotification->getTitle(), 30)
|
||||||
<< std::setw(25) << currentNotification->getCreatedAt().toString()
|
<< std::setw(25) << currentNotification->getCreatedAt().toString()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
indexedNotifications.insert(currentIndex, currentNotification);
|
indexedNotifications.insert(currentIndex, currentNotification);
|
||||||
@@ -886,7 +886,7 @@ inline bool getNotificationPreference(const std::string& serviceName)
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << " Configure Notification Preferences\n";
|
std::cout << "Configure Notification Preferences\n";
|
||||||
std::cout << "\n" << serviceName << " Notifications\n";
|
std::cout << "\n" << serviceName << " Notifications\n";
|
||||||
std::cout << "1. Enable Notifications\n";
|
std::cout << "1. Enable Notifications\n";
|
||||||
std::cout << "2. Disable Notifications\n";
|
std::cout << "2. Disable Notifications\n";
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ Author: Trenser
|
|||||||
Date:19-May-2026
|
Date:19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
#include "InputHelper.h"
|
#include "InputHelper.h"
|
||||||
#include "OutputHelper.h"
|
#include "OutputHelper.h"
|
||||||
@@ -23,6 +25,8 @@ Return type: void
|
|||||||
*/
|
*/
|
||||||
void UserInterface::run()
|
void UserInterface::run()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
m_controller.loadSystemData();
|
m_controller.loadSystemData();
|
||||||
m_controller.runSystemChecks();
|
m_controller.runSystemChecks();
|
||||||
bool isMenuActive = true;
|
bool isMenuActive = true;
|
||||||
@@ -46,6 +50,19 @@ void UserInterface::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_controller.saveSystemData();
|
m_controller.saveSystemData();
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument& exception)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: Invalid Argument: " << exception.what() << std::endl;
|
||||||
|
}
|
||||||
|
catch (const std::exception& exception)
|
||||||
|
{
|
||||||
|
std::cout << "Exception: " << exception.what() << std::endl;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
std::cout << "Unknown error occurred." << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user