Nп/п : 44 из 100
 От   : Kaz Kylheku                         2:5075/128        09 сен 23 03:03:20
 К    : Janis Papanagnou                                      09 сен 23 06:05:01
 Тема : Re: Nice prompt [Bash specific]
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <20230908195903.275@kylheku.com> c24ba601
@REPLY: 1@dont-email.me> 4eb4ae59
@REPLYADDR Kaz Kylheku <864-117-4973@kylheku.com>
@REPLYTO 2:5075/128 Kaz Kylheku
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <20230908195903.275@kylheku.com>
@RFC-References: <20230803112254.131@kylheku.com>
1@dont-email.me>
@TZUTC: -0000
@PID: slrn/pre1.0.4-9 (Linux)
@TID: FIDOGATE-5.12-ge4e8b94
On 2023-09-08, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> 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)?

In the current version of the code, I see I had abandoned the
above approach. I have only one string which is rendered.
There is still duplication, but only of the escapes:

  local status_esc="$esc[7m$esc[m"

  while true; do
    local status="$esc[7m$(date +%m-%d/%H:%M)$esc[m $HOSTNAME $dots$pwd"
    local status_len=$((${#status} - ${#status_esc}))
    [ $status_len -le $COLUMNS ] && break
    pwd=${pwd#/}
    pwd=/${pwd#*/}
    dots=`...`
    [ "${pwd#/*/}" == "$pwd" ] && break
  done

status_esc is a string consisting of all the escape material
which occurs in status, so has to be maintained in parallel.

While that sucks, it sucks less than repeating the $(date ...)
and $HOSTNAME and other details. 

In the above loop, I should be using a cached sample of the
$(date ...) too.
--- slrn/pre1.0.4-9 (Linux)
 * 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    
                                                                                
В этой области больше нет сообщений.

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