Project

General

Profile

« Previous | Next » 

Revision 0a32fd63

Added by david.sorber over 2 years ago

Improved filtering and added parsing input from a plaintext file.

View differences:

src/Catalog.cc
#include <algorithm>
#include <fstream>
#include <iostream>
#include "Catalog.h"
Catalog::Catalog()
{
// Temporarily fill the catalog with some test data
/*
{"Target", "baranovich@gmail.com\nF-B-3-7"},
{"United", "david.sorber@gmail.com\nF-B-3-7"},
{"Pepco", "david.sorber@gmail.com\nNZ-98-O"},
{"Washington Gas", "baranovich@gmail.com\nS-N-718"}
*/
#if 0
m_catalog.push_back({"Target", "baranovich@gmail.com\nF-B-3-7"});
m_catalog.push_back({"United", "david.sorber@gmail.com\nF-B-3-7"});
m_catalog.push_back({"Pepco", "david.sorber@gmail.com\nNZ-98-O"});
m_catalog.push_back({"Washington Gas", "baranovich@gmail.com\nS-N-718"});
#else
const std::string pwFile("/home/dsorber/Documents/chicken_soup/chicken_soup.txt");
std::ifstream infile(pwFile);
if (! infile)
{
return;
}
// Iterate over the PW file and parse it (key is first line of each stanza
// and the value are the remaining lines)
std::string line;
std::string key;
std::string value;
bool firstLine = true;
while (std::getline(infile, line))
{
if (line.size() == 0)
{
// Debuggery
// std::cout << "KEY: " << key << std::endl;
// std::cout << "VAL: " << value << "\n" << std::endl;
m_catalog.push_back({key, value});
firstLine = true;
}
else
{
if (firstLine)
{
key.clear();
value.clear();
key.swap(line);
firstLine = false;
}
else
{
value += line + "\n";
}
}
}
// Debuggery
// std::cout << "KEY: " << key << std::endl;
// std::cout << "VAL: " << value << "\n" << std::endl;
m_catalog.push_back({key, value});
// Close the input file
infile.close();
#endif
// Sort the catalog (A -> Z) for display purposes
std::sort(
src/CatalogItem.cc
#include <cstring>
#include "CatalogItem.h"
CatalogItem::CatalogItem(const std::string& key, const std::string& value)
......
m_keyLower.at(idx) = (m_keyLower.at(idx) | 32);
}
}
// Zero out value buffer and then copy the value into the buffer
std::memset(m_valueBuffer, 0, VALUE_BUFFER_SIZE);
std::memcpy(m_valueBuffer, m_value.data(), m_value.size());
}
CatalogItem::~CatalogItem()
src/CatalogItem.h
{
public:
static inline const uint32_t VALUE_BUFFER_SIZE{1024};
CatalogItem(const std::string& key, const std::string& value);
~CatalogItem();
......
return m_value;
}
inline char* getValueBuffer()
{
return m_valueBuffer;
}
inline uint32_t getValueBufferSize() const
{
return VALUE_BUFFER_SIZE;
}
/**
* Should this CatalogItem be visible
* @return
......
std::string m_keyLower;
std::string m_value;
char m_valueBuffer[VALUE_BUFFER_SIZE];
bool m_visible;
};
src/main.cpp
// pwmgr main
// Dear ImGui: standalone example application for SDL2 + SDL_Renderer
// (SDL is a cross-platform general purpose library for handling windows, inputs,
// OpenGL/Vulkan/Metal graphics context creation, etc.)
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp
//
// TODO: consider switching to the below
// Important to understand: SDL_Renderer is an _optional_ component of SDL2.
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and
// SDL+OpenGL on Linux/OSX.
......
#include <cstdio>
#include <cstdint>
#include <iostream>
//#include <ostream>
#include <map>
#include <string>
#include <vector>
......
#endif
const std::string APP_NAME("pwmgr");
const std::string VERSION("v0.0.1");
const std::string BOLD{"\033[1m"};
......
#define ERROR_MSG BOLD << RED << "ERROR: " << ENDC
Catalog catalog;
static ImGuiInputTextFlags MULTILINE_TEXT_FLAGS = ImGuiInputTextFlags_AllowTabInput;
static ImGuiInputTextFlags MULTILINE_TEXT_FLAGS =
ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_ReadOnly;
int catalogFilterCallback(ImGuiInputTextCallbackData* data)
{
if (data->BufTextLen > 0)
{
std::cout << "BUFFER: " << data->Buf << std::endl;
// Lowercase the buffer in place
for (uint32_t idx = 0; idx < data->BufTextLen; ++idx)
{
if ((data->Buf[idx] >= 'A') && (data->Buf[idx] <= 'Z'))
{
data->Buf[idx] |= 32;
}
}
// Debuggery
// std::cout << "BUFFER: " << data->Buf << std::endl;
// Now filter the catalog
catalog.filter(data->Buf);
}
else
......
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != nullptr);
// Our state
bool show_demo_window = false;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// GUI state
// Main loop
bool done = false;
......
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
#endif
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::Begin("inner window", nullptr,
ImGui::Begin("inner_window", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_MenuBar);
......
for (auto& iter : catalog)
{
// ImGuiInputTextFlags_ReadOnly
if (iter.visible() &&
ImGui::CollapsingHeader(iter.getKey().c_str()))
{
// ImGui::Text("%s", iter.second.c_str());
ImGui::InputTextMultiline(
iter.getLcKey().c_str(),
const_cast<char*>(iter.getValue().c_str()),
iter.getValue().size(),
ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 4),
iter.getValueBuffer(),
iter.getValueBufferSize(),
ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 4),
MULTILINE_TEXT_FLAGS);
}
}
......
ImGui::BeginChild("item view",
ImVec2(0, -ImGui::GetFrameHeightWithSpacing()));
// ImGui::Text("MyObject: %d", selected);
char str0[128]{};
ImGui::InputText("Filter", str0,
IM_ARRAYSIZE(str0),
char filterBuffer[128]{};
ImGui::InputText("Filter", filterBuffer,
IM_ARRAYSIZE(filterBuffer),
ImGuiInputTextFlags_CallbackEdit,
catalogFilterCallback);
ImGui::Separator();
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
{
if (ImGui::BeginTabItem("Description"))
if (ImGui::BeginTabItem("Options"))
{
ImGui::TextWrapped(
"Lorem ipsum dolor sit amet, consectetur adipiscing "
......
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Details"))
if (ImGui::BeginTabItem("About"))
{
ImGui::Text("ID: 0123456789");
ImGui::Text("%s version: %s", APP_NAME.c_str(),
VERSION.c_str());
ImGui::Text("Compiled on: %s ", __TIMESTAMP__);
ImGui::Text("Created by: dsorber");
ImGui::EndTabItem();
}
ImGui::EndTabBar();

Also available in: Unified diff