chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.6k stars 142 forks source link

from lua, send command to prompt and run it #665

Closed indiscible closed 2 months ago

indiscible commented 2 months ago

I looked at the lua doc and the closest I found was rl_buffer.insert("dir") but then I cannot find a way to send the return as well...

Basically the feature I'm looking for is a way to inject commands into the console.

chrisant996 commented 2 months ago

Basically the feature I'm looking for is a way to inject commands into the console.

When? In response to what?

Maybe you're looking for clink.onprovideline()?

Maybe you're looking for rl.invokecommand() and accept-line?

Or maybe for something else, depending on broader context about what you're trying to do.

indiscible commented 2 months ago

I would like to send a (for example a compile & run) command (from emacs or clink?) to an existing cmd window as if I had entered it by hand. To replace a "Save, Alt-Tab, Up-Arrow, Enter" sequence.

Conceptually it's like writing to the stdin of another cmd process, if that makes sense.

clink.onprovideline() looks interesting (and dangerous), thanks !

chrisant996 commented 2 months ago

It sounds like you want to send arbitrary keystrokes from one program/window (the active one...?) to another program/window (which is not the active window...?). If so, then that isn't related to Clink.

If you want to send keys to the active window, then you can explore SendKeys and similar things.

Sending keys to a non-active window is more difficult, and is unreliable depending on what keys you're trying to send (and in what language, etc). This stackoverflow post gives a quick introductory summary into the topic.

indiscible commented 2 months ago

ok, thanks for the extra info, I'll keep digging....