-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move functionality into the grexd module. - Create the hugefileviewer infra that uses mmap and only reads the portion of the file that is on the screen. - works tmp
- Loading branch information
Showing
8 changed files
with
642 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
A visualizer for huge files | ||
This is mostly a test for the hugefileviewer prompt-toolkit widget and | ||
control. | ||
""" | ||
|
||
import argparse | ||
import logging | ||
import os | ||
|
||
import grexd | ||
from prompt_toolkit import Application | ||
from prompt_toolkit.key_binding import KeyBindings | ||
from prompt_toolkit.key_binding.key_processor import KeyPressEvent | ||
from prompt_toolkit.layout.containers import Container, Window | ||
from prompt_toolkit.layout.layout import Layout | ||
from prompt_toolkit.widgets import Frame | ||
|
||
E = KeyPressEvent | ||
|
||
|
||
class HugeFileViewerWidget: | ||
def __init__(self, filename: os.PathLike[str]): | ||
self.filename = filename | ||
with open(self.filename, "rb") as fd: | ||
self.control = grexd.HugeFileViewerUIControl(fd=fd) | ||
self.window = Window(self.control) | ||
|
||
def __pt_container__(self) -> Container: | ||
return self.window | ||
|
||
|
||
def hugefileviewer_run(filename: os.PathLike[str]) -> None: | ||
hugefileviewer = HugeFileViewerWidget(filename) | ||
root_container = Frame(title=str(filename), body=hugefileviewer) | ||
layout = Layout(root_container) | ||
kb = KeyBindings() | ||
app: Application[None] = Application( | ||
layout=layout, | ||
full_screen=True, | ||
key_bindings=kb, | ||
mouse_support=True, | ||
) | ||
kb.add("c-c")(lambda e: app.exit()) | ||
kb.add("c-d")(lambda e: app.exit()) | ||
kb.add("escape", "q")(lambda e: app.exit()) | ||
app.run() | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument( | ||
"--version", "-V", action="version", version="%(prog)s " + grexd.version() | ||
) | ||
parser.add_argument("file", type=str, nargs=1, help="File to view") | ||
args = parser.parse_args() | ||
logging.basicConfig(filename="log.txt", level=logging.INFO) | ||
hugefileviewer_run(args.file[0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.