[Gambas-user] removing xterm escape codes from terminal text

Brian G brian at westwoodsvcs.com
Thu Jun 9 16:26:38 CEST 2022


> "Failure is the key to success;
> each mistake teaches us something" .. Morihei Ueshiba
> Brian G

> ----- On Jun 8, 2022, at 1:53 PM, Bruce Steers <bsteers4 at gmail.com> wrote:

>> On Wed, 8 Jun 2022 at 13:19, Bruce Steers < [ mailto:bsteers4 at gmail.com |
>> bsteers4 at gmail.com ] > wrote:

>>> On Wed, 8 Jun 2022 at 05:06, Brian G < [ mailto:brian at westwoodsvcs.com |
>>> brian at westwoodsvcs.com ] > wrote:

>>>> I think there is, I will check it in the morning

>>>> --
>>>> Thanks
>>>> Brian G
>>>> Tuesday, 07 June 2022, 01:20PM -07:00 from Bruce Steers [
>>>> mailto:bsteers4 at gmail.com | bsteers4 at gmail.com ] :

>>>>> Has anyone made a routine to strip xterm escape codes from a terminal text?

>>>>> I'm looking at having to have a close study of the TerminalFilter_VT100.class
>>>>> and try to account for all possible code combinations to strip them.

>>>>> I thought before i spent hours doing it i'd ask if anyone already has and could
>>>>> share the code.

>>>>> Or if there is already a way either an existing function somewhere or possibly
>>>>> in gb.form.terminal or some other class a function that could do it.

>>>>> I'm looking at TerminalFilter_VT100.class and the function OutputTo() looks like
>>>>> it could do it , it seems to do all the right processing but for other reasons.
>>>>> maybe by printing to a stream i could get plain text but i do not know how to
>>>>> do that :(

>>>>> Any thoughts/suggestions?
>>>>> Many thanks
>>>>> All the best
>>>>> BruceS

>>> Cheers Brian.

>>> I have managed this so far but it seems bulky.
>>> I added it to TerminalView.class ,
>>> Bulky because it makes a whole new hidden form/terminalview and uses it's
>>> OutputTo() to print text to it then uses TerminalView.Text,
>>> trouble is OutputTo() needs a terminalview object in it's arguments.

>>> Could be easier to just use the normal TerminalView.Text and process all the
>>> text not one line at a time as it's output. :-/

>>> Or maybe I should copy the OutputTo() and Escape() methods and edit them to not
>>> print text to a TerminalView stream but return it instead.

>> I did the above mentioned, copied OutputTo() and Escape() from
>> TerminalFilter_VT100.class and removed all functionality and made all Print
>> statements assign to a return string instead.

>> I'll attach the project in case anyone is interested. (feel free to
>> optimize/improve the code ;) )

>> the aim of the project is to enable/disable a private root shell inside an
>> application for issuing multiple commands with only one authorization request.
>> Easy enough to to with a TerminalView and bash but not so easy to get some kind
>> of "Wait" ability and getting return values and text from inside the bash
>> shell.

>> It relies on monitoring the process text output, is starts bash and echos a
>> "shell-ready" then after the command completes it echos "com-done:$?" giving
>> the return value.

>> Wishing well
>> BruceS

> I seem to remember there was a callback style thing to allow filtering, checking
> could be a dream!

>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----

> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
Bruce, 

Did you look at the ConnectTo to method in the terminal view, It allows to filter IO 
' allow a connection to a filter or other task 
' Output is the Pipe on which the connect Task or process will receive input 
' the input stream I the one this process will use to receive input 
' if a callBack is passed then the preprocess method is executed before recieved data is handled by the terminal 
' Preprocess may return true to have the terminal process the data, or false to have the terminal ignore the data 
' This allows the implementation of a state machine or filter to hande extended terminal functions on the stream 

Maybe this can help 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220609/fc9062bb/attachment.htm>


More information about the User mailing list