how to input multiline statements into arangosh? - arangodb

as far as I know the only way to register aqlfunctions is via arangosh. JS functions very fastly get a few more lines of code which normally also have line breaks for better understanding. Whenever I paste them into the arangosh it gets corrupt as it excepts to get a "proper" end signal/sign. If I don't know it , the only way to reset it is a shotdown. My questions are:
Is there any shortcut like which resets the line input in such a case?
How can I write JS code into several lines and paste them into the arangosh directly?
Is there another way to register (more complex) JS functions I don't know?
Thanks for your help in advance.

<STRG> + D also works in windows.
Multiline doesn't work well with the CMD, it works partly with the cygwin shell window.
However, if the context shows that a function will start (using a brace) it will offer to add another line until the brace closes.
Probably the easiest way to get in more complex code is:
require("internal").load("c:\\tmp\\test.js")
which will be executed right away, so if you define functions in that, they will be usable in the shell context from then on.

Related

How to create linux tui like this one on the picture

Could someone share how can i create tui like this one with input boxex and search ?
What do i need?
Normally programmers use a ready to use library like ncurses.
You can also do it by hand if you really have to much time. To get for example the border lines of a dialog window you have to take a look at the current code page your terminal is emulating, for example: Code Page 850. As you can see, you will find single and double line boarders and also crossings and so on. Now you have to move your cursor to a given position, print that char from the code page and ... lots of work. Moving cursors itself can also be done by simple chars from your emulated terminal by using escape codes.
As said: Instead of doing it all by hand, simply use a lib like ncurses.
You can use some python libraries like pyTermTk or textual, there is wide selection of
libraries to choose from.

How to transform lines of code into a comment in Python3

just wondering how to convert a set of code into comments, without having to go through each individual line of code and put a # at the beginning. Was thinking that maybe there was a quick way to highlight the code and then convert it into comment, atm i'm just cutting it off the code and then re-pasting it in later on.
Much appreciated :)
P.S. i m using Pycharm as my IDE
In jupyter notebook, we select lines of code and press ctrl and / key simultaneously to convert a set of code into comments. Also same for vice versa.
You can try it in Pycharm.
You can use the (""") symbol before and after the text you want to comment out. It is not exactly a comment and more of a text constant, but either way it is often used for documentation, so you can use it for multiline comments except for some cases when it causes unexpected errors
To avoid such cases you could simply use multiple single line comments by selecting the desired lines and using ctrl+/ to comment them out

How to call external "interactive/TUI" command, interact, and read std output

I am trying to write my first vim script, so I apologize if this question boils down to not understanding the basics.
The main goal is that I want to call out to an external command from inside vim and read the results back into the file.
I know how to do this with simple shell commands, e.g. r !ls. However the command I want to interact with is "interactive".
I don't know if this is a meaningful description. But calling this command in the shell opens a TUI, then after interacting with the TUI the command will exit and put things into standard output. I want to read that standard output back into vim.
Possibly it will help to discuss the specific command, which is papis a cli citation manager. If you call, e.g. papis list --format '{doc[title]} {doc[author]}' in the shell it will open up a TUI that allows me to filter down and select a document. After selecting the document it will put the title and author into the standard output. This is what I want to read into vim.
However, my first few attempts have not been successful. Trying the naive :r !papis list results in an error, even though that command is valid in the shell and would result in the TUI being opened. So I'm obviously missing something.
Can anyone recommend a guide or suggest a possible solution for correctly calling out to TUI-based external commands and reading back their standard output?

stdio/piping issues when using vim in child process in node.js

I am using node.js to write a command line interface that generates unit test files. I have been using inquirer to get user input, however there is one field in which the user will very likely want to copy-paste and/or edit, large multi-line chunks of JSON data. Therefore, my goal is to:
open vim # certain point in CLI -> allow input-> close vim -> write out to tmp file -> process the result.
The problem is that input to vim is also going to the parent stdin, and when the return key is hit, the program continues on top of vim (mayhem). I'm fairly certain that stdio/in/out/err are not set up properly, but i cant seem to find the exact solution anywhere. Every iteration of my manipulating the streams seems closer, but i know that there is a small missing link.
i have tried a lot of things along the lines of:
var vim = child_process.spawn('vim', [path], {stdin: 'pipe', stdout: 'pipe', stderr: 'pipe'});
var vim = child_process.spawn('vim', [path], {stdio: 'inherit'}); //{stdio: ['pipe','pipe','pipe']}
Finally, i have followed a lot of the stdio manipulation from this example, How do I open a terminal application from node.js?, but there still remains some small missing link that i need help with
Notes:
I am 99% certain that my async promises are in order.
it doesn't necessarily have to be vim, as I am checking the ENV for
an editor first
I liken this to git commit, where an editor pops up and allows input
before closing
in a small test program, i can get perfect functionality, but when
trying to do this over another process, it doesnt go well
tl;dr : i want to ignore the parent process while input goes only to vim (child_process), but i cannot keep them separated, and because of this, the program goes haywire
If there is anything i can clarify, please let me know.
Thanks!
I know this is old, but anyway 6 days ago they released a function with 2015.02.06 Version 0.12.0 (Stable) that makes this very easy.
var spawnSync=require("child_process").spawnSync;
spawnSync("vim",[__filename],{stdio:"inherit"});
It will of course block the event loop, but in such a situation you likely want to wait for the user. Otherwise, you may end up with node writing to stdout and reading stdin while you are editing, which is obviously very confusing, and is the issue you were running into.
If you really still need asynchronous stuff while you are editing, it's probably easier to require("child_process").fork so you don't confuse the stdin/stdout. I imagine you could do some fancy stuff to remove all the listeners and add them back later, but it's probably not worth the effort.

Creating new files with Lua I/O functions

I'm starting to learn about the io. functions, and am trying to implement them in my code. I've searched for the answer to this and nothing seems to give a clear cut yes or no, or at least I don't see one. I'm hoping someone here will know the answer and be able to help with this.
I'm wanting to create a text file that I can write to as time progresses. It'll basically be a log to which I'll be appending lines of output. Apparently io.open("textfile.txt") does not create the file, or so it appears.
Is there a way to create a text file in Lua that can later be accessed with io.read/write? Additionally, do I need to call io.close() before opening or creating a new text file? I appreciate any help given. Thanks!
You need to open the file for writing as follows: f=io.open("textfile.txt","w"). Then use f:write() to write stuff to it. When finished writing, call f:close().

Resources