feat: list files as color coded lines and hide unused table columns

This commit is contained in:
randogoth 2026-10-25 10:14:11 +02:00
parent 98044782e5
commit d2e43e7839
4 changed files with 92 additions and 73 deletions

View file

@ -11,7 +11,10 @@ from orvanitag.cmd import main
def otag(tmp_path, monkeypatch, capsys):
monkeypatch.chdir(tmp_path)
def run(*argv):
def run(*argv, tty=False):
if tty: # capsys swaps sys.stdout in only once the test runs, so it is patched here
monkeypatch.setattr(sys.stdout, 'isatty', lambda: True)
monkeypatch.setenv('TERM', 'dumb') # no ANSI styles
monkeypatch.setattr(sys, 'argv', ['otag', *argv])
main()
return capsys.readouterr().out
@ -117,3 +120,32 @@ def test_piped_list_prints_bare_paths(otag, tmp_path):
assert otag('ls', '--files') == 'sub/a long name that a table would wrap.mp3\n'
assert otag('ls', '-d') == 'sub\n'
assert otag('ls', '#none') == ''
def test_list_prints_otag_lines(otag, tmp_path):
(tmp_path / 'a.mp3').touch()
(tmp_path / 'sub').mkdir()
otag('a', 'a.mp3', '#lofi', '+album', 'first', ':take:', '2')
otag('a', 'sub', '@archive')
assert otag('ls', tty=True) == 'a.mp3 --- +album #lofi first :take: 2\nsub/ --- @archive\n'
def test_table_shows_only_used_categories(otag, tmp_path):
(tmp_path / 'a.mp3').touch()
otag('a', 'a.mp3', '#lofi')
out = otag('ls', '-t', tty=True)
assert 'Tags' in out and '#lofi' in out
assert not any(header in out for header in ['Projects', 'Contexts', 'Note'])
def test_piped_table_prints_bare_paths(otag, tmp_path):
(tmp_path / 'a.mp3').touch()
otag('a', 'a.mp3', '#lofi')
assert otag('ls', '-t') == 'a.mp3\n'
def test_list_without_results(otag, tmp_path):
(tmp_path / 'a.mp3').touch()
otag('a', 'a.mp3', '#lofi')
assert 'No results found for #none' in otag('ls', '#none', tty=True)
assert 'No results found' in otag('ls', '-d', tty=True)

View file

@ -175,7 +175,7 @@ def test_cmd_user_errors_exit_with_1(cwd, monkeypatch, capsys):
def test_cmd_list_shows_square_brackets(cwd, monkeypatch, capsys):
(cwd / 'a [demo].mp3').touch()
OrvaniTag().add('a [demo].mp3', '#lofi', 'note', '[with]', 'brackets')
monkeypatch.setattr(sys.stdout, 'isatty', lambda: True) # the table, not piped output
monkeypatch.setattr(sys.stdout, 'isatty', lambda: True) # terminal output, not piped paths
monkeypatch.setattr(sys, 'argv', ['otag', 'ls', '#lofi'])
main()
out = capsys.readouterr().out