phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

REPL/CLI/Interactive Console

Open jasonm23 opened this issue 9 years ago • 25 comments
trafficstars

It would be nice if there was a REPL/CLI/Interactive Console to assist people who are getting to grips with the api.

Any feelings about this? @kasper

jasonm23 avatar Nov 27 '15 13:11 jasonm23

Definitely an interesting idea! I’m not sure how hard or easy this would be to implement...

kasper avatar Nov 27 '15 13:11 kasper

I'd like to have a crack at it, hopefully I'll have some time this weekend.

jasonm23 avatar Nov 27 '15 13:11 jasonm23

Ok, nice! Let me know what you discover.

kasper avatar Nov 27 '15 14:11 kasper

This will probably require a completely different CLI-binary and creating a new context that can read from the standard input and write to the standard output interactively. This would obviously mean splitting the core into a separate framework to avoid duplicated code. I would guess implementing this would need quit a bit of work.

kasper avatar Nov 28 '15 18:11 kasper

I was thinking this might be do-able using a socket, didn't get time over the last couple of weekends, hopefully the christmas period will gift me some spare time ;)

jasonm23 avatar Dec 07 '15 02:12 jasonm23

i think react native uses a socket to chrome web dev tools for this sort of thing.

tjbo avatar Apr 04 '16 03:04 tjbo

Amazing idea, when I use awesome in Linux, I love the console.

alswl avatar Apr 04 '16 16:04 alswl

Just wanted to chime in and say that I implemented a REPL as a modal, if anyone is interested:

https://github.com/metakirby5/.dots/blob/master/osx/.phoenix.js#L1046

Usage

metakirby5 avatar Nov 19 '16 23:11 metakirby5

I think I’ll add a small socket server to Phoenix that will listen and consume data as a stream. It can then evaluate that into the current context and return the last value generated. Then, I can write a small bash script and include it in the app bundle that will act as an interactive console client.

This should also make #140 possible.

kasper avatar Nov 26 '16 16:11 kasper

I just updated to 2.6.1 and noticed that the Phoenix JSContext is picked up by the web inspector now:

screen shot 2018-04-09 at 9 41 08

This is basiically a REPL :). The only reason I noticed it is that I have the option set to automatically launch them:

screen shot 2018-04-09 at 9 43 29

Maybe this could be used or improved? For example, I noticed my config isn't available in the inspector.

Then again, maybe not suitable as an official REPL since it requires enabling Safari developer options, etc.

mafredri avatar Apr 09 '18 06:04 mafredri

I noticed that too, but for some reason I was only able to get it to show up in debug builds. I was thinking of writing a Wiki page about it, if I could get it working properly.

kasper avatar Apr 09 '18 07:04 kasper

Interesting, I just pulled in mine from brew cask and it popped up 😅.

mafredri avatar Apr 09 '18 07:04 mafredri

Maybe it was just conflicting since I had the older release build running or then something has been fixed in the newer app bundle and it only works in 2.6.1. 😄

kasper avatar Apr 09 '18 07:04 kasper

Yes, it indeed seems to work out of the box with 2.6.1! 🎉

kasper avatar Apr 09 '18 10:04 kasper

Super sweet!

I now noticed that the reason I can't access my config is because I use webpack, so everything has it's own scope. But I can enter debugger; statements in my code and have Phoenix pause there, pretty neat!

One thing missing is being able to view the config as a source file though. And it would be super awesome to get source maps working. If you have any ideas I'm all ears, otherwise I might try to hack around a bit this weekend 😄.

PS. Do you think there might be any security implications from always exposing the context, considering that Phoenix has accessibility access, etc?

mafredri avatar Apr 09 '18 13:04 mafredri

@jasonm23 Congratulations, phoenix is on Github trending today.

image

alswl avatar Apr 09 '18 14:04 alswl

Wrote a short tutorial in the Wiki about how to use the Web Inspector to debug Phoenix. https://github.com/kasper/phoenix/wiki/Attaching-to-Web-Inspector-for-Debugging/

kasper avatar Apr 15 '18 11:04 kasper

I was trying to do this today, but after building and running the Debug release from source, I only see this in Safari > Develop > machine-name ...

Screenshot 2022-07-11 at 08 49 46

I've tried:

  • start Safari first
  • start Phoenix.app (debug) first
  • restart macos

Is there anything I need to do?

jasonm23 avatar Jul 11 '22 01:07 jasonm23

@jasonm23 Ah, I think I forgot to add com.apple.security.get-task-allow to the debug entitlements (https://github.com/kasper/phoenix/blob/master/Phoenix/PhoenixDebug.entitlements) when I was refactoring. That needs to be fixed. Good catch!

kasper avatar Jul 11 '22 06:07 kasper

Cool I'll try adding it locally to get moving

jasonm23 avatar Jul 11 '22 06:07 jasonm23

My debug entitlements now look like this...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.cs.disable-library-validation</key>
	<true/>
	<key>com.apple.security.get-task-allow</key>
	<true/>
</dict>
</plist>

Am I doing it right? Safari still doesn't see JSContext

jasonm23 avatar Jul 11 '22 09:07 jasonm23

@jasonm23 It should be right, maybe Apple has introduced some other entitlements as well? 🤔 I need to test it out.

kasper avatar Jul 11 '22 12:07 kasper

Thank you

jasonm23 avatar Jul 11 '22 16:07 jasonm23

I'll try rebooting.. https://developer.apple.com/forums/thread/67689

jasonm23 avatar Jul 11 '22 16:07 jasonm23

Got some downtime, reboot didn't fix anything :(

jasonm23 avatar Jul 13 '22 03:07 jasonm23