mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
update and fix python plugin example (#6633)
* update and fix python plugin example * update comment
This commit is contained in:
parent
23bba9935f
commit
d2e4f03d19
1 changed files with 12 additions and 4 deletions
|
@ -1,12 +1,12 @@
|
||||||
# Example of using a Python script as a Nushell plugin
|
# Example of using a Python script as a Nushell plugin
|
||||||
#
|
#
|
||||||
# The example uses JSON encoding but it should be a similar process using
|
# 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
|
# msgpack 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
|
# would be that you need to use msgpack relative lib(like msgpack) to
|
||||||
# that decode and encode information that is read and written to stdin and stdout
|
# decode and encode information that is read and written to stdin and stdout
|
||||||
#
|
#
|
||||||
# To register the plugin use:
|
# To register the plugin use:
|
||||||
# register <path-to-py-file> -e json
|
# register <path-to-py-file>
|
||||||
#
|
#
|
||||||
# Be carefull with the spans. Miette will crash if a span is outside the
|
# 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
|
# 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():
|
def plugin():
|
||||||
|
tell_nushell_encoding()
|
||||||
call_str = ",".join(sys.stdin.readlines())
|
call_str = ",".join(sys.stdin.readlines())
|
||||||
plugin_call = json.loads(call_str)
|
plugin_call = json.loads(call_str)
|
||||||
|
|
Loading…
Reference in a new issue