mirror of
https://github.com/RGBCube/ZTerm
synced 2025-07-28 08:27:45 +00:00
Add charsets and fix off-by-one error
This commit is contained in:
parent
8716c68f55
commit
7ef370f96e
3 changed files with 11 additions and 4 deletions
|
@ -16,7 +16,7 @@ const zterm = @import("zterm");
|
|||
|
||||
pub fn main() !void {
|
||||
var sp = zterm.Spinner{
|
||||
.charset = &[_][]const u8{ "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷" },
|
||||
.charset = zterm.Spinner.charsets[3],
|
||||
.message = "Selling all your data to the CCP...",
|
||||
};
|
||||
try sp.start();
|
||||
|
|
|
@ -5,8 +5,15 @@ const Thread = std.Thread;
|
|||
const time = std.time;
|
||||
const Spinner = @This();
|
||||
|
||||
pub const charsets = [_][]const []const u8{
|
||||
&[_][]const u8{ "|", "/", "-", "\\" },
|
||||
&[_][]const u8{ "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" },
|
||||
&[_][]const u8{ "⠋", "⠙", "⠚", "⠞", "⠖", "⠦", "⠴", "⠲", "⠳", "⠓" },
|
||||
&[_][]const u8{ "⠄", "⠆", "⠇", "⠋", "⠙", "⠸", "⠰", "⠠", " ", "⠠", "⠰", "⠸", "⠙", "⠋", "⠇", "⠆", "⠄", " " },
|
||||
};
|
||||
|
||||
// Must be only accessed when thread_lock is held by the current thread.
|
||||
charset: []const []const u8 = &[_][]const u8{ "|", "/", "-", "\\" },
|
||||
charset: []const []const u8 = charsets[0],
|
||||
message: []const u8 = "",
|
||||
|
||||
keep_going: Atomic(bool) = Atomic(bool).init(false),
|
||||
|
@ -59,7 +66,7 @@ fn writer(sp: *Spinner) !void {
|
|||
|
||||
while (true) : (current_char_idx += 1) {
|
||||
if (!sp.keep_going.load(.SeqCst)) return;
|
||||
if (current_char_idx >= sp.charset.len - 1) current_char_idx = 0;
|
||||
if (current_char_idx > sp.charset.len - 1) current_char_idx = 0;
|
||||
|
||||
sp.thread_lock.lock();
|
||||
try stdErr.writeAll(sp.charset[current_char_idx]);
|
||||
|
|
|
@ -6,7 +6,7 @@ const zterm = struct {
|
|||
|
||||
pub fn main() !void {
|
||||
var sp = zterm.Spinner{
|
||||
.charset = &[_][]const u8{ "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷" },
|
||||
.charset = zterm.Spinner.charsets[3],
|
||||
.message = "Selling all your data to the CCP...",
|
||||
};
|
||||
try sp.start();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue