From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 03D631F8C2 for ; Sat, 13 Feb 2021 21:34:35 +0000 (UTC) Received: from localhost ([::1]:53560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lB2Yk-0005AV-0G for e@80x24.org; Sat, 13 Feb 2021 16:34:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lB2Yi-0005AP-QI for dtas-all@nongnu.org; Sat, 13 Feb 2021 16:34:32 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:43224) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lB2Yg-0000do-W7 for dtas-all@nongnu.org; Sat, 13 Feb 2021 16:34:32 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 828991F8C2 for ; Sat, 13 Feb 2021 21:34:27 +0000 (UTC) From: Eric Wong To: dtas-all@nongnu.org Subject: [PATCH] dtas-console: gracefully handle seek failures Date: Sat, 13 Feb 2021 16:34:27 -0500 Message-Id: <20210213213427.24381-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" dtas-console doesn't need to quit when a user attempts to seek an unseekable file, since the user often doesn't know it's unseekable until a seek is attempted. --- bin/dtas-console | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bin/dtas-console b/bin/dtas-console index d7e1a23..0c56450 100755 --- a/bin/dtas-console +++ b/bin/dtas-console @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# Copyright (C) 2013-2020 all contributors +# Copyright (C) 2013-2021 all contributors # License: GPL-3.0+ # frozen_string_literal: true # @@ -112,7 +112,8 @@ def rg_string(rg, current) rv end -def may_fail(res, events) +def may_fail(c, req, events) + res = c.req(req) events << res if res != "OK" end @@ -227,17 +228,17 @@ def may_fail(res, events) when $stdin # keybindings taken from mplayer / vi case key = Curses.getch - when "j" then c.req_ok("seek -5") - when "k" then c.req_ok("seek +5") + when "j" then may_fail(c, "seek -5", events) + when "k" then may_fail(c, "seek +5", events) when "q" then exit(0) - when Curses::KEY_DOWN then c.req_ok("seek -60") - when Curses::KEY_UP then c.req_ok("seek +60") - when Curses::KEY_LEFT then c.req_ok("seek -10") - when Curses::KEY_RIGHT then c.req_ok("seek +10") - when Curses::KEY_BACKSPACE then c.req_ok("seek 0") + when Curses::KEY_DOWN then may_fail(c, "seek -60", events) + when Curses::KEY_UP then may_fail(c, "seek +60", events) + when Curses::KEY_LEFT then may_fail(c, "seek -10", events) + when Curses::KEY_RIGHT then may_fail(c, "seek +10", events) + when Curses::KEY_BACKSPACE then may_fail(c, "seek 0", events) # yes, some of us have long audio files - when Curses::KEY_PPAGE then c.req_ok("seek +600") - when Curses::KEY_NPAGE then c.req_ok("seek -600") + when Curses::KEY_PPAGE then may_fail(c, "seek +600", events) + when Curses::KEY_NPAGE then may_fail(c, "seek -600", events) when '9' then c.req_ok('rg volume-=0.01') when '0' then c.req_ok('rg volume+=0.01') when '=' then c.req_ok('rg volume=1') @@ -248,8 +249,8 @@ def may_fail(res, events) when "f" then c.req_ok("rg fallback_gain-=1") when ">" then c.req_ok("tl next") when "<" then c.req_ok("tl prev") - when "!" then may_fail(c.req("cue prev"), events) - when "@" then may_fail(c.req("cue next"), events) + when "!" then may_fail(c, "cue prev", events) + when "@" then may_fail(c, "cue next", events) when "o" then tfmt = update_tfmt(prec_step[prec_nr], tsec = !tsec) when " " c.req("play_pause")