pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.62k stars 518 forks source link

a console api #490

Open CapsAdmin opened 9 years ago

CapsAdmin commented 9 years ago

Currently there is a local console for zerobrane but I'd like to have a remote console for my own project without the need to duplicate the local console code.

At the moment I've copied the local console code and modified it slightly. The modifications are just changing the title, localizing some global functions so they don't conflict with the local console and added an event on line input and a way to print to the console.

On line input I send a tcp message to my project and my project sends console output to zerobrane. This works very well for me but it would be nice if I could do this without the needibg to duplicate and maintain the local console code. This might not be a very general use case but I would propose a way to add a custom console with lua similar to CommandLineRun

pkulchenko commented 9 years ago

Elias, are you looking for a way to have another tab that interacts with your app? Like a remote console that has input/output connected to your particular app?

Does it need to be a tcp message or can it be stdin/stdout? If you may need either one for your project, it seems like it needs to be done in a generic way; when creating this component you'd need to provide two callbacks for input/output (unless you can use a default one that is based on stdin/stdout).

Can you do a diff of your changes and gist them somewhere? I think it will help to assess the amount of work needed to support this? Thanks.

CapsAdmin commented 9 years ago

Elias, are you looking for a way to have another tab that interacts with your app? Like a remote console that has input/output connected to your particular app?

Exactly.

Does it need to be a tcp message or can it be stdin/stdout? Callbacks so people can choose yeah. If you may need either one for your project, it seems like it needs to be done in a generic way; when creating this component you'd need to provide two callbacks for input/output (unless you can use a default one that is based on stdin/stdout).

Can you do a diff of your changes and gist them somewhere? I think it will help to assess the amount of work needed to support this? Thanks.

https://www.diffchecker.com/jcfabyvl

it's kinda hacked on but you hopefully get the idea. I just call CONSOLE_OUT(str) whenever I receive a console message from my project. And I call PLUGIN:onLineInput(tx) on my plugin (i should call it on the actual object and not the metatable and CONSOLE_OUT should be renamed "RemoteConsolePrint" but yeah you get the idea)

it could be something simple like this:

local shell = AddConsole(TR"Remote Console", function(line) 
    if IsLineBad(line) then 
        return false, "bad line" -- calls shell:DisplayErr("bad line") or something
    end

    socket:send(line)
end)

shell:Display("hello world!")
CapsAdmin commented 8 years ago

I have rewritten my remote console code to support more than one console. All configuration is done in PLUGIN:Setup() which is also where I handle input and output. This launches a process and redirects the process' output to the shellbox remote console. For input I create a socket that connects to my application. This is sort of what I'd like zerobrane to have but a bit more generic maybe.

In the duplicate shellbox code I localize things in order for it not to conflict with the existing shellbox. ie local DisplayShell = ..., strip down executeShellCode to handle input only and then i copy the code that allows the "select all" and "clear" context menu to the bottom of the duplicate shellbox code.

My main issue is that I have to duplicate the shellbox code. I'm not really sure what the solution is other than to have an api of some sort for creating multiple shellboxes.

You seem to be moving to a style which avoids using many globals and instead have a library, like ide:Print instead of DisplayOutputLn. This would be a start at least (if you remove DisplayOutputLn)

pkulchenko commented 8 years ago

@CapsAdmin, very interesting; I think I'll have a better idea of how the API may look like after I explore your code a bit.

My main issue is that I have to duplicate the shellbox code. I'm not really sure what the solution is other than to have an api of some sort for creating multiple shellboxes.

Agree; it would be beneficial to just have some API that allows you to create a new shellbox/console with (1) input/output connected to a function, or (2) input/output connected to a script. Would that satisfy your requirements?

I was also thinking about having a method to create that simple editor menu (so that you could just add Clear Console Window to it, but it turned out to be not that beneficial; maybe I need to revisit it, but if there is a way to create new console, then this menu would already be included there.

You seem to be moving to a style which avoids using many globals and instead have a library, like ide:Print instead of DisplayOutputLn. This would be a start at least (if you remove DisplayOutputLn)

Indeed; in fact, there is also ide:GetOutput():Print() and ide:GetConsole():Print() (as well as Write() calls); ide:Print() is just a shortcut that uses the output (although it has special internal implementation that allows you to use it even when the output window is not yet setup).