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=-2.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,URIBL_BLACK shortcircuit=no autolearn=no 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 4A7D91F5AE for ; Mon, 15 Jun 2020 00:24:44 +0000 (UTC) Received: from localhost ([::1]:42690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jkcvb-0002S0-3A for e@80x24.org; Sun, 14 Jun 2020 20:24:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkcvZ-0002Rp-Go for dtas-all@nongnu.org; Sun, 14 Jun 2020 20:24:41 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:35860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkcvX-0002aK-D7 for dtas-all@nongnu.org; Sun, 14 Jun 2020 20:24:41 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C50B61F5AE; Mon, 15 Jun 2020 00:24:34 +0000 (UTC) Date: Mon, 15 Jun 2020 00:24:34 +0000 From: Eric Wong To: dtas-all@nongnu.org Subject: Re: Line wrapping in YAML output Message-ID: <20200615002434.GA30135@dcvr> References: <20200613152543.owwp2ey3byvf2row@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200613152543.owwp2ey3byvf2row@gmail.com> Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/14 20:24:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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" James Rowe wrote: > Hi, > > I routinely find myself needing to use a “real language” when I want > to perform a quick hack with dtas purely to workaround the default line > wrapping in YAML output. With unwrapped output sed/awk would often be > a viable solution from the shell prompt. Understandable. Do you use dtas-ctl or some other socket tool? On the flip side, one of the reasons I picked YAML over JSON is the indented + wrapped-by-default nature made it $EDITOR-friendly. In retrospect, I kinda wish I'd gone with JSON for a wire format and maybe YAML or even RFC822 for $EDITOR-friendliness. > Given that psych supports an options mapping where setting > ``line_width: -1`` disables wrapping entirely, I’m wondering if there > would be support for disabling the line wrapping. I’m also wondering if > I’m missing some drawbacks to doing so. My patch below seems to work. The dtas-*edit tools had to be updated for $EDITOR-friendliness. dtas-ctl output could become difficult-to-read on the terminal; maybe it could detect stdout is a terminal and rewrap in that case. ------8<------ From: Eric Wong Subject: [PATCH] player: disable line wrapping in YAML socket output Introduce DTAS.yaml wrapper to consistently disable line wrapping in player output. To keep dtas-*edit commands from having excessively long lines, we'll re-wrap them before spawning text editors. --- bin/dtas-sinkedit | 1 + bin/dtas-sourceedit | 1 + lib/dtas.rb | 4 ++++ lib/dtas/player.rb | 2 +- lib/dtas/player/client_handler.rb | 16 ++++++++-------- lib/dtas/state_file.rb | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/dtas-sinkedit b/bin/dtas-sinkedit index 3393aac..16ece0b 100755 --- a/bin/dtas-sinkedit +++ b/bin/dtas-sinkedit @@ -70,6 +70,7 @@ else include DTAS::SpawnFix tmp = tmpyaml + buf = orig.to_yaml # re-enable line wrapping tmp_path = tmp.path do_update = lambda { commit_update.call(File.read(tmp_path)) } tmp.write(buf << DTAS_DISCLAIMER) diff --git a/bin/dtas-sourceedit b/bin/dtas-sourceedit index 23362c2..2e9dd57 100755 --- a/bin/dtas-sourceedit +++ b/bin/dtas-sourceedit @@ -57,6 +57,7 @@ else include DTAS::SpawnFix tmp = tmpyaml + buf = orig.to_yaml # re-enable line wrapping tmp_path = tmp.path do_update = lambda { commit_update.call(File.read(tmp_path)) } tmp.write(buf << DTAS_DISCLAIMER) diff --git a/lib/dtas.rb b/lib/dtas.rb index 1eac704..23d5ea4 100644 --- a/lib/dtas.rb +++ b/lib/dtas.rb @@ -33,6 +33,10 @@ def self.libc end end + def self.yaml(obj) + obj.to_yaml(line_width: -1) # disable wrapping + end + # String#-@ will deduplicate strings when Ruby 2.5 is released (Dec 2017) # https://bugs.ruby-lang.org/issues/13077 if RUBY_VERSION.to_f >= 2.5 diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb index b39a2e7..f21b6a0 100644 --- a/lib/dtas/player.rb +++ b/lib/dtas/player.rb @@ -228,7 +228,7 @@ def dpc_clear(io, msg) end def dpc_queue(io, msg) - 'cat' == msg[0] and io.emit(@queue.to_yaml) + 'cat' == msg[0] and io.emit(DTAS.yaml(@queue)) end def dpc_watch(io, _) diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index cf5442d..c11ed69 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -176,7 +176,7 @@ def dpc_sink(io, msg) io.emit("OK") when "cat" sink = @sinks[name] or return io.emit("ERR #{name} not found") - io.emit(sink.to_hash.to_yaml) + io.emit(DTAS.yaml(sink.to_hash)) else io.emit("ERR unknown sink op #{msg[0]}") end @@ -259,7 +259,7 @@ def current_expect_samples(in_samples) # @current.samples end def dpc_rg(io, msg) - return io.emit(@rg.to_hsh.to_yaml) if msg.empty? + return io.emit(DTAS.yaml(@rg.to_hsh)) if msg.empty? before = @rg.to_hsh msg.each do |kv| k, v = kv.split('=', 2) @@ -333,7 +333,7 @@ def dpc_current(io, msg) end end tmp['tracklist'] = @tl.to_hsh(false) - io.emit(tmp.to_yaml) + io.emit(DTAS.yaml(tmp)) end def __buf_reset(buf) # buf is always @sink_buf for now @@ -351,12 +351,12 @@ def dpc_skip(io, msg) def play_pause_handler(io, command) prev = @paused __send__("do_#{command}") - io.emit({ + io.emit(DTAS.yaml({ "paused" => { "before" => prev, "after" => @paused, } - }.to_yaml) + })) end def do_pause @@ -515,7 +515,7 @@ def dpc_source(io, msg) src = map[name] or return io.emit("ERR non-existent source name") case op when "cat" - io.emit(src.to_source_cat.to_yaml) + io.emit(DTAS.yaml(src.to_source_cat)) when "ed" before = src.to_state_hash.inspect sd = src.source_defaults @@ -642,7 +642,7 @@ def _dpc_tl_shuffle(io, msg) prev = (!!@tl.shuffle).to_s v = msg.shift case v - when 'debug' then return io.emit(@tl.shuffle.to_yaml) # TODO: remove + when 'debug' then return io.emit(DTAS.yaml(@tl.shuffle)) # TODO: remove when nil else set_bool(io, 'tl shuffle', v) do |b| @@ -844,7 +844,7 @@ def dpc_cue(io, msg) case msg[0] when nil tmp = { "infile" => cur.infile, "cue" => bp.map(&:to_hash) } - io.emit(tmp.to_yaml) + io.emit(DTAS.yaml(tmp)) when "next", "prev" return __bp_prev_next(io, msg, cur, bp) when 'seek' then return __bp_seek(io, msg, cur, bp) diff --git a/lib/dtas/state_file.rb b/lib/dtas/state_file.rb index eac3e2f..8d7d413 100644 --- a/lib/dtas/state_file.rb +++ b/lib/dtas/state_file.rb @@ -18,7 +18,7 @@ def tryload end def dump(obj, force_fsync = false) - yaml = obj.to_hsh.to_yaml.b + yaml = DTAS.yaml(obj.to_hsh).b # do not replace existing state file if there are no changes # this will be racy if we ever do async dumps or shared state