[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TerminalView position and text of prompt


On Tue, 16 Apr 2024 at 14:15, Benoît Minisini <
benoit.minisini@xxxxxxxxxxxxxxxx> wrote:

> Le 16/04/2024 à 15:03, Bruce Steers a écrit :
> >
> > So i just need to know reliably where exactly the PS1 prompt ends and
> > the command begins.
> >
> > If possible, If somewhere in the terminalview code this place is known?
> > Or if from the codes perspective that position is all handled by the
> > running shell so it's irrelevant/unknown.
> >
> > Respects
> > BruceS
> >
>
> I think there is no reliable way to detect a prompt:
>
> - The shell knows what the prompt is, and when it will be printed to the
> terminal. But it cannot know how exactly it will be drawn inside the
> terminal.
>
> - The terminal knows how things are drawn. But it has no way to know
> what is a prompt, and what is not a prompt.
>
> Regards,
>
> --
> Benoît Minisini.
>
I may have found an answer already in the code...
https://gitlab.com/gambas/gambas/-/blob/master/comp/src/gb.form.terminal/.src/TerminalView/TerminalFilter_VT100.class?ref_type=heads#L158

it does this.....

        If sCmd = "0" Or If sCmd = "2" Then          hView.Title = sTitle

sData at that point has the path to the left of iPos2 that is used to set
the title and it seems to have the prompt to the right

        If sCmd = "0" Or If sCmd = "2" Then          hView.Title = sTitle
          hView.Prompt = Mid$(sData, iPos2 + 1)


I wish there was an easily way to remove escape sequences and convert it to
plain text

All i found was a sed command

Private Sub Prompt_Write(Value As String)

  Shell "echo -n '" & Value & "'| sed -r
\"s/\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g\"" To $sPrompt

End


Respects
BruceS

Follow-Ups:
Re: TerminalView position and text of promptBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
References:
TerminalView position and text of promptBruce Steers <bsteers4@xxxxxxxxx>
Re: TerminalView position and text of promptGianluigi <gradobag@xxxxxxxxxxx>
Re: TerminalView position and text of promptBruce Steers <bsteers4@xxxxxxxxx>
Re: TerminalView position and text of promptBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>