Nп/п : 20 из 100
 От   : Kaz Kylheku                         2:5075/128        29 авг 23 23:42:02
 К    : Janis Papanagnou                                      29 авг 23 02:44:02
 Тема : Re: Nice prompt [Bash specific]
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <20230829162831.608@kylheku.com> 8efc4951
@REPLY: 1@dont-email.me> f69ba20e
@REPLYADDR Kaz Kylheku <864-117-4973@kylheku.com>
@REPLYTO 2:5075/128 Kaz Kylheku
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <20230829162831.608@kylheku.com>
@RFC-References: <20230803112254.131@kylheku.com>
1@dont-email.me> <20230804101131.699@kylheku.com> 1@dont-email.me>
<20230805084100.353@kylheku.com> 1@dont-email.me> 1@dont-email.me>
@TZUTC: -0000
@PID: slrn/pre1.0.4-9 (Linux)
@TID: FIDOGATE-5.12-ge4e8b94
On 2023-08-29, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> On 08.08.2023 03:57, Janis Papanagnou wrote:
>> [...a Kornshell variant of "basta"...]
>> 
>> namespace kosta
>> {
>>     typeset -i  rows=${LINES} cols=${COLUMNS}
>
> When installing the module to be sourced during .profile/.kshrc
> initialization I noticed that these two shell variables aren`t
> yet defined at that instance of time (which at least initially

Yes. I discovered this too. A while ago, in fact.
Then I forgot about it, so that a bug recently crept in. I
I changed a certain global variable initialization to this:

  basta_scroll_lines=${basta_scroll_lines-$LINES}

which left the variable with a blank value when initializing out
of .bashrc!

I pushed out a fix for this just this morning!

However, LINES is available by the Bash calls the prompt hook.
So the bulk of the initialization is done at that time.

Speaking of globals, I initializee all global variables conditionally:

  basta_old_cmdno=${basta_old_cmdno-0}
  basta_old_lines=${basta_old_lines-0}
  basta_old_cols=${basta_old_cols-0}

  basta_scroll_lines=${basta_scroll_lines-0}
  basta_prev_reserved_rows=${basta_prev_reserved_rows-}

  basta_status_alarm_pid=${basta_status_alarm_pid-}

This allows for hot reloading without clobbering the variables.

In Common Lisp there is a defvar macro operator which defines
a variable if it doesn`t already exist. If a value is specified
it assigns that value. If the variable already exists, it does
not assign the value. E.g.

  (defvar *obj-count* 0)

If you reload the code, it will not reset your *obj-count* to zero.

If you want that you use:

  (defparameter *obj-count* 0)

whose second argument is mandatory and always assigned to the
variable.

>     typeset -i  rows cols
>     stty size | read rows cols

I no longer trust the size, except on first invocation.

In the first-time, once-only initialization code that is done by the
prompt hook when it detects that startup, I trust that the $LINES
variable corresponds to the usable area of the terminal, not
necessary the whole thing. I then query the terminal to determine
its size: position the cursor to 999,999 and then inquire about
the current position, to get ther row number and that`s the size.
From that, it is inferred whethere or not there is already a protected
status line; we put our status line above any protected status lines.

On subsequent terminal resize operations, the terminal is always
queried for the size, rather than believing that $LINES or the tty
driver has the correct size.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
--- 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    
                                                                                
В этой области больше нет сообщений.

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