mirror of https://github.com/fairyglade/ly.git
bigclock: add 12-hour & seconds support (#805)
Added P,A,M characters to bigclock and added 12hr and seconds support to bigclock via `bigclock_12hr` and `bigclock_seconds` in the config.  Image has bigclock_12hr and bigclock_seconds enabled. Farsi characters for P,A,M are blank since I don't know what it would look like in their language. (should i have just used the english characters as a placeholder?) Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/805 Reviewed-by: AnErrupTion <anerruption@disroot.org> Co-authored-by: RadsammyT <radsammyt@gmail.com> Co-committed-by: RadsammyT <radsammyt@gmail.com>
This commit is contained in:
parent
4fbbb6f0f2
commit
b382d74969
|
@ -48,7 +48,11 @@ bg = 0x00000000
|
|||
# none -> Disabled (default)
|
||||
# en -> English
|
||||
# fa -> Farsi
|
||||
bigclock = none
|
||||
bigclock = en
|
||||
# Set bigclock to 12-hour notation.
|
||||
bigclock_12hr = false
|
||||
# Set bigclock to show the seconds.
|
||||
bigclock_seconds = false
|
||||
|
||||
# Blank main box background
|
||||
# Setting to false will make it transparent
|
||||
|
|
|
@ -51,6 +51,9 @@ fn toBigNumber(char: u8, bigclock: Bigclock) [SIZE]u21 {
|
|||
'7' => locale_chars.SEVEN,
|
||||
'8' => locale_chars.EIGHT,
|
||||
'9' => locale_chars.NINE,
|
||||
'p', 'P' => locale_chars.P,
|
||||
'a', 'A' => locale_chars.A,
|
||||
'm', 'M' => locale_chars.M,
|
||||
':' => locale_chars.S,
|
||||
else => locale_chars.E,
|
||||
};
|
||||
|
|
|
@ -21,5 +21,8 @@ pub const LocaleChars = struct {
|
|||
NINE: [SIZE]u21,
|
||||
S: [SIZE]u21,
|
||||
E: [SIZE]u21,
|
||||
P: [SIZE]u21,
|
||||
A: [SIZE]u21,
|
||||
M: [SIZE]u21,
|
||||
};
|
||||
// zig fmt: on
|
||||
|
|
|
@ -90,5 +90,26 @@ pub const locale_chars = LocaleChars{
|
|||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
},
|
||||
.P = [_]u21{
|
||||
X,X,X,X,X,
|
||||
X,X,O,X,X,
|
||||
X,X,X,X,X,
|
||||
X,X,O,O,O,
|
||||
X,X,O,O,O,
|
||||
},
|
||||
.A = [_]u21{
|
||||
X,X,X,X,X,
|
||||
X,X,O,X,X,
|
||||
X,X,X,X,X,
|
||||
X,X,O,X,X,
|
||||
X,X,O,X,X,
|
||||
},
|
||||
.M = [_]u21{
|
||||
X,X,X,X,X,
|
||||
X,O,X,O,X,
|
||||
X,O,X,O,X,
|
||||
X,O,O,O,X,
|
||||
X,O,O,O,X,
|
||||
},
|
||||
};
|
||||
// zig fmt: on
|
|
@ -76,6 +76,27 @@ pub const locale_chars = LocaleChars{
|
|||
O,O,O,X,O,
|
||||
O,O,O,X,O,
|
||||
},
|
||||
.P = [_]u21{
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
},
|
||||
.A = [_]u21{
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
},
|
||||
.M = [_]u21{
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
O,O,O,O,O,
|
||||
},
|
||||
.S = [_]u21{
|
||||
O,O,O,O,O,
|
||||
O,O,X,O,O,
|
||||
|
|
|
@ -13,6 +13,8 @@ asterisk: ?u32 = '*',
|
|||
auth_fails: u64 = 10,
|
||||
bg: u32 = 0x00000000,
|
||||
bigclock: Bigclock = .none,
|
||||
bigclock_12hr: bool = false,
|
||||
bigclock_seconds: bool = false,
|
||||
blank_box: bool = true,
|
||||
border_fg: u32 = 0x00FFFFFF,
|
||||
box_title: ?[]const u8 = null,
|
||||
|
|
12
src/main.zig
12
src/main.zig
|
@ -482,11 +482,19 @@ pub fn main() !void {
|
|||
}
|
||||
|
||||
if (config.bigclock != .none and buffer.box_height + (bigclock.HEIGHT + 2) * 2 < buffer.height) {
|
||||
const format = "%H:%M";
|
||||
var format_buf: [16:0]u8 = undefined;
|
||||
var clock_buf: [32:0]u8 = undefined;
|
||||
// We need the slice/c-string returned by `bufPrintZ`.
|
||||
const format: [:0]const u8 = try std.fmt.bufPrintZ(&format_buf, "{s}{s}{s}{s}",
|
||||
.{
|
||||
if (config.bigclock_12hr) "%I" else "%H",
|
||||
":%M",
|
||||
if (config.bigclock_seconds) ":%S" else "",
|
||||
if (config.bigclock_12hr) "%P" else ""
|
||||
});
|
||||
const xo = buffer.width / 2 - @min(buffer.width, (format.len * (bigclock.WIDTH + 1))) / 2;
|
||||
const yo = (buffer.height - buffer.box_height) / 2 - bigclock.HEIGHT - 2;
|
||||
|
||||
var clock_buf: [format.len + 1:0]u8 = undefined;
|
||||
const clock_str = interop.timeAsString(&clock_buf, format);
|
||||
|
||||
for (clock_str, 0..) |c, i| {
|
||||
|
|
Loading…
Reference in New Issue