bin/dtas-console in dtas-0.19.0 vs bin/dtas-console in dtas-0.20.0
- old
+ new
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
-# Copyright (C) 2013-2021 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
#
# Note: no idea what I'm doing, especially w.r.t. curses
require 'dtas'
@@ -9,33 +9,37 @@
require 'dtas/rg_state'
require 'dtas/sigevent'
require 'dtas/process'
require 'dtas/format'
include DTAS::Process
-require 'yaml'
begin
require 'curses'
rescue LoadError
abort "please install the 'curses' RubyGem to use #$0"
end
+# workaround https://bugs.debian.org/958973
+$VERBOSE = nil if RUBY_VERSION.to_f < 3.0
+
tsec = false
se = DTAS::Sigevent.new
trap(:WINCH) { se.signal }
w = DTAS::UNIXClient.new
w.req_ok('watch')
c = DTAS::UNIXClient.new
-cur = YAML.load(c.req('current'))
+cur = DTAS.yaml_load(c.req('current'))
readable = [ se, w, $stdin ]
+set_title = (ENV['DISPLAY'] || ENV['WAYLAND_DISPLAY']) ? $stdout : nil
# current rg mode
rg_mode = DTAS::RGState::RG_MODE.keys.unshift("off")
if (rg = cur["rg"]) && (rg = rg["mode"])
rg_mode_i = rg_mode.index(cur["rg"]["mode"])
else
rg_mode_i = 0
end
+show_info = false
def update_tfmt(prec, tsec)
if tsec
prec == 0 ? '%_8s' : "%_8s.%#{prec}N"
else
@@ -165,10 +169,14 @@
# FS encoding != locale encoding, but we need to display an FS path
# name to whatever locale the terminal is encoded to, so force it
# and risk mojibake...
infile.encode(enc_locale,
undef: :replace, invalid: :replace, replace: '?')
+ if set_title
+ dir, base = File.split(infile)
+ set_title.syswrite("\033]0;#{base} dtas-console\07")
+ end
Curses.setpos(lineno += 1, 0)
Curses.clrtoeol
Curses.addstr(infile)
total = " [#{Time.at(samples / rate).utc.strftime(tfmt)}]" if samples != 0
Curses.setpos(lineno += 1, 0)
@@ -201,10 +209,31 @@
trim = cur['trim'] || 'off'
extra << "trim=#{trim}"
Curses.addstr(extra.join(' '))
pre_mute_vol = cur_vol if cur_vol != 0
+ if show_info && current && comments = current['comments']
+ Curses.setpos(lineno += 1, 0)
+ Curses.clrtoeol
+ Curses.addstr('comments:')
+ comments.each do |k,v|
+ v = v.split(/\n+/)
+ k = k.dump if /[[:cntrl:]]/ =~ k
+ if first = v.shift
+ Curses.setpos(lineno += 1, 0)
+ Curses.clrtoeol
+ first = first.dump if /[[:cntrl:]]/ =~ first
+ Curses.addstr(" #{k}: #{first}")
+ v.each do |val|
+ val = val.dump if /[[:cntrl:]]/ =~ val
+ Curses.setpos(lineno += 1, 0)
+ Curses.clrtoeol
+ Curses.addstr(" #{val}")
+ end
+ end
+ end
+ end
show_events(lineno, screen, events)
Curses.refresh # draw and wait
r = IO.select(readable, nil, nil, current ? interval : nil) or next
r[0].each do |io|
@@ -222,11 +251,11 @@
when %r{\Afile }
end
events << "#{Time.now.strftime(tfmt)} #{event}"
# something happened, refresh current
# we could be more intelligent here, maybe, but too much work.
- cur = YAML.load(c.req('current'))
+ cur = DTAS.yaml_load(c.req('current'))
when $stdin
# keybindings taken from mplayer / vi
case key = Curses.getch
when "j" then may_fail(c, "seek -5", events)
when "k" then may_fail(c, "seek +5", events)
@@ -270,9 +299,12 @@
prec_nr += 1
tfmt = update_tfmt(prec_step[prec_nr], tsec)
interval = 1.0 / 10 ** prec_nr
end
when 27 # TODO readline/edit mode?
+ when 'i'
+ show_info = !show_info
+ Curses.clear if !show_info
else
Curses.setpos(screen.maxy - 1, 0)
Curses.clrtoeol
Curses.addstr("unknown key=#{key.inspect}")
end