sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

slstatus-kanji-20260218-614c275.diff (2780B)


      1 From 2e73de23551224fe114b7e26131d8c620c1270d7 Mon Sep 17 00:00:00 2001
      2 From: Lukas Lynch <madi@mxdi.xyz>
      3 Date: Wed, 18 Feb 2026 16:40:30 -0800
      4 Subject: [PATCH] Displays the Japanese kanji for the current day of the week.
      5 
      6 ---
      7  Makefile           |  1 +
      8  components/kanji.c | 30 ++++++++++++++++++++++++++++++
      9  config.def.h       |  1 +
     10  slstatus.h         |  3 +++
     11  4 files changed, 35 insertions(+)
     12  create mode 100644 components/kanji.c
     13 
     14 diff --git a/Makefile b/Makefile
     15 index 7a18274..305ab91 100644
     16 --- a/Makefile
     17 +++ b/Makefile
     18 @@ -14,6 +14,7 @@ COM =\
     19  	components/entropy\
     20  	components/hostname\
     21  	components/ip\
     22 +	components/kanji\
     23  	components/kernel_release\
     24  	components/keyboard_indicators\
     25  	components/keymap\
     26 diff --git a/components/kanji.c b/components/kanji.c
     27 new file mode 100644
     28 index 0000000..80228ee
     29 --- /dev/null
     30 +++ b/components/kanji.c
     31 @@ -0,0 +1,30 @@
     32 +/* Written by Lukas Lynch <madi@mxdi.xyz> */
     33 +#include <time.h>
     34 +#define LEN(x) sizeof(x) / sizeof(*x)
     35 +
     36 +static const char *symbols[] = {
     37 +        "日", // Sunday
     38 +        "月", // Monday
     39 +        "火", // Tuesday
     40 +        "水", // Wednesday
     41 +        "木", // Thursday
     42 +        "金", // Friday
     43 +        "土"  // Saturday
     44 +};
     45 +
     46 +/**
     47 +* Returns the appropriate Japanese Kanji character correlating with the current
     48 +* day of the week.
     49 +*
     50 +* @param  unused (NULL)
     51 +* @return the appropriate Kanji character (char *)
     52 +*/
     53 +const char *
     54 +kanji(const char *unused) {
     55 +    const time_t current_time = time(NULL);
     56 +    const unsigned int weekday = localtime(
     57 +        &current_time
     58 +    )->tm_wday; // We don't need anything else from returned tm structure
     59 +
     60 +    return (weekday < LEN(symbols)) ? symbols[weekday] : "?";
     61 +}
     62 \ No newline at end of file
     63 diff --git a/config.def.h b/config.def.h
     64 index 100093e..1187100 100644
     65 --- a/config.def.h
     66 +++ b/config.def.h
     67 @@ -31,6 +31,7 @@ static const char unknown_str[] = "n/a";
     68   * hostname            hostname                        NULL
     69   * ipv4                IPv4 address                    interface name (eth0)
     70   * ipv6                IPv6 address                    interface name (eth0)
     71 + * kanji               current day of week kanji       NULL
     72   * kernel_release      `uname -r`                      NULL
     73   * keyboard_indicators caps/num lock indicators        format string (c?n?)
     74   *                                                     see keyboard_indicators.c
     75 diff --git a/slstatus.h b/slstatus.h
     76 index 394281c..85c7f98 100644
     77 --- a/slstatus.h
     78 +++ b/slstatus.h
     79 @@ -32,6 +32,9 @@ const char *ipv4(const char *interface);
     80  const char *ipv6(const char *interface);
     81  const char *up(const char *interface);
     82  
     83 +/* kanji */
     84 +const char *kanji(const char *unused);
     85 +
     86  /* kernel_release */
     87  const char *kernel_release(const char *unused);
     88  
     89 -- 
     90 2.53.0
     91