aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Watch for empty response when getting current line.HEADmasterKaz Kylheku40 hours1-1/+1
| | | | | | | | - When we query the current line from the terminal, there are situations when that might time out and yield a blank response. In basta.check_cursor, we guard against that, or else the user may, rarely, see a message complaining that the [ command is missing an operand for the -gt operator.
* Do not set termios rows in prompt hooks.Kaz Kylheku4 days1-2/+2
| | | | | | | - I suspect this is involved in the bug I'm seeing whereby the scroll region goes wonky. It may be preventing our logic from kicking in to fix the situation, by making termios_lines equal LINES and to basta_old_lines.
* Use \e for ESC via Bash $'...' syntax.Kaz Kylheku5 days1-18/+12
| | | | | - We get rid of 'local esc=$(printf "\033")' everywhere and use the escape sequence.
* README: recommend simple reload first.Kaz Kylheku9 days1-11/+9
|
* Abruptly disappearing status bug.Kaz Kylheku2025-01-141-1/+1
| | | | | | | | | | | - In the basta.update_status function's path abbreviating loop, we must test whether the path can be abbreviated, and bail, before doing the abbreviation. If we do the test after the abbreviation, we create a one off error where we bail the loop with an overlong status line that does not fit even though we could have abbreviated the path by one more component. And then the status line is surprisingly blanked.
* Copyright year bump to 2025.Kaz Kylheku2025-01-011-1/+1
|
* Check the termios rows and columns for sanity.Kaz Kylheku2024-12-311-1/+18
| | | | | | | | | | | | | | | - In basta.update_status, we should be checking not only for LINES and COLUMNS changing, but also for the underlying termios parameters changing (which we can obtain using stty size). The motivation for this change is that I'm still seeing situations in which the scroll region gets messed up. I can get Basta to fix it by manually setting basta_old_lines to 0 to force basta.update_status to call basta.prepare_term. That tells me that the problem is that basta_old_lines is equal to $LINES. I've not root-caused the issue, though. The hypothesis is that perhaps $LINES has become incorrect: perhaps Bash didn't set LINES to the size that the kernel knows about and has set up in termios. We can catch that discrepancy.
* Streamline code in basta.prepare_term.Kaz Kylheku2024-12-191-4/+4
| | | | | | | | - We calculate the final LINES value unconditionally whether or not it is the first call that sets basta_prev_reserved_rows. Then we just copy that value into basta_scroll_lines and basta_old_lines. We don't rely on the side effect of the "stty rows" command setting LINES.
* bugfix: don't clobber LINES with real terminal sizeKaz Kylheku2024-12-191-3/+4
| | | | | | | | | - In basta.prepare_term, if we already know how many reserved rows there are, we should not be calling bsata.query_terminal_lines to get the real terminal size into LINES. We need to get that into a local variable and then subtract form that the lines we know are reserved, and use that for setting the number of lines.
* bugfix: nameref hygiene problem.Kaz Kylheku2024-12-191-2/+2
| | | | | | | | - the basta.query_terminal_lines function is invoked by a caller which passes in a variable name realrows. If the function has a same-named local variable, the name wrongly refers to that variable. We rename the local to curline.
* Bail if Bash is not interactive.Kaz Kylheku2024-12-191-0/+2
|
* workaround for GNU Readline problem.Kaz Kylheku2024-12-161-0/+4
| | | | | | | | | - When the bracketed paste feature is enablied in GNU Readline, then each time the library processes a SIGLARM signal, it emits codes to turn off and on bracketed paste. In between these codes, it also emits a CR character that causes the cursor to jump to the beginning of the line. We work around this by turning off bracketed paste.
* Streamline $_ saving.Kaz Kylheku2024-04-101-2/+1
| | | | | | | | | | | | - Remove basta_uln_save variable. - In basta.alarm_timer use nicer sequence for saving and restoring $_, stashing it directly in the command's expansion, without requiring the global variable, taking advantage of our handler ignoring its arguments. - Independently pointed out by Janis Papagnou and Koichi Murase.
* Worked out way of protecting $_ variable.Kaz Kylheku2024-04-092-8/+2
| | | | | | | | | | | | | - Remove Bugs section from README. - Add new basta_uln_save global variable. We don't have to preserve its value across reloads since it is only temporarily used. - The ALRM and WINCH traps set up by basta.install_hooks are now three-command sequences which save $_ into the global, then run the handler, and the restore it using a trick involving the : null command.
* Add Bugs section to README.Kaz Kylheku2024-04-091-0/+6
| | | | - In README.md add note about the unreliable value of $_.
* Fix some wrong indentation.Kaz Kylheku2024-04-091-11/+11
| | | | | - in basta.initial_prompt_hook and basta.prompt_hook, the three space indent should be two spaces.
* Add mechanism to temporarily disable.Kaz Kylheku2023-11-282-6/+30
| | | | | | | - New functions: basta.install_hooks, basta.remove_hooks. - Mainline now calls basta.install_hooks instead of setting traps and the prompt hook at the top level.
* cleanup: kill the status alarm task.Kaz Kylheku2023-11-281-0/+1
| | | | | | | | - in basta.cleanup we kill $basta_status_alarm_pid. This is not strictly necessary because the process quits if the command kill -ALRM $$ fails. If the parent's PID got recycled, though, it would keep sending SIGALRM to the wrong process.
* bugfix: reference to nonexistent ROWS variable.Kaz Kylheku2023-11-221-1/+1
| | | | | - in basta.get_cur_line, the default answer should be obtained from $LINES, not $ROWS.
* bugfix: regression: cursor jumps to first line on startupKaz Kylheku2023-09-151-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | This is a regression caused by commit f68dc7ccb1489dabce1fd3997a7c59e39b23b4ad Date: Tue Aug 29 11:51:07 2023 -0700 Subject: bugfix: don't use $LINE to initialize basta_scroll_lines. Issue is that if we initialize basta_scroll_lines to zero, the basta.check_cursor function reacts to it, and not very well. It moves the cursor to the top of the screen. - We add a new function basta.initial_prompt_hook which is installed at startup. This function doesn't do any processing of the exit status of the previous command (there isn't one) and doesn't call basta.check_cursor. - basta.initial_prompt_hook changes the hook to basta.prompt_hook after one call. The basta_scroll_lines variable is initialized at that point, so all is well. - with this approach, there is no added run-time check for "is basta_scroll_lines initialized".
* cache date in loop.Kaz Kylheku2023-09-081-1/+2
| | | | | | | | - in the basta.update_status function we have a loop that trims the path until it fits the status line. In that loop we have no reason to be calling date on each iteration; let's sample the date once into a variable.
* bugfix: don't use $LINE to initialize basta_scroll_lines.Kaz Kylheku2023-08-291-1/+1
| | | | | | | - When a new interactive shell is launched, there is a time before the LINE variable exists, so we end up initializing basta_scroll_lines to a blank value, which causes bad syntax in the comparison [ $curln -gt $basta_scroll_lines ].
* Typo fix.Kaz Kylheku2023-08-281-1/+1
| | | | | - basta.prepare_term is calling a nonexistent function called basta.query_terminal_line.
* Refactor: absorb helper functions called once.Kaz Kylheku2023-08-271-15/+4
| | | | | | | | - The basta.calc_prev_reserved and basta.calc_current_size funtions disappear, replaced by open code in basta.prepare_term. Since basta.prepare_term calls stty rows near bottom, we don't bring in the stty rows call from basta.calc_current_size.
* Refactor: one function for getting termina lines.Kaz Kylheku2023-08-271-5/+10
| | | | | | | | | - New function: basta.query_terminal_lines. This stores the result into a variable specified by the caller. We use Bash's Korn-inspired namerefs for this to avoid eval. - basta.calc_prev_reserved and basta.calc_current_size now call this function.
* Calculate real terminal size when resize detected.Kaz Kylheku2023-08-271-0/+11
| | | | | | | | | | | | | | | | | | | | Basta should not trust that a changed value of LINES reflects the terminal size. In cases when LINES is set to a bad value, it leaves the display in a bad state: wrong scrolling region, wrong status line position. As a test, try a command like "LINES=3; stty rows $LINES". Before this change, Basta will react and move the status line to the third line, setting up a two-line scrolling region. With this change, Basta isn't fooled; it asks the terminal. - New function basta.calc_current_size interrogates the terminal to get the size, just like basta.calc_prev_preserved does. The function sets up LINES and stty rows to the discovered terminal size. - basta.prepare_term calls this function the second and subsequent time it is called.
* Refer to $basta_scroll_lines instead of $LINES.Kaz Kylheku2023-08-271-3/+4
| | | | | | | - In basta.update_status and basta.check_cursor, we don't refer to the current value of $LINES to inform us of the usable window area, but rely on our calculated basta_scroll_lines value.
* Work harder at protecting the TTY rows.Kaz Kylheku2023-08-251-2/+4
| | | | | | | | | | | | | | - New variable basta_scroll_lines tracks the correct of LINES and tty rows. - In basta.prepare_term, we set the value of this variable. Also, bugfix: we were referring to some nonexistent variables in the calculation. Luckily the bogus term existing_reserved-rows evaluated to 0. - In basta.prompt_hook we set the tty rows to basta_scroll_lines.
* Modify TTY parameters around entire prompt hook.Kaz Kylheku2023-08-251-4/+2
| | | | | | | | | | | - Rather than putting the TTY raw and then sane just in basta.check_cursor, we do that in basta.prompt_hook. This way, the bash.update_status code also runs in raw mode. This change greatly reduces the spurious echoing of typed-ahead characters, since less of our logic runs with the TTY in echo mode. When I hold down Enter to repeat it, it's almost entirely clean now; spurious blank lines are much more rarely observed.
* Improve TTY handling in basta.check_cursor.Kaz Kylheku2023-08-241-3/+2
| | | | | | | | | - We don't save and restore the TTY settings. They might not be good anyway. We go for "stty sane". - Add -echo to raw mode. I'm seeing a glitch whereby if I hold down the Enter key, sometimes I see ^M being echoed; this makes it go away.
* hack: do cursor check only if no input pendingKaz Kylheku2023-08-191-9/+24
| | | | | | | | | | | | | | | | | | | | | | | I'm addressing the following problem. Sometimes the user types a new command while a previous command is still running. This typed-ahead input is buffered in the TTY. When we execute our check to query the terminal "is the cursor out of bounds?" there is a conflict between that buffered input and the query. An imperfect fix is to check for the presence of unread input and skip doing the cursor check. This means that if the user runs some program that puts the cursor out of bounds, and impatiently types ahead before that command has completed, the cursor will go out of bounds. - We break the basta.before_prompt function into two: basta.check_cursor and basta.do_exit_status. - In basta.check_cursor, we now temporarily put the TTY into raw mode, so that the file descriptor can be polled for the presence of any bytes whatsoever. If we don't do this, read -t 0 will only report true (input is present) if the user has typed Enter, due to canonical input processing.
* Use a timeout when reading response from terminal.Kaz Kylheku2023-08-171-2/+2
| | | | | | | | | | | | | | | - In basta.get_cur_line, use a three second timeout in the read call. If we don't time out and the terminal doesn't respond in the right way or characters are lost for whatever reason (noisy serial line), the read will block forever waiting for the delimiter. - Without this change, if the user types "stty iuclc", basta locks up. The R delimiter turns into r. The only way to recover is to "stty -ilcuc < /dev/<whatever>" from another terminal and then go to the locked up session and type R.
* README: refer to ~/.bashrc rather than ~/.bash_profile.Kaz Kylheku2023-08-141-2/+2
| | | | | If Basta is sourced from ~/.bashrc, then it activates in non-login shells, which is important.
* Address resizing glitches.Kaz Kylheku2023-08-091-2/+6
| | | | | | | | | | | | | | | | | | | This is motivated by a behavior of Gnome Terminal. When the user switches tabs in Gnome Terminal, the terminal session gets a resize event, even if no resize took place. So our response to resizing must be smooth; we can't be printing a blank linke and moving the cursor. - In basta.prepare_term, we now avoid printing a blank line and moving the cursor, except when this is called for the first time. When this is called at other times, it is due to a resize, and so we don't do anything. - We now trap the SIGWINCH signal to the basta.update_status signal. This addresses the glitch that would otherwise result, because basta.update_status won't otherwise be called until the user runs a command line, and that will take place with our scrolling region reset to the full window size, clobbering the status line.
* renaming around alarm timer.Kaz Kylheku2023-08-091-4/+6
| | | | | | | | | | | | | Before or after hot-reloading this change, run the command "kill $update_status_alarm", since this will run a new background process to update the status line. - the update_status_alarm variable becomes properly namespaced as basta_status_alarm_pid and is defined at the top. - the basta.basta_alarm_timer function is renamed to basta.alarm_timer to drop the repetition.
* split status update from prompt-related logic.Kaz Kylheku2023-08-091-7/+18
| | | | | | | | | | | | | | | | | | | The status line update is not tightly connected to the prompt; it can be called at any time (and we are invoking it from an alarm handler). Therefore it shouldn't be doing any prompt- related processing. - bash.update_status now only draws the status line and restores the cursor. The alarm timer function continues to calal bash.update_status. - New function basta.before_prompt does the check whether the cursor is out-of-bounds on the prompt (and this is done first). Then it does the check whether a failed termination status should be printed. - New function basta.prompt_hook calls both of these functions, and that function is now the PROMPT_COMMAND.
* README: advice on reloading.Kaz Kylheku2023-08-081-0/+21
|
* README: Add screenshot of nested shell sessions.Kaz Kylheku2023-08-062-0/+6
|
* Bug: stray character.Kaz Kylheku2023-08-061-1/+1
| | | | - Remove stray character in basta.cleanup.
* README: update mention of update_status_line to new name.Kaz Kylheku2023-08-051-1/+1
|
* README: recommend ~/.basta.sh name.Kaz Kylheku2023-08-051-4/+5
|
* Put everything into namespace.Kaz Kylheku2023-08-051-24/+27
| | | | | | - Global variables now begin with basta_. - Functions begin with basta.
* Bugfix with restoring scrolling region.Kaz Kylheku2023-08-051-1/+6
| | | | | | | | | | | - Save and restore cursor position - Restore scrolling region to just one line more; do not use exsiting_reserved_rows in calculation. - Clear the existing status line, and print the good-bye message Basta! which will go into that space if the cursor is currently at the bottom.
* Detect existing status line and clean up on exit.Kaz Kylheku2023-08-051-2/+30
| | | | | | | | | | | | - On startup, determine how many bottom rows of the terminal are already reserved by something, and remember this value. - When resizing, observe this value; set the scrolling region such that we protect the existing one. - When terminating, restore the protection to the original one found, or else reset the scrolling region. Also bump up the stty rows again; don't leave it trimmed.
* Project renamed to Basta!Kaz Kylheku2023-08-052-8/+6
| | | | | | - README.md: text updated. - bash-prompt.sh renamed to basta.sh
* Improve background updater.Kaz Kylheku2023-08-051-4/+14
| | | | | | | | | | | | | | | | | | - We put the update loop into a function; the while loop now checks for the kill command failing, and terminates, so that if the parent shell disappears, the loop will quit, even if it doesn't get a SIGHUP. - We close the standard file descriptors. - We trap SIGINT so that runs the null command. This solves the issue that the process dies due to a TTY interrupt (Ctrl-C) because it's not a proper job control backgrounded task. - We use the Bash disown command to remove the process from Bash's job control list.
* README: explain "Kabapro".Kaz Kylheku2023-08-051-0/+2
|
* Clock updates now. Add screenshot.Kaz Kylheku2023-08-053-1/+18
|
* Add README.md file.Kaz Kylheku2023-08-041-0/+29
|
* Add license.Kaz Kylheku2023-08-041-0/+26
|