2006-03-04 18:16:49 +00:00
|
|
|
/*
|
|
|
|
htop - ListItem.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2006-03-04 18:16:49 +00:00
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ListItem.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
|
|
|
#include "CRT.h"
|
2015-08-19 16:43:20 +00:00
|
|
|
#include "StringUtils.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
#include "RichString.h"
|
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
/*{
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "Object.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
typedef struct ListItem_ {
|
|
|
|
Object super;
|
|
|
|
char* value;
|
|
|
|
int key;
|
2015-01-22 01:27:31 +00:00
|
|
|
bool moving;
|
2006-03-04 18:16:49 +00:00
|
|
|
} ListItem;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void ListItem_delete(Object* cast) {
|
|
|
|
ListItem* this = (ListItem*)cast;
|
|
|
|
free(this->value);
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ListItem_display(Object* cast, RichString* out) {
|
2015-01-22 01:27:31 +00:00
|
|
|
ListItem* const this = (ListItem*)cast;
|
2008-03-09 08:58:38 +00:00
|
|
|
assert (this != NULL);
|
2012-11-10 00:31:37 +00:00
|
|
|
/*
|
2008-03-09 08:58:38 +00:00
|
|
|
int len = strlen(this->value)+1;
|
|
|
|
char buffer[len+1];
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, len, "%s", this->value);
|
2012-11-10 00:31:37 +00:00
|
|
|
*/
|
2015-01-22 01:27:31 +00:00
|
|
|
if (this->moving) {
|
2015-07-17 12:33:34 +00:00
|
|
|
RichString_write(out, CRT_colors[DEFAULT_COLOR],
|
|
|
|
#ifdef HAVE_LIBNCURSESW
|
2015-09-19 16:21:22 +00:00
|
|
|
CRT_utf8 ? "↕ " :
|
2015-07-17 12:33:34 +00:00
|
|
|
#endif
|
2015-09-19 16:21:22 +00:00
|
|
|
"+ ");
|
2015-01-22 01:27:31 +00:00
|
|
|
} else {
|
|
|
|
RichString_prune(out);
|
|
|
|
}
|
|
|
|
RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
ObjectClass ListItem_class = {
|
|
|
|
.display = ListItem_display,
|
2012-12-12 13:03:52 +00:00
|
|
|
.delete = ListItem_delete,
|
|
|
|
.compare = ListItem_compare
|
2012-12-05 15:12:20 +00:00
|
|
|
};
|
|
|
|
|
2010-02-25 01:43:18 +00:00
|
|
|
ListItem* ListItem_new(const char* value, int key) {
|
2012-12-05 15:12:20 +00:00
|
|
|
ListItem* this = AllocThis(ListItem);
|
2016-02-02 14:53:02 +00:00
|
|
|
this->value = xStrdup(value);
|
2006-03-04 18:16:49 +00:00
|
|
|
this->key = key;
|
2015-01-22 01:27:31 +00:00
|
|
|
this->moving = false;
|
2006-03-04 18:16:49 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-11-10 00:31:37 +00:00
|
|
|
void ListItem_append(ListItem* this, const char* text) {
|
|
|
|
int oldLen = strlen(this->value);
|
|
|
|
int textLen = strlen(text);
|
|
|
|
int newLen = strlen(this->value) + textLen;
|
2016-02-02 14:53:02 +00:00
|
|
|
this->value = xRealloc(this->value, newLen + 1);
|
2012-11-10 00:31:37 +00:00
|
|
|
memcpy(this->value + oldLen, text, textLen);
|
|
|
|
this->value[newLen] = '\0';
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* ListItem_getRef(ListItem* this) {
|
|
|
|
return this->value;
|
|
|
|
}
|
|
|
|
|
2014-04-25 22:41:23 +00:00
|
|
|
long ListItem_compare(const void* cast1, const void* cast2) {
|
2006-03-04 18:16:49 +00:00
|
|
|
ListItem* obj1 = (ListItem*) cast1;
|
|
|
|
ListItem* obj2 = (ListItem*) cast2;
|
|
|
|
return strcmp(obj1->value, obj2->value);
|
|
|
|
}
|