Skip to content

Commit

Permalink
fopen: add flag -q to suppress stdout from external command
Browse files Browse the repository at this point in the history
pass twice to also suppress stderr
  • Loading branch information
rsekman committed Apr 11, 2022
1 parent de4e2dd commit 882fde4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions stig/commands/base/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import asyncio

from subprocess import Popen, DEVNULL, PIPE
from threading import Thread
from time import sleep

from . import _mixin as mixin
from .. import CmdError, CommandMeta
Expand Down Expand Up @@ -183,18 +181,21 @@ class FOpenCmdbase(metaclass=CommandMeta):
'fileopen "that torrent" *.mkv mpv'
'fileopen "that torrent" *.mkv mpv --fullscreen',)
argspecs = (
{'names': ('--quiet', '-q'),
'description': 'Suppress stdout from the external command. Pass twice to also suppress stderr',
'action': 'count', 'default': 0},
make_X_FILTER_spec('TORRENT', or_focused=True, nargs='?'),
make_X_FILTER_spec('FILE', or_focused=True, nargs='?'),
{"names": ('COMMAND',),
'description': "Command to use to open files. Default: xdg-open",
{'names': ('COMMAND',),
'description': 'Command to use to open files. Default: xdg-open',
'nargs': '?'
},
{"names": ('OPTS',),
{'names': ('OPTS',),
'description': "Options for the external command.",
'nargs': 'REMAINDER'
},
)
async def run(self, TORRENT_FILTER, FILE_FILTER, COMMAND, OPTS):
async def run(self, quiet, TORRENT_FILTER, FILE_FILTER, COMMAND, OPTS):
default_command = 'xdg-open'
if COMMAND is None:
command = default_command
Expand Down Expand Up @@ -244,7 +245,11 @@ def closepipes(proc):

# TODO separate options for stdout/stderr
stdoutlogger = lambda s: self.info(command + ": " + s)
if quiet >= 1:
stdoutlogger = lambda s: None
stderrlogger = lambda s: self.error(command + ": " + s)
if quiet >= 2:
stderrlogger = lambda s: None
loop = asyncio.get_running_loop()
try:
if command == default_command:
Expand Down
4 changes: 2 additions & 2 deletions stig/commands/tui/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ class FOpenCmd(base.FOpenCmdbase, mixin.make_request, mixin.select_torrents, mix
# When files are selected in the tui, the two first arguments, the torrent
# and the file(s) need to be filled in. That is, `fopen mpv` should mean
# `fopen torrent file mpv`
async def run(self, COMMAND, TORRENT_FILTER, FILE_FILTER, OPTS):
await base.FOpenCmdbase.run(self, TORRENT_FILTER=COMMAND, FILE_FILTER=FILE_FILTER, COMMAND=TORRENT_FILTER, OPTS=OPTS)
async def run(self, quiet, COMMAND, TORRENT_FILTER, FILE_FILTER, OPTS):
await base.FOpenCmdbase.run(self, quiet, TORRENT_FILTER=COMMAND, FILE_FILTER=FILE_FILTER, COMMAND=TORRENT_FILTER, OPTS=OPTS)

0 comments on commit 882fde4

Please sign in to comment.