From d2e4f03d194361676e406717eeb7a7eeafb28b1f Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Thu, 29 Sep 2022 06:06:43 +0800 Subject: [PATCH] update and fix python plugin example (#6633) * update and fix python plugin example * update comment --- .../{plugin.py => nu_plugin_python_example.py} | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) rename crates/nu_plugin_python/{plugin.py => nu_plugin_python_example.py} (97%) diff --git a/crates/nu_plugin_python/plugin.py b/crates/nu_plugin_python/nu_plugin_python_example.py similarity index 97% rename from crates/nu_plugin_python/plugin.py rename to crates/nu_plugin_python/nu_plugin_python_example.py index 223a53bb30..32d0e8a870 100644 --- a/crates/nu_plugin_python/plugin.py +++ b/crates/nu_plugin_python/nu_plugin_python_example.py @@ -1,12 +1,12 @@ # Example of using a Python script as a Nushell plugin # # The example uses JSON encoding but it should be a similar process using -# Cap'n Proto to move data between Nushell and the plugin. The only difference -# would be that you need to compile the schema file in order have the objects -# that decode and encode information that is read and written to stdin and stdout +# msgpack to move data between Nushell and the plugin. The only difference +# would be that you need to use msgpack relative lib(like msgpack) to +# decode and encode information that is read and written to stdin and stdout # # To register the plugin use: -# register -e json +# register # # Be carefull with the spans. Miette will crash if a span is outside the # size of the contents vector. For this example we are using 0 and 1, which will @@ -392,7 +392,15 @@ def process_call(plugin_call): } +def tell_nushell_encoding(): + sys.stdout.write(chr(4)) + for ch in "json": + sys.stdout.write(chr(ord(ch))) + sys.stdout.flush() + + def plugin(): + tell_nushell_encoding() call_str = ",".join(sys.stdin.readlines()) plugin_call = json.loads(call_str)