axiros / terminal_markdown_viewer

Styled Terminal Markdown Viewer
Other
1.8k stars 105 forks source link

monitor mode is may be broken #93

Closed derVedro closed 3 years ago

derVedro commented 3 years ago

If I try something like: $ mdv -M "notes:md::open '__fp__'" I get a KeyError:

`Traceback (most recent call last):
  File "/home/me/.local/bin/mdv", line 8, in <module>
    sys.exit(run())
  File "/home/me/.local/lib/python3.8/site-packages/mdv/markdownviewer.py", line 1655, in run
    monitor_dir(kw)
  File "/home/me/.local/lib/python3.8/site-packages/mdv/markdownviewer.py", line 1519, in monitor_dir
    args.pop("monitor_file")
KeyError: 'monitor_file'

May be I am doing something wrong cause I missunderstud the -M option.

axgkl commented 3 years ago

confirmed - ty, fixed in 435b6885d0237fe10a9f894375b10c1103bfaae0

derVedro commented 3 years ago

Thank you for the fix, but it's possible that something else is broken too.

First let me explain, what I am doing and then how. So may be I am doing something wrong and that's the issue. I have a directory notes with some markdown files. I edit them and I want to render them instantly in some terminal window as I save them. So I use that -M option. I don't really understand the command syntax, so far as I get it from the code and readme, it's something like "PATH : EXTENSIONS :: COMMAND 'MAGIC_PLACEHOLDER'".

Now the issue, If I run the latest version mdv with your fix (I just replaced the mdv directory of the pip installed version with github code), I still get trouble. So let assume I have two simple md files in /tmp/notes - first.md and second.md, and I run mdv like that:

$ mdv -M "/tmp/notes:md::open '__fp__'"

SOME HEADER FROM SECOND.MD

(/tmp/notes/second.md)
Running open '_"/tmp/notes/second.md"_'
Traceback (most recent call last):
  File "/home/me/.local/bin/mdv", line 8, in <module>
    sys.exit(run())
  File "/home/me/.local/lib/python3.8/site-packages/mdv/markdownviewer.py", line 1674, in run
    monitor_dir(kw)
  File "/home/me/.local/lib/python3.8/site-packages/mdv/markdownviewer.py", line 1600, in monitor_dir
    show_fp(fp)
  File "/home/me/.local/lib/python3.8/site-packages/mdv/markdownviewer.py", line 1529, in show_fp
    run_changed_file_cmd(cmd, fp=fp, pretty=pretty)
  File "/home/me/.local/lib/python3.8/site-packages/mdv/markdownviewer.py", line 1512, in run_changed_file_cmd
    cmd = cmd.replace(r, what.encode("base64"))
LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs