mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-11-11 20:43:00 +01:00
mzte-mpv: clear line before logging
This commit is contained in:
parent
4ca0521a5f
commit
43f2ac0901
3 changed files with 23 additions and 9 deletions
|
@ -1,7 +1,15 @@
|
|||
const std = @import("std");
|
||||
const root = @import("root");
|
||||
|
||||
pub usingnamespace @import("delimited_writer.zig");
|
||||
|
||||
pub const Opts = struct {
|
||||
log_pfx: ?[]const u8 = null,
|
||||
log_clear_line: bool = false,
|
||||
};
|
||||
|
||||
const opts: Opts = if (@hasDecl(root, "mztecommon_opts")) root.mztecommon_opts else .{};
|
||||
|
||||
var stderr_isatty: ?bool = null;
|
||||
|
||||
pub var log_file: ?std.fs.File = null;
|
||||
|
@ -12,11 +20,6 @@ pub fn logFn(
|
|||
comptime fmt: []const u8,
|
||||
args: anytype,
|
||||
) void {
|
||||
const log_pfx: ?[]const u8 = if (@hasDecl(@import("root"), "mztecommon_log_pfx"))
|
||||
@import("root").mztecommon_log_pfx
|
||||
else
|
||||
null;
|
||||
|
||||
const color = log_file == null and stderr_isatty orelse blk: {
|
||||
const isatty = std.posix.isatty(std.posix.STDERR_FILENO);
|
||||
stderr_isatty = isatty;
|
||||
|
@ -25,7 +28,11 @@ pub fn logFn(
|
|||
|
||||
const logfile = log_file orelse std.io.getStdErr();
|
||||
|
||||
const scope_prefix = if (log_pfx) |lpfx|
|
||||
if (opts.log_clear_line) {
|
||||
logfile.writer().writeAll("\x1b[2K\r") catch {};
|
||||
}
|
||||
|
||||
const scope_prefix = if (opts.log_pfx) |lpfx|
|
||||
if (scope != .default)
|
||||
"[" ++ lpfx ++ " " ++ @tagName(scope) ++ "] "
|
||||
else
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const common = @import("common");
|
||||
const c = ffi.c;
|
||||
|
||||
const ffi = @import("ffi.zig");
|
||||
|
@ -6,10 +7,13 @@ const util = @import("util.zig");
|
|||
|
||||
pub const std_options = std.Options{
|
||||
.log_level = .debug,
|
||||
.logFn = @import("common").logFn,
|
||||
.logFn = common.logFn,
|
||||
};
|
||||
|
||||
pub const mztecommon_log_pfx = "mzte-mpv";
|
||||
pub const mztecommon_opts = common.Opts{
|
||||
.log_pfx = "mzte-mpv",
|
||||
.log_clear_line = true,
|
||||
};
|
||||
|
||||
export fn mpv_open_cplugin(handle: *c.mpv_handle) callconv(.C) c_int {
|
||||
tryMain(handle) catch |e| {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const common = @import("common");
|
||||
const opts = @import("opts");
|
||||
|
||||
const init = @import("init.zig").init;
|
||||
|
@ -11,7 +12,9 @@ pub const std_options = std.Options{
|
|||
.logFn = @import("common").logFn,
|
||||
};
|
||||
|
||||
pub const mztecommon_log_pfx = "mzteriver";
|
||||
pub const mztecommon_opts = common.Opts{
|
||||
.log_pfx = "mzteriver",
|
||||
};
|
||||
|
||||
pub fn main() !void {
|
||||
var dbg_gpa = if (@import("builtin").mode == .Debug) std.heap.GeneralPurposeAllocator(.{}){} else {};
|
||||
|
|
Loading…
Reference in a new issue