From ac5cecb6fc6e08283cf7278acea6490cacec17d6 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 17 Feb 2009 18:33:32 +0000 Subject: [PATCH] Option to display hostname in the meters area --- CRT.c | 7 +++++++ CRT.h | 1 + ChangeLog | 1 + HostnameMeter.c | 33 +++++++++++++++++++++++++++++++++ HostnameMeter.h | 22 ++++++++++++++++++++++ Makefile.am | 5 +++-- Meter.c | 2 ++ Meter.h | 1 + 8 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 HostnameMeter.c create mode 100644 HostnameMeter.h diff --git a/CRT.c b/CRT.c index 3b54db11..86771eda 100644 --- a/CRT.c +++ b/CRT.c @@ -100,6 +100,7 @@ typedef enum ColorElements_ { CPU_IOWAIT, CPU_IRQ, CPU_SOFTIRQ, + HOSTNAME, LAST_COLORELEMENT } ColorElements; @@ -264,6 +265,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CPU_IOWAIT] = A_NORMAL; CRT_colors[CPU_IRQ] = A_BOLD; CRT_colors[CPU_SOFTIRQ] = A_BOLD; + CRT_colors[HOSTNAME] = A_BOLD; } else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE) { CRT_colors[RESET_COLOR] = ColorPair(Black,White); CRT_colors[DEFAULT_COLOR] = ColorPair(Black,White); @@ -322,6 +324,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black); CRT_colors[CPU_IRQ] = ColorPair(Blue,White); CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,White); + CRT_colors[HOSTNAME] = ColorPair(Black,White); } else if (CRT_colorScheme == COLORSCHEME_BLACKONWHITE2) { CRT_colors[RESET_COLOR] = ColorPair(Black,Black); CRT_colors[DEFAULT_COLOR] = ColorPair(Black,Black); @@ -380,6 +383,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black); CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black); CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,Black); + CRT_colors[HOSTNAME] = ColorPair(White,Black); } else if (CRT_colorScheme == COLORSCHEME_MIDNIGHT) { CRT_colors[RESET_COLOR] = ColorPair(White,Blue); CRT_colors[DEFAULT_COLOR] = ColorPair(White,Blue); @@ -438,6 +442,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,Blue); CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Black,Blue); CRT_colors[CPU_SOFTIRQ] = ColorPair(Black,Blue); + CRT_colors[HOSTNAME] = ColorPair(White,Blue); } else if (CRT_colorScheme == COLORSCHEME_BLACKNIGHT) { CRT_colors[RESET_COLOR] = ColorPair(Cyan,Black); CRT_colors[DEFAULT_COLOR] = ColorPair(Cyan,Black); @@ -496,6 +501,7 @@ void CRT_setColors(int colorScheme) { CRT_colors[CPU_IOWAIT] = ColorPair(Yellow,Black); CRT_colors[CPU_IRQ] = A_BOLD | ColorPair(Blue,Black); CRT_colors[CPU_SOFTIRQ] = ColorPair(Blue,Black); + CRT_colors[HOSTNAME] = ColorPair(Green,Black); } else { /* Default */ CRT_colors[RESET_COLOR] = ColorPair(White,Black); @@ -555,5 +561,6 @@ void CRT_setColors(int colorScheme) { CRT_colors[CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black); CRT_colors[CPU_IRQ] = ColorPair(Yellow,Black); CRT_colors[CPU_SOFTIRQ] = ColorPair(Magenta,Black); + CRT_colors[HOSTNAME] = A_BOLD; } } diff --git a/CRT.h b/CRT.h index 4d228351..02ed5c4b 100644 --- a/CRT.h +++ b/CRT.h @@ -102,6 +102,7 @@ typedef enum ColorElements_ { CPU_IOWAIT, CPU_IRQ, CPU_SOFTIRQ, + HOSTNAME, LAST_COLORELEMENT } ColorElements; diff --git a/ChangeLog b/ChangeLog index 7f3c95e3..7444d59a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ What's new in version 0.8.2 +* Option to display hostname in the meters area * BUGFIX: Fix missing tree view when userland threads are hidden (thanks to Josh Stone) * BUGFIX: Fix for VPID on OpenVZ systems diff --git a/HostnameMeter.c b/HostnameMeter.c new file mode 100644 index 00000000..db3528c6 --- /dev/null +++ b/HostnameMeter.c @@ -0,0 +1,33 @@ +/* +htop +(C) 2004-2006 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "HostnameMeter.h" +#include "Meter.h" + +#include + +#include "debug.h" + +int HostnameMeter_attributes[] = { + HOSTNAME +}; + +static void HostnameMeter_setValues(Meter* this, char* buffer, int size) { + gethostname(buffer, size-1); +} + +MeterType HostnameMeter = { + .setValues = HostnameMeter_setValues, + .display = NULL, + .mode = TEXT_METERMODE, + .total = 100.0, + .items = 1, + .attributes = HostnameMeter_attributes, + .name = "Hostname", + .uiName = "Hostname", + .caption = "Hostname: ", +}; diff --git a/HostnameMeter.h b/HostnameMeter.h new file mode 100644 index 00000000..49e96aa0 --- /dev/null +++ b/HostnameMeter.h @@ -0,0 +1,22 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_HostnameMeter +#define HEADER_HostnameMeter +/* +htop +(C) 2004-2006 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +#include + +#include "debug.h" + +extern int HostnameMeter_attributes[]; + +extern MeterType HostnameMeter; + +#endif diff --git a/Makefile.am b/Makefile.am index 2ffda5c8..2e9c076f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,8 @@ DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ SignalItem.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \ -UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c +UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ +HostnameMeter.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ @@ -28,7 +29,7 @@ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ ScreenManager.h Settings.h SignalItem.h SignalsPanel.h String.h \ SwapMeter.h TasksMeter.h TraceScreen.h UptimeMeter.h UsersTable.h Vector.h \ -Process.h AffinityPanel.h +Process.h AffinityPanel.h HostnameMeter.h SUFFIXES = .h diff --git a/Meter.c b/Meter.c index eec5ca56..1436bb22 100644 --- a/Meter.c +++ b/Meter.c @@ -98,6 +98,7 @@ typedef enum { #include "UptimeMeter.h" #include "BatteryMeter.h" #include "ClockMeter.h" +#include "HostnameMeter.h" #ifndef MIN @@ -124,6 +125,7 @@ MeterType* Meter_types[] = { &UptimeMeter, &BatteryMeter, &AllCPUsMeter, + &HostnameMeter, NULL }; diff --git a/Meter.h b/Meter.h index 34f83816..86e3489c 100644 --- a/Meter.h +++ b/Meter.h @@ -99,6 +99,7 @@ typedef enum { #include "UptimeMeter.h" #include "BatteryMeter.h" #include "ClockMeter.h" +#include "HostnameMeter.h" #ifndef MIN