Yes, "es" == "emit string" is one of the arcane bits of Leo-lore, IMO. I 
think the docs should mention this, IIRC they do not and it must have 
caused some puzzlement over the years...

On Wednesday, January 3, 2024 at 2:02:15 AM UTC tbp1...@gmail.com wrote:

> Ha! Should have tried that right off!.  Thanks.
>
> On Tuesday, January 2, 2024 at 8:16:51 PM UTC-5 Félix wrote:
>
>> Hi Thomas! :)
>>
>> I gather that by an 'Output window' you mean the LeoJS Log Window? (The 
>> equivalent of Leo's Log Window)
>> [image: log_pane.png]
>>
>> Using *console.log (*which is indeed the equivalent of python's *print 
>> *function, 
>> which prints in the terminal instead of Leo's Log Window), will itself 
>> indeed print in the developer's-tools-terminal. (not recommended)
>>
>> What I recommend in contrast, is the *g.es <http://g.es> *function (and 
>> other 'g' methods like es_print, etc.) which does print in the Log Window. 
>>
>> See (and study) this example script that gives a few pointers on how to 
>> do various useful stuff :
>>
>> @language javascript
>> const vscode = g.app.vscode;
>> g.es("hahahaha");
>> // 'await' for doCommandByName required only if other code in script is 
>> 'awaited'.
>> await c.doCommandByName('insert-headline-time');
>>
>> const userInput = await vscode.window.showInputBox({
>>     placeHolder: 'Enter something', // Placeholder text in the input box
>>     prompt: 'Please enter some text:', // Prompt message above the input 
>> box
>> });
>> if (userInput === undefined) {
>>     g.es('User canceled the input.');
>> } else {
>>     g.es('User input:', userInput);
>> }
>> try {
>>     const apiUrl = 'https://jsonplaceholder.typicode.com/users';
>>     const response = await fetch(apiUrl);
>>     g.es("about to call");
>>     if (!response.ok) {
>>         throw new Error('Network response was not ok');
>>     }
>>     const data = await response.json();
>>     g.es("got it!!", JSON.stringify(data));
>> } catch (error) {
>>     g.es("oh no!");
>>     console.error('Fetch error:', error);
>> }
>>
>>
>> It will insert the current time on the selected node, then pop an input 
>> box and print it back out in the log window, along with the result of an 
>> HTTP fetch call to some test API. Here is a screenshot of the result of 
>> running this script online in vscode on the web :
>> [image: screen_script_web.png]
>>
>> Hope this helps! 
>>
>> Félix
>>
>> On Tuesday, January 2, 2024 at 12:43:46 PM UTC-5 tbp1...@gmail.com wrote:
>>
>>> This script apparently runs without error but nothing shows in the 
>>> Output window:
>>>
>>> @language javascript
>>> console.log('this is another test');
>>>
>>> Using print() doesn't work, of course, because there isn't a print() 
>>> function.  How can we get a visible output?
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/d7fd99f7-6e40-495f-9d1f-ba3c06673f6dn%40googlegroups.com.

Reply via email to