[Gambas-user] removing xterm escape codes from terminal text
Bruce Steers
bsteers4 at gmail.com
Wed Jun 8 14:19:23 CEST 2022
On Wed, 8 Jun 2022 at 05:06, Brian G <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 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.
but the following works at least, this is the output (263 = actual output,
264 = CleanText() output)
RootShell.Process_Read.263: "\x1B]0;root at bonus-G33M-DS2R:
~\x07root at bonus-G33M-DS2R:~# *|com-ready|*"
RootShell.Process_Read.264: "root at bonus-G33M-DS2R:~# *|com-ready|*"
RootShell.Process_Read.263: " \x1B[0m\x1B[01;36mbin\x1B[0m
\x1B[01;36mlib32\x1B[0m \x1B[01;34mroot\x1B[0m"
RootShell.Process_Read.264: " bin lib32 root"
*Public Sub CleanText(Text As String) As String Dim w As Window, tv As
TerminalView, p As Process w = New Form w.Width = Screen.Width w.Height
= 100 w.Arrangement = Arrange.Fill tv = New TerminalView(w) tv.ReadOnly
= True 'w.Show Wait p = tv.Shell("bash")While p.State <> Process.Running
Wait Wend $hFilter.OutputTo(tv, tv._GetCurrentScreen(), p, Text)Dim sText
As String = tv.TextTry p.CloseTry tv.KillReturn sTextEnd*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220608/9d0b43c3/attachment.htm>
More information about the User
mailing list