From 12898fb609e88000b586222486242755b43f657d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 14 Jan 2020 21:12:52 +0100 Subject: [PATCH] Display the list of conversations --- conversations_screen.cpp | 14 +++++++++++--- ui_utils.cpp | 9 +++++++++ ui_utils.h | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/conversations_screen.cpp b/conversations_screen.cpp index d03d52a..6bea6c7 100644 --- a/conversations_screen.cpp +++ b/conversations_screen.cpp @@ -48,7 +48,7 @@ static void ChooseConv(ConversationsList &list, const UsersList &users, Conversa /* Create items */ vector itemsStr; - int numItems = 0; + size_t numItems = 0; n_choices = static_cast(list.size()) + 2; my_items = static_cast(calloc(static_cast(n_choices), sizeof(ITEM *))); @@ -57,8 +57,16 @@ static void ChooseConv(ConversationsList &list, const UsersList &users, Conversa // Conversations for(size_t i = 0; i < list.size(); ++i) { - itemsStr.push_back(list[i].name(users)); - my_items[i+1] = new_item("yo", "d"); + std::string name = list[i].name(users); + ui_utils::remove_special_chars(name); + itemsStr.push_back(name); + itemsStr.push_back(to_string(list[i].members().size()) + " members"); + } + + for(size_t i = 0; i < list.size(); ++i) { + my_items[i+1] = new_item(itemsStr.at(numItems).c_str(), + itemsStr.at(numItems+1).c_str()); + numItems+=2; } my_items[n_choices-1] = new_item(nullptr, nullptr); diff --git a/ui_utils.cpp b/ui_utils.cpp index 733ad13..a2000d0 100644 --- a/ui_utils.cpp +++ b/ui_utils.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include using namespace std; @@ -70,3 +72,10 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, char *strin wattroff(win, color); refresh(); } + +void ui_utils::remove_special_chars(string &input) +{ + input.erase(std::remove_if(input.begin(), input.end(), + [](char c) { return !std::isspace(c) && !std::isalpha(c); } ), + input.end()); +} diff --git a/ui_utils.h b/ui_utils.h index b4c8f3a..2a0e834 100644 --- a/ui_utils.h +++ b/ui_utils.h @@ -13,6 +13,7 @@ namespace ui_utils { void alert(WINDOW *win, const std::string &msg); void print_base_screen(WINDOW *w); + void remove_special_chars(std::string &input); } void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);