8000 WIP: py-terminal plugin by antocuni · Pull Request #1771 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

WIP: py-terminal plugin #1771

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

Closed
wants to merge 13 commits into from
Closed

WIP: py-terminal plugin #1771

wants to merge 13 commits into from

Conversation

antocuni
Copy link
Contributor

WIP

import { hooks } from "../core.js";

// XXX TODO:
// 1. these imports should be lazy?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { Terminal } = await import(/* webpackIgnore: true */ "https://cdn.jsdelivr.net/npm/xterm@5.3.0/+esm");
const { Readline } = await import(/* webpackIgnore: true */ "https://cdn.jsdelivr.net/npm/xterm-readline@1.1.1/+esm");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top level await should work out of the box, this file is lazily imported anyway ... we could also decide to install these as peer dependencies or something and let the bundler bring in everything we need?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also decide to install these as peer dependencies or something and let the bundler bring in everything we need?

I don't have any strong opinion about that is the best way to go, happy to do whatever you think it's best


// XXX TODO:
// 1. these imports should be lazy?
// 2. would be nice to automatically add xterm.css on demand
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can grab its content and append it on document.head ... as long as the document is the right one (see workers).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of dynamically adding a <link> element.

we can grab its content and append it on document.head

is there any advantage in doing this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the concept is the same, we add dynamically a tag or its content to the document.head and my "we can grab its content" was poorly worded: anyway we want to do so works, we still need to grab its content and append to the document.head either as link or style ... that's not what I was after, rather the fact in worker cases only we need that exsting or proxied document and add the style content in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the other hand, the link coudl be likely be added out of the box from main, no need to branch logic for workers cases only.

console.log("hello onInterpreterReady");
const t = makePyTerminal();
if (!t) {
console.log("<py-terminal> not found, nothing to do");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console warn maybe? if we enable this by default the bootstrap time will definitively increase (and in such case it should be a console.debug not a log) while if this is an explicit opt-in I would expect actually a console.warn instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, these are just for development/debugging, they should probably just go away

@@ -0,0 +1,110 @@
// PyScript py-terminal plugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be called py-terminal.js instead? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point 👍

@antocuni antocuni force-pushed the antocuni/py-terminal branch from 86bb287 to 89c2124 Compare September 29, 2023 13:04
@antocuni
Copy link
Contributor Author
antocuni commented Sep 29, 2023

this is still very very WIP and needs to be polished, but it's working enough to allow code.interact() to work:

<script type="py" worker>
import sys
from pyscript import display
display("Hello", "PyScript Next", append=False)
print("this should go to the terminal")
print("another line")
# XXX we have a problem with the error plugin: this line should
# just go to the terminal, NOT to the red box in the DOM
print("this goes to stderr", file=sys.stderr)
import code
code.interact()
</script>
<py-terminal></py-terminal>

image

@WebReflection
Copy link
Contributor

AFAIK this is a blocker for the next release, see #1786

I wonder if the WIP state should hint it's too early to keep reviewing this but if that's not the case please let me know so I can go through the code (I've seen a few pushes since last time I've checked) and hopefully help moving forward.

As side note, if there is any particular blocker please either file an issue per each blocker (or a discussion if you feel like that's needed) so that we can track side-issues/blockers around this plugin, thank you!

@WebReflection WebReflection mentioned this pull request Oct 12, 2023
3 tasks
@WebReflection
Copy link
Contributor

I think this MR took over this WIP so, for clean-up duty sake, I'll just remove it from the pending MR. I hope that's OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0