Nп/п : 43 из 100
 От   : Kaz Kylheku                         2:5075/128        09 сен 23 02:53:25
 К    : Janis Papanagnou                                      09 сен 23 05:56:02
 Тема : Re: Nice prompt [Bash specific]
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <20230908194428.631@kylheku.com> 39fe48ee
@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: <20230908194428.631@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)?

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

Let`s recall that the code is Bash specific.

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.

Now the thing is that I have a code smell: the double invocation
of date! In status_nohl, I`m calling date a second time, only
to get the format for the purposee of counting length.

I would prefer some solution in which we mark up the ANSI stuff
somehow like:

   @@$esc [m@@.

For the purposes of rendering the codes, we filter out the expanded
version of @@$esc[m@@ (and everything similar) into just $esc[m.

For the purposes of calculating size, we filter @@$esc[m@@ into
nothing.

Bash should be able to do this ${var/this/that} substitution;
I will look into it.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don`t see you, unless you`re whitelisted.
--- 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    
                                                                                
В этой области больше нет сообщений.

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