Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate into pyvim #34

Closed
clach04 opened this issue Mar 11, 2023 · 6 comments
Closed

integrate into pyvim #34

clach04 opened this issue Mar 11, 2023 · 6 comments
Labels
early-access early access code available enhancement New feature or request in-progress Code is in progress

Comments

@clach04
Copy link
Owner

clach04 commented Mar 11, 2023

https://github.com/prompt-toolkit/pyvim

Semi related to #22

  1. ptpyvim; See if can import pyvim and monkey patch file IO, ideally with note tree API (rather than cypher API so as to allow future use of virtual file system).
  2. write a pyvim io backend, https://github.com/prompt-toolkit/pyvim/blob/master/pyvim/io/backends.py (also see 1 above).

Also see alternatives https://github.com/prompt-toolkit/pyvim#alternatives
#35

load from command line seems fine, as does saving.

Prompting for password experiments ONLY work when loading from command line (pre "gui" init?). Get coroutine errors (that are garbled):

    diff --git a/puren_tonbo/tools/ptpyvim.py b/puren_tonbo/tools/ptpyvim.py
    index cc386f0..aed8444 100644
    --- a/puren_tonbo/tools/ptpyvim.py
    +++ b/puren_tonbo/tools/ptpyvim.py
    @@ -21,6 +21,10 @@ from pyvim.io import FileIO, DirectoryIO, HttpIO, GZipFileIO
     from pyvim.io.backends import ENCODINGS, _auto_decode
     from pyvim.io import EditorIO

    +from prompt_toolkit import prompt
    +from prompt_toolkit.shortcuts import input_dialog
    +
    +
     import puren_tonbo


    @@ -87,8 +91,25 @@ class PureTonboFileIO(EditorIO):
             Read/decrypt file from disk.
             """
             #import web_pdb; web_pdb.set_trace()  # https://github.com/romanvm/python-web-pdb
    -        if not password:
    -            raise puren_tonbo.BadPassword('Missing password, set OS env PT_PASSWORD')
    +        global password
    +        while not password:
    +            #password = prompt('Enter password: ', is_password=True)
    +            password = input_dialog(
    +                title="Password dialog example",
    +                text="Please type your password:",
    +                password=True,
    +            ).run()
    +            #raise puren_tonbo.BadPassword('Missing password, set OS env PT_PASSWORD')
    +            """ this code works fine from command line, but :edit ... causes....
    +
    +
    +            `:e filename.chi` (or any file supported by PT) fails with:
    +
    +                ...\site-packages\pyvim\editor_buffer.py:112: RuntimeWarning: coroutine 'Application.run_async' was never awaited
    +                Cannot read 'test.chi': RuntimeError('This event loop is already running')
    +                Rtest.cha   ng: Enable tracemal    to get the object allocation traceback
    +
    +            """
@clach04 clach04 added the enhancement New feature or request label Mar 11, 2023
@clach04
Copy link
Owner Author

clach04 commented Mar 11, 2023

Posted 6339cc7 to show possibilities.

@clach04
Copy link
Owner Author

clach04 commented Mar 11, 2023

Note some minor UX issues with pyvim:

Opened #46 with above

@clach04
Copy link
Owner Author

clach04 commented Mar 11, 2023

Not yet figured out how to add a prompt, but have figured out a hack to display a message to the screen from the io backend plugin:

diff --git a/puren_tonbo/tools/ptpyvim.py b/puren_tonbo/tools/ptpyvim.py
index 8ef30db..ae5f3f9 100644
--- a/puren_tonbo/tools/ptpyvim.py
+++ b/puren_tonbo/tools/ptpyvim.py
@@ -59,6 +59,9 @@ password = 'password'  # FIXME! debug hack for testing, bare minimum is pick up
 if not isinstance(password, bytes):
     password = password.encode('us-ascii')

+# Create new editor instance.
+editor = Editor()  # global hack!
+

 class PureTonboFileIO(EditorIO):
     """
@@ -85,6 +88,7 @@ class PureTonboFileIO(EditorIO):
         """
         Read/decrypt file from disk.
         """
+        editor.show_message('%s' % 'my messahe')
         location = os.path.expanduser(location)  # revisit this, future virtual file system support

         handler_class = puren_tonbo.filename2handler(location)
@@ -140,8 +144,10 @@ def main(argv=None):
     # TODO any argument processing?
     locations = argv[1:]

+    """
     # Create new editor instance.
     editor = Editor()
+    """

     # monkey patch PT support into Editor instance
     editor.io_backends = [

@clach04 clach04 added in-progress Code is in progress early-access early access code available labels Mar 12, 2023
@clach04
Copy link
Owner Author

clach04 commented Mar 26, 2023

For now password prompt done potentially by caller (e.g. ptig) or before opening files for view/edit in ptpyvim IF a filename that has been passed in requires encryption. ed6385a

@clach04
Copy link
Owner Author

clach04 commented Mar 26, 2023

Opened #46 for improvements, closing as initial integration is complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
early-access early access code available enhancement New feature or request in-progress Code is in progress
Projects
None yet
Development

No branches or pull requests

1 participant