|
|
@ -1,6 +1,15 @@ |
|
|
|
#!/usr/bin/python3 |
|
|
|
|
|
|
|
import sys |
|
|
|
import fileinput |
|
|
|
|
|
|
|
try: |
|
|
|
import vim |
|
|
|
DEBUG = vim.eval("g:VimCheckmark_DebugMode") |
|
|
|
except ModuleNotFoundError: |
|
|
|
import os |
|
|
|
DEBUG = os.environ.get("CHECKMARK_DEBUG") |
|
|
|
if not DEBUG: |
|
|
|
raise NotImplementedError("this library only works inside vim!") |
|
|
|
|
|
|
|
from rich.markdown import Markdown |
|
|
|
from textual import events |
|
|
@ -13,25 +22,24 @@ class VimCheckmark(App): |
|
|
|
|
|
|
|
async def on_load(self) -> None: |
|
|
|
"""set up""" |
|
|
|
try: |
|
|
|
self.path = sys.argv[-1] |
|
|
|
except IndexError: |
|
|
|
raise() |
|
|
|
# self.path = "STDIN" |
|
|
|
# |
|
|
|
# if self.path == "STDIN": |
|
|
|
# for line in fileinput.input(): |
|
|
|
await self.bind("q", "quit", "Quit") |
|
|
|
|
|
|
|
async def on_mount(self, event: events.Mount) -> None: |
|
|
|
"""handle rendering""" |
|
|
|
body = ScrollView(gutter=1) |
|
|
|
await self.view.dock(body) |
|
|
|
|
|
|
|
with open(self.path, 'rb') as fh: |
|
|
|
output = Markdown(fh.read(), hyperlinks=True) |
|
|
|
text = '' |
|
|
|
with fileinput.input() as fh: |
|
|
|
for line in fh: |
|
|
|
text = text + line + "\n" |
|
|
|
output = Markdown(text, hyperlinks=True) |
|
|
|
await body.update(output) |
|
|
|
|
|
|
|
|
|
|
|
def main() -> None: |
|
|
|
"""simple container func""" |
|
|
|
def checkmark() -> None: |
|
|
|
VimCheckmark.run() |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
VimCheckmark.run() |