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

Lua Debug Terminal #641

Closed
gwww opened this issue Apr 4, 2021 · 4 comments
Closed

Lua Debug Terminal #641

gwww opened this issue Apr 4, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@gwww
Copy link
Contributor

gwww commented Apr 4, 2021

Is your feature request related to a problem? Please describe.
In order to learn about the API having a playground to test things out would be helpful. It would allow tweaking the running in-memory configuration to try out ideas.

Describe the solution you'd like
The basic idea is that a new window (or tab??) pops up that allows you to type in Lua and see the results. The context would be with the running configuration, globals, etc. All print statements would display in the debug terminal. A bonus is that all log messages would show up there too.

Any Lua statements would affect the current running config if they are applicable.

I don't yet understand domains but my guess is a DebugDomain concept might apply.

Hammerspoon (also Lua-based config) has a concept similar to what I'm proposed with the
toggleConsole command.

Screen Shot 2021-04-04 at 14 39 24

Describe alternatives you've considered
I thought about having a modifying SendString that might accomplish the purpose but that does not seem like a right solution as it would not be "powerful" enough.

@gwww gwww added the enhancement New feature or request label Apr 4, 2021
wez added a commit that referenced this issue May 3, 2021
Adds a `ShowDebugOverlay` key assignment that will create a tab
overlay that shows a limited number of recently logged events.

refs: #641
wez added a commit that referenced this issue May 3, 2021
`wezterm` is pre-imported.
The repl prints the result of the expressions to the overlay.

refs: #641
wez added a commit that referenced this issue May 3, 2021
Make print equivalent to log_info.
Improve the various log functions so that all of their arguments
are considered.

refs: #641
@wez
Copy link
Owner

wez commented May 3, 2021

There's now a basic implementation of this in main; a debug overlay can be activated and shown over the top of the current tab.
Pressing escape (when the prompt line is empty) will cancel the overlay.
Typing in lines of lua code will evaluate that code and print the return value of that expression.

I've bound {key="l", mods="SHIFT|CTRL", action="ShowDebugOverlay"}, to trigger the debug overlay in my local config.

Any state changed in the lua context in that overlay is local to that overlay. The lua context has wezterm pre-imported, but doesn't yet have access to the window, so it's not possible to effect any real changes from this context at this time.

One thing to note about this is that it won't be possible to directly define event handlers using wezterm.on in this repl, because those events need to be accessible via the main config on the main thread and this repl environment cannot access that context.

However, once window and some functions that expose info about the rest of the mux model are present, it should be useful as a way to inspect and prototype the more imperative things. For example, this demonstrates playing around with the colors in format and quickly seeing the results:

image

wez added a commit that referenced this issue May 4, 2021
@gwww
Copy link
Contributor Author

gwww commented May 4, 2021

Thanks for this!!! You are rocking!!

A couple of things I noticed to start. SHIFT+CTRL+L cleared my screen rather than invoking the debug overlay. When I
added it to my key mappings it worked fine.

It was aggressive in parsing. I typed a= and got an syntax error before I could complete the a=1.

I haven't tried much else yet, and, I know this is early code. Pretty cool though! And it didn't seem to be much code when I browsed the commit.

@wez
Copy link
Owner

wez commented May 5, 2021

When I added it to my key mappings it worked fine.

Yeah, I haven't added a default key assignment for this yet.

It was aggressive in parsing

Yeah, the line under the line editor shows a "preview" of the parse status. It parses but does not execute the code until you hit enter!

wez added a commit that referenced this issue May 31, 2021
@wez wez closed this as completed in 2309799 Aug 9, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants