prevent long strings in CPU from overflowing when outputted to screen
This commit is contained in:
parent
466c09b944
commit
d00fcd2d04
9
CPU.cpp
9
CPU.cpp
@ -6,11 +6,14 @@ using namespace std;
|
||||
|
||||
void display(const CPU &cpu) {
|
||||
|
||||
const int minTotalWidth = max((size_t) 38, cpu.cpuId.length() + 2);
|
||||
// Calculate total width, make sure architecture fits
|
||||
const vector<int> widths = {18, max(minTotalWidth - 19, (int) cpu.architecture.length() + 2)};
|
||||
const int totalWidth = widths[0] + widths[1];
|
||||
// CPU ID
|
||||
// width is different because bold characters are counted but invisible
|
||||
string boldCenteredCpuId = centeredStr(boldStr(cpu.cpuId), 46);
|
||||
printTableHeader({39}, {boldCenteredCpuId});
|
||||
static const vector<int> widths = {18, 20};
|
||||
string boldCenteredCpuId = centeredStr(boldStr(cpu.cpuId), totalWidth + 8);
|
||||
printTableHeader({totalWidth + 1}, {boldCenteredCpuId});
|
||||
|
||||
// Release Year
|
||||
cout << "| ";
|
||||
|
@ -55,11 +55,20 @@ void DisplayManager<T>::displayTree() const {
|
||||
"Architecture",
|
||||
"Base Clock (GHz)"
|
||||
};
|
||||
static const std::vector<int> widths = {20, 14, 12, 20, 18};
|
||||
printTableHeader(widths, headers);
|
||||
std::vector<int> widths = {20, 14, 12, 20, 18};
|
||||
|
||||
// Call the BST's inorder traversal method to calculate the column widths
|
||||
bst->inOrder([this, &widths](const string &cpuId) {
|
||||
CPU cpu;
|
||||
cpu.setCpuId(cpuId);
|
||||
this->hashTable->search(cpu, cpu, key_to_index);
|
||||
widths[0] = max(cpu.getCpuId().length() + 2, (size_t) widths[0]);
|
||||
widths[3] = max(cpu.getArchitecture().length() + 2, (size_t) widths[3]);
|
||||
});
|
||||
|
||||
printTableHeader(widths, headers);
|
||||
// Call the BST's inorder traversal method to display the tree
|
||||
bst->inOrder([this](const string &cpuId) {
|
||||
bst->inOrder([this, &widths](const string &cpuId) {
|
||||
CPU cpu;
|
||||
cpu.setCpuId(cpuId);
|
||||
this->hashTable->search(cpu, cpu, key_to_index);
|
||||
|
Loading…
x
Reference in New Issue
Block a user