From d93cac12be1a7a580e338c6fa80286bfa703ffc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Mon, 5 Oct 2020 13:52:58 +0200 Subject: [PATCH] Add a date and datetime meter (#159) Add a date meter and sort header and source files in Makefile Change the lists of header and source files sorted alphabetical and one file per line. This way diffs become better readable and merges easier. --- CRT.c | 10 ++++ CRT.h | 2 + DateMeter.c | 47 ++++++++++++++++ DateMeter.h | 16 ++++++ DateTimeMeter.c | 47 ++++++++++++++++ DateTimeMeter.h | 16 ++++++ Makefile.am | 120 +++++++++++++++++++++++++++++++++------- darwin/Platform.c | 4 ++ dragonflybsd/Platform.c | 4 ++ freebsd/Platform.c | 4 ++ linux/Platform.c | 4 ++ openbsd/Platform.c | 4 ++ solaris/Platform.c | 4 ++ unsupported/Platform.c | 4 ++ 14 files changed, 267 insertions(+), 19 deletions(-) create mode 100644 DateMeter.c create mode 100644 DateMeter.h create mode 100644 DateTimeMeter.c create mode 100644 DateTimeMeter.h diff --git a/CRT.c b/CRT.c index 374e1721e..d38740437 100644 --- a/CRT.c +++ b/CRT.c @@ -122,6 +122,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), [CLOCK] = A_BOLD, + [DATE] = A_BOLD, + [DATETIME] = A_BOLD, [CHECK_BOX] = ColorPair(Cyan,Black), [CHECK_MARK] = A_BOLD, [CHECK_TEXT] = A_NORMAL, @@ -195,6 +197,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD, [HELP_BOLD] = A_BOLD, [CLOCK] = A_BOLD, + [DATE] = A_BOLD, + [DATETIME] = A_BOLD, [CHECK_BOX] = A_BOLD, [CHECK_MARK] = A_NORMAL, [CHECK_TEXT] = A_NORMAL, @@ -268,6 +272,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(Black,White), [HELP_BOLD] = ColorPair(Blue,White), [CLOCK] = ColorPair(Black,White), + [DATE] = ColorPair(Black,White), + [DATETIME] = ColorPair(Black,White), [CHECK_BOX] = ColorPair(Blue,White), [CHECK_MARK] = ColorPair(Black,White), [CHECK_TEXT] = ColorPair(Black,White), @@ -341,6 +347,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = ColorPair(Yellow,Black), [HELP_BOLD] = ColorPair(Blue,Black), [CLOCK] = ColorPair(Yellow,Black), + [DATE] = ColorPair(White,Black), + [DATETIME] = ColorPair(White,Black), [CHECK_BOX] = ColorPair(Blue,Black), [CHECK_MARK] = ColorPair(Blue,Black), [CHECK_TEXT] = ColorPair(Blue,Black), @@ -414,6 +422,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [LOAD] = A_BOLD | ColorPair(White,Blue), [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Blue), [CLOCK] = ColorPair(White,Blue), + [DATE] = ColorPair(White,Blue), + [DATETIME] = ColorPair(White,Blue), [CHECK_BOX] = ColorPair(Cyan,Blue), [CHECK_MARK] = A_BOLD | ColorPair(White,Blue), [CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue), diff --git a/CRT.h b/CRT.h index 4eeb9a461..13fe66d77 100644 --- a/CRT.h +++ b/CRT.h @@ -85,6 +85,8 @@ typedef enum ColorElements_ { CHECK_MARK, CHECK_TEXT, CLOCK, + DATE, + DATETIME, HELP_BOLD, HOSTNAME, CPU_NICE, diff --git a/DateMeter.c b/DateMeter.c new file mode 100644 index 000000000..6fd933731 --- /dev/null +++ b/DateMeter.c @@ -0,0 +1,47 @@ +/* +htop - DateMeter.c +(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "DateMeter.h" + +#include "CRT.h" + +#include + + +int DateMeter_attributes[] = { + DATE +}; + +static void DateMeter_updateValues(Meter* this, char* buffer, int size) { + time_t t = time(NULL); + struct tm result; + struct tm *lt = localtime_r(&t, &result); + this->values[0] = lt->tm_yday; + int year = lt->tm_year + 1900; + if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + this->total = 366; + } + else { + this->total = 365; + } + strftime(buffer, size, "%F", lt); +} + +MeterClass DateMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete + }, + .updateValues = DateMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 365, + .attributes = DateMeter_attributes, + .name = "Date", + .uiName = "Date", + .caption = "Date: ", +}; diff --git a/DateMeter.h b/DateMeter.h new file mode 100644 index 000000000..6cb899dd5 --- /dev/null +++ b/DateMeter.h @@ -0,0 +1,16 @@ +#ifndef HEADER_DateMeter +#define HEADER_DateMeter +/* +htop - DateMeter.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern int DateMeter_attributes[]; + +extern MeterClass DateMeter_class; + +#endif diff --git a/DateTimeMeter.c b/DateTimeMeter.c new file mode 100644 index 000000000..5c60884ae --- /dev/null +++ b/DateTimeMeter.c @@ -0,0 +1,47 @@ +/* +htop - DateTimeMeter.c +(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "DateTimeMeter.h" + +#include "CRT.h" + +#include + + +int DateTimeMeter_attributes[] = { + DATETIME +}; + +static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) { + time_t t = time(NULL); + struct tm result; + struct tm *lt = localtime_r(&t, &result); + int year = lt->tm_year + 1900; + if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + this->total = 366; + } + else { + this->total = 365; + } + this->values[0] = lt->tm_yday; + strftime(buffer, size, "%F %H:%M:%S", lt); +} + +MeterClass DateTimeMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete + }, + .updateValues = DateTimeMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 365, + .attributes = DateTimeMeter_attributes, + .name = "DateTime", + .uiName = "Date and Time", + .caption = "Date & Time: ", +}; diff --git a/DateTimeMeter.h b/DateTimeMeter.h new file mode 100644 index 000000000..6d1e3a68a --- /dev/null +++ b/DateTimeMeter.h @@ -0,0 +1,16 @@ +#ifndef HEADER_DateTimeMeter +#define HEADER_DateTimeMeter +/* +htop - DateTimeMeter.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Meter.h" + +extern int DateTimeMeter_attributes[]; + +extern MeterClass DateTimeMeter_class; + +#endif diff --git a/Makefile.am b/Makefile.am index 1ef92364a..9bfe007a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,25 +13,107 @@ pixmap_DATA = htop.png AM_CFLAGS += -pedantic -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" AM_LDFLAGS = -myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ -ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DiskIOMeter.c DiskIOMeter.h \ -MainPanel.c 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 \ -SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c \ -TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ -HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \ -InfoScreen.c CommandScreen.c XAlloc.c - -myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ -CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ -CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \ -Hashtable.h Header.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 SignalsPanel.h StringUtils.h SwapMeter.h \ -TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ -AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ -EnvScreen.h InfoScreen.h CommandScreen.h XAlloc.h Macros.h +myhtopsources = \ + Action.c \ + Affinity.c \ + AffinityPanel.c \ + AvailableColumnsPanel.c \ + AvailableMetersPanel.c \ + BatteryMeter.c \ + CategoriesPanel.c \ + CheckItem.c \ + ClockMeter.c \ + ColorsPanel.c \ + ColumnsPanel.c \ + CommandScreen.c \ + CPUMeter.c \ + CRT.c \ + DateMeter.c \ + DateTimeMeter.c \ + DiskIOMeter.c \ + DiskIOMeter.h \ + DisplayOptionsPanel.c \ + EnvScreen.c \ + FunctionBar.c \ + Hashtable.c \ + Header.c \ + HostnameMeter.c \ + htop.c \ + IncSet.c \ + InfoScreen.c \ + ListItem.c \ + LoadAverageMeter.c \ + MainPanel.c \ + MemoryMeter.c \ + Meter.c \ + MetersPanel.c \ + Object.c \ + OpenFilesScreen.c \ + Panel.c \ + Process.c \ + ProcessList.c \ + RichString.c \ + ScreenManager.c \ + Settings.c \ + SignalsPanel.c \ + StringUtils.c \ + SwapMeter.c \ + TasksMeter.c \ + TraceScreen.c \ + UptimeMeter.c \ + UsersTable.c \ + Vector.c \ + XAlloc.c + +myhtopheaders = \ + Action.h \ + Affinity.h \ + AffinityPanel.h \ + AvailableColumnsPanel.h \ + AvailableMetersPanel.h \ + BatteryMeter.h \ + CPUMeter.h \ + CRT.h \ + CategoriesPanel.h \ + CheckItem.h \ + ClockMeter.h \ + ColorsPanel.h \ + ColumnsPanel.h \ + CommandScreen.h \ + DateMeter.h \ + DateTimeMeter.h \ + DisplayOptionsPanel.h \ + EnvScreen.h \ + FunctionBar.h \ + Hashtable.h \ + Header.h \ + HostnameMeter.h \ + IncSet.h \ + InfoScreen.h \ + ListItem.h \ + LoadAverageMeter.h \ + Macros.h \ + MainPanel.h \ + MemoryMeter.h \ + Meter.h \ + MetersPanel.h \ + Object.h \ + OpenFilesScreen.h \ + Panel.h \ + Process.h \ + ProcessList.h \ + RichString.h \ + ScreenManager.h \ + Settings.h \ + SignalsPanel.h \ + StringUtils.h \ + SwapMeter.h \ + TasksMeter.h \ + TraceScreen.h \ + UptimeMeter.h \ + UsersTable.h \ + Vector.h \ + XAlloc.h # Linux # ----- diff --git a/darwin/Platform.c b/darwin/Platform.c index 5aa50a65f..8ca8d2c69 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -13,6 +13,8 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" @@ -95,6 +97,8 @@ ProcessFieldData Process_fields[] = { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 36ab2c21a..61fe25b68 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "UptimeMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "DragonFlyBSDProcess.h" #include "DragonFlyBSDProcessList.h" @@ -78,6 +80,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 36256f9a1..2c1d72e6d 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -14,6 +14,8 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "UptimeMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" @@ -79,6 +81,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/linux/Platform.c b/linux/Platform.c index 2d3258646..ef5015d1d 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -22,6 +22,8 @@ in the source distribution for its full text. #include "UptimeMeter.h" #include "PressureStallMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" @@ -106,6 +108,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/openbsd/Platform.c b/openbsd/Platform.c index ce3709945..574b573ca 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "LoadAverageMeter.h" #include "UptimeMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "SignalsPanel.h" #include "OpenBSDProcess.h" @@ -91,6 +93,8 @@ void Platform_setBindings(Htop_Action* keys) { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/solaris/Platform.c b/solaris/Platform.c index 2114215ef..07f57517d 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" @@ -88,6 +90,8 @@ ProcessField Platform_defaultFields[] = { PID, LWPID, USER, PRIORITY, NICE, M_SI MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class, diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 6a6b01310..fbcf6431f 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -15,6 +15,8 @@ in the source distribution for its full text. #include "TasksMeter.h" #include "LoadAverageMeter.h" #include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" #include "HostnameMeter.h" #include "UptimeMeter.h" @@ -59,6 +61,8 @@ ProcessFieldData Process_fields[] = { MeterClass* Platform_meterTypes[] = { &CPUMeter_class, &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, &LoadAverageMeter_class, &LoadMeter_class, &MemoryMeter_class,