Author Topic: cannot exec_command_to_window towards output  (Read 322 times)

RaffoPazzo

  • Community Member
  • Posts: 74
  • Hero Points: 2
cannot exec_command_to_window towards output
« on: April 27, 2021, 07:47:54 pm »
I'm trying to refactor my Idris bindings to print to the output window and I'm trying something like this
Code: [Select]
int outputWindowId = activate_output();
return exec_command_to_window(cmd, outputWindowId);

But it fails with property or method not allowed on this object  ???

Code: [Select]
Stack trace written to file: /tmp/vsstack.raff
 This property or method is not allowed on this object
pipe.ex 1158 exec_handle_pipes(
   1:   ._typename()=ExecState
   1:   .outWindow=281
   1:   .auxOutWindow=-1
   1:   .progress=-1
   1:   .progCount=0
   1:   .curWin=344
   1:   .procStdin=31
   1:   .procStdout=32
   1:   .procStderr=30
   1:   .procHand=10
   1:   .readProgresFromStdout=0
   1:   .progStep=10
   1:   .progN=10
   1:   .buf=Error: While processing right hand side of foo. Can't find an implementation for Num String.

/home/raff/Test.idr:4:9--4:10
 1 |
   1:   .finished=0
   1:   .result=(null)
   p_window_id: 281
   p_object: OI_FORM
   p_name: _tboutputwin_form
pipe.ex 2024 exec_command_to_window(idris --no-color /home/raff/Test.idr --client ":r",281,-1,-1,0)   p_window_id: 247   p_object: OI_EDITOR   p_name: ctloutput
idris.ex 171 idris:_run(idris,--no-color,/home/raff/Test.idr,--client,":r")   p_window_id: 247   p_object: OI_EDITOR   p_name: ctloutput
idris.ex 375 idris:_idris(:r)   p_window_id: 344   p_object: OI_EDITOR   p_name:
idris.ex 580 IdrisReload()   p_window_id: 344   p_object: OI_EDITOR   p_name:

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1651
  • Hero Points: 140
Re: cannot exec_command_to_window towards output
« Reply #1 on: April 27, 2021, 08:49:33 pm »
I think the documentation in exec_command_to_window() may need a tweak.  The outWindow really wants the text control handle for the output window, not the window form itself. 

Replace "activate_output()", with "output_window_text_control()" from stdcmds.e.  It does the same thing as activate_output(), but returns the text control handle rather the window handle.

RaffoPazzo

  • Community Member
  • Posts: 74
  • Hero Points: 2
Re: cannot exec_command_to_window towards output
« Reply #2 on: April 28, 2021, 08:08:48 am »
Thanks! This worked. In fact, I hacked it to write to the build window because I wanted to exploit the xterm coloring feature (I'm on v25) but I see things like
Code: [Select]
<ESC>[38;5;9;1mError:<ESC>[0m <ESC>[1mWhile processing ...Perhaps this is because of the way I'm sending the idris output to the build window? Perhaps I'm accidentally "wrapping" the text in a way that breaks the parser?
Here's (a reduced version of) what I'm doing
Code: [Select]
static int _build_window_text_control() {
   oform := tw_find_form('_tbshell_form', _MDICurrent());
   if (oform <= 0)
      oform = activate_tool_window('_tbshell_form');
   return oform._find_control('_shellEditor');
}

static int _run(_str cmd) {
  int wid = _build_window_text_control();
  return exec_command_to_window(cmd, wid);
}

If it makes things easier, I can also interact with Idris using `_PipeXyz()` as opposed to building a command line (although looking at `pipe.e` I guess it makes no difference to this issue).
« Last Edit: April 28, 2021, 10:51:19 am by RaffoPazzo »

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1651
  • Hero Points: 140
Re: cannot exec_command_to_window towards output
« Reply #3 on: April 28, 2021, 01:31:20 pm »
Only the output from the process associated with the build window gets interpreted for ANSI escapes, it won't see text you're inserting into the text control directly.

But if you want it to be run in the build window, you can use concur-command to execute your command instead.  Then the color coding should be shown.  ie: concur_command('ls --color') will run the ls in Build window's shell process.  It will start the process if it hasn't been already.