Skip to content

Commit

Permalink
output mode log-file defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
last-arg committed Jan 14, 2021
1 parent 9d73a65 commit da4820e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub fn main() anyerror!void {
const path_fmt = "/v5/videos/{s}/comments?content_offset_seconds={d:.2}";

var output_mode: ui.UiMode = .stdout;
// output_mode = .notcurses;
var opt_log_file: []const u8 = "stdout";
output_mode = .notcurses;
var opt_log_file: ?[]const u8 = null;
var socket_path: []const u8 = "/tmp/mpv-twitch-socket";
var comments_delay: f32 = 0.0;

Expand Down Expand Up @@ -117,21 +117,20 @@ pub fn main() anyerror!void {
warn("Option '-log-file' requires path or `stdout` ", .{});
return;
};
if (std.mem.eql(u8, "stdout", value)) {
log_file_path = null;
} else {
log_file_path = value;
}
opt_log_file = value;
} else if (std.mem.eql(u8, "-help", arg) or std.mem.eql(u8, "-h", arg)) {
const help_text =
\\mpv-vod-chat [options]
\\
\\Options:
\\ -h, -help Print help text
\\ -socket-path Default: '/tmp/mpv-twitch-socket'. Set mpv players socket path
\\ -socket-path Default: '/tmp/mpv-twitch-socket'.
\\ Set mpv players socket path
\\ -comments-delay When comments are displayed compared to video time
\\ -output-mode Default: stdout. Can enter one three: stdout, direct, notcurses.
\\ -log-file Default: stdout. Can output application log messages to stdout, a file or tty.
\\ -output-mode Default: stdout. Can enter one of three: stdout, direct, notcurses.
\\ -log-file Default(output mode: stdout, direct): stdout.
\\ -log-file Default(output mode: notcurses): '/tmp/mpv-twitch-chat.log'.
\\ Can output application log messages to stdout, a file or tty.
\\
;

Expand All @@ -140,6 +139,20 @@ pub fn main() anyerror!void {
}
}

// Set log output place: stdout, file, tty
if (opt_log_file) |file| {
if (std.mem.eql(u8, "stdout", file)) {
log_file_path = null;
} else {
log_file_path = file;
}
} else {
switch (output_mode) {
.stdout, .direct => log_file_path = null,
.notcurses => log_file_path = "/tmp/mpv-twitch-chat.log",
}
}

var mpv = Mpv.init(allocator, socket_path) catch |err| {
warn("Failed to find mpv socket path: {s}\n", .{socket_path});
return err;
Expand Down
1 change: 1 addition & 0 deletions src/ui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub const UiNotCurses = struct {
}

pub fn sleepLoop(ui: *Ui, ns: u64) !void {
errdefer ui.deinit();
var self = @fieldParentPtr(Self, "ui", ui);
const input_inactive_ns = time.ns_per_ms * 120;
const input_active_ns = time.ns_per_ms * 60;
Expand Down
1 change: 1 addition & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Improve:

Bugs:
[ ] Ui (NotCurses) on unexpected crash cant see cursor after
[ ] When screen isn't filled with text scrolling works by moving text to bottom or top



Expand Down

0 comments on commit da4820e

Please sign in to comment.