Nп/п : 45 из 100
 От   : Janis Papanagnou                    2:5075/128        09 сен 23 05:22:57
 К    : Richard Harnden                                       09 сен 23 06:25:02
 Тема : Re: Nice prompt [Bash specific]
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> fe24d547
@REPLY: 1@dont-email.me> c05ea27a
@REPLYADDR Janis Papanagnou
<janis_papanagnou+ng@hotmail.com>
@REPLYTO 2:5075/128 Janis Papanagnou
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References: <20230803112254.131@kylheku.com>
1@dont-email.me> 1@dont-email.me>
@TZUTC: 0200
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:45.0)
Gecko/20100101 Thunderbird/45.8.0
@TID: FIDOGATE-5.12-ge4e8b94
On 08.09.2023 20:13, Richard Harnden wrote:
> On 08/09/2023 15:04, Janis Papanagnou wrote:
>> On 03.08.2023 20:31, Kaz Kylheku wrote:
>>> [...]
>>>      local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME
>>> $dots$pwd"
>>>      local status_nohl="$(date +%m-%d/%H:%M) $HOSTNAME $dots$pwd"
>>>      [ ${#status_nohl} -le $COLUMNS ] && break
>>> [...]
>>
>> One more question; is there any neat way to get the "net" length of a
>> string that carries ANSI control characters (without duplicating the
>> code as above)?
>>
>> Initially I wanted to add [ANSI-escape] colors to my "kosta" variant
>> (e.g. somthing like  errorsshlvlpath...),
>> but lacking a good idea I abstained from supporting that feature.

> I was also having problems with printf and ansi/utf8.

> Don`t have a ksh solution, but a short bit of C ... maybe it`s useful.

> eg:
> [snip samples ]

> Anyway ...
> [ snip C-code ]

I`m looking for any ideas or insights, so thanks for your idea and
C-code.

I see that you seem to have used a heuristic, triggering with Esc
and terminating with any lower-case character. - This is (almost)
exactly what I tried in shell with patterns (operating on text
that uses an \\E escape literal for Esc)...

  plain=${var//\\E\\[*([!a-z])[a-z]} ; len=${#plain}

I had used "Esc[" (for my cases) but "Esc]" might also be relevant
for a more general application of the pattern (an extension to both
brackets is straightforward, of course). I had included the brace
because I wasn`t sure whether an Esc might occur in other contexts
as well alone. (I wasn`t sure, though, whether such patterns are
just a hack or sufficient for all ANSI escapes and not conflicting
with other applications.)

The C-code reminds me that any clumsy solution could also be hidden
by creating a shell built-in from a C-function. (But that relocates
the task just to another place.)

Instead of a C program another option could also be a sed-script.
(Performance should not be an issue here.)

Initially I was hoping for a _standard_ tool (like col(1), a tool
to filter reverse line feeds from input), since shell patterns (or
C-code) appears to me to be a bit bulky. (But probably there isn`t
any neat and bulletproof standard tool existing...?)

Janis

--- Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
 * Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх