Nп/п : 46 из 100
 От   : Janis Papanagnou                    2:5075/128        09 сен 23 05:39:01
 К    : Kaz Kylheku                                           09 сен 23 06:41:02
 Тема : Re: Nice prompt [Bash specific]
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> 716f0dbb
@REPLY: <20230908194428.631@kylheku.com> 39fe48ee
@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> <20230908194428.631@kylheku.com>
@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 09.09.2023 04:53, Kaz Kylheku wrote:
> 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)?

> There could be ways, like using a function like $(ansi "$esc[m").

Yes, any neat interface that prevents duplication would be nice.


> Let`s recall that the code is Bash specific.

I took the code from your bash code for explanation only, but I
have the same issue with my ksh variant; it`s a general task
independent from these status line projects.


> Bash has dynamically scoped local variables, allowing us to cleanly
> control the behavior of functions with flags, without resorting
> to blatant global variables.

>   local ansi_enable=y

> such that $(ansi ...) will output its argument, rather than
> consume it and output nothing. When the scope terminates
> the prior value of ansi_enable is restored automatically.

The interface question is crucial for a neat implementation.

For ksh, maybe defining a discipline function for a "no_ansi"
variable would be a sensible implementation, say,

  no_ansi=${status} ; printf "${no_ansi}"

with  function no_ansi.set  removing the ANSI escapes using a
variable substitution (or a C-compiled shell built-in)?

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    
                                                                                
В этой области больше нет сообщений.

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