aboutsummaryrefslogtreecommitdiffstats
path: root/FunctionBar.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /FunctionBar.c
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'FunctionBar.c')
-rw-r--r--FunctionBar.c74
1 files changed, 51 insertions, 23 deletions
diff --git a/FunctionBar.c b/FunctionBar.c
index e05f72e..627bc77 100644
--- a/FunctionBar.c
+++ b/FunctionBar.c
@@ -1,18 +1,21 @@
/*
htop - FunctionBar.c
(C) 2004-2011 Hisham H. Muhammad
-Released under the GNU GPL, see the COPYING file
+Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
+#include "config.h" // IWYU pragma: keep
+
#include "FunctionBar.h"
-#include "CRT.h"
-#include "RichString.h"
-#include "XAlloc.h"
-#include <assert.h>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
+
+#include "CRT.h"
+#include "Macros.h"
+#include "ProvideCurses.h"
+#include "XUtils.h"
static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL};
@@ -24,6 +27,8 @@ static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_
static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
static const int FunctionBar_EnterEscEvents[] = {13, 27};
+static int currentLen = 0;
+
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
const char* functions[] = {enter, esc, NULL};
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
@@ -40,20 +45,20 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke
}
if (keys && events) {
this->staticData = false;
- this->keys = xCalloc(15, sizeof(char*));
+ this->keys.keys = xCalloc(15, sizeof(char*));
this->events = xCalloc(15, sizeof(int));
int i = 0;
while (i < 15 && functions[i]) {
- this->keys[i] = xStrdup(keys[i]);
+ this->keys.keys[i] = xStrdup(keys[i]);
this->events[i] = events[i];
i++;
}
this->size = i;
} else {
this->staticData = true;
- this->keys = (char**) FunctionBar_FKeys;
+ this->keys.constKeys = FunctionBar_FKeys;
this->events = FunctionBar_FEvents;
- this->size = 10;
+ this->size = ARRAYSIZE(FunctionBar_FEvents);
}
return this;
}
@@ -65,9 +70,9 @@ void FunctionBar_delete(FunctionBar* this) {
free(this->functions);
if (!this->staticData) {
for (int i = 0; i < this->size; i++) {
- free(this->keys[i]);
+ free(this->keys.keys[i]);
}
- free(this->keys);
+ free(this->keys.keys);
free(this->events);
}
free(this);
@@ -83,37 +88,60 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
}
}
-void FunctionBar_draw(const FunctionBar* this, char* buffer) {
- FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
+void FunctionBar_draw(const FunctionBar* this) {
+ FunctionBar_drawExtra(this, NULL, -1, false);
}
-void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
+void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) {
attrset(CRT_colors[FUNCTION_BAR]);
- mvhline(LINES-1, 0, ' ', COLS);
+ mvhline(LINES - 1, 0, ' ', COLS);
int x = 0;
for (int i = 0; i < this->size; i++) {
attrset(CRT_colors[FUNCTION_KEY]);
- mvaddstr(LINES-1, x, this->keys[i]);
- x += strlen(this->keys[i]);
+ mvaddstr(LINES - 1, x, this->keys.constKeys[i]);
+ x += strlen(this->keys.constKeys[i]);
attrset(CRT_colors[FUNCTION_BAR]);
- mvaddstr(LINES-1, x, this->functions[i]);
+ mvaddstr(LINES - 1, x, this->functions[i]);
x += strlen(this->functions[i]);
}
+
if (buffer) {
- attrset(attr);
- mvaddstr(LINES-1, x, buffer);
- CRT_cursorX = x + strlen(buffer);
+ if (attr == -1) {
+ attrset(CRT_colors[FUNCTION_BAR]);
+ } else {
+ attrset(attr);
+ }
+ mvaddstr(LINES - 1, x, buffer);
+ attrset(CRT_colors[RESET_COLOR]);
+ x += strlen(buffer);
+ }
+
+ if (setCursor) {
+ CRT_cursorX = x;
curs_set(1);
} else {
curs_set(0);
}
+
+ currentLen = x;
+}
+
+void FunctionBar_append(const char* buffer, int attr) {
+ if (attr == -1) {
+ attrset(CRT_colors[FUNCTION_BAR]);
+ } else {
+ attrset(attr);
+ }
+ mvaddstr(LINES - 1, currentLen, buffer);
attrset(CRT_colors[RESET_COLOR]);
+
+ currentLen += strlen(buffer);
}
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {
int x = 0;
for (int i = 0; i < this->size; i++) {
- x += strlen(this->keys[i]);
+ x += strlen(this->keys.constKeys[i]);
x += strlen(this->functions[i]);
if (pos < x) {
return this->events[i];

© 2014-2024 Faster IT GmbH | imprint | privacy policy