Skip to content

Commit

Permalink
bash file fixes for stty issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Ward committed Aug 23, 2024
1 parent 6d18558 commit fe96b80
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions mettalog
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,39 @@ fi


# Capture original auto margins setting and terminal size
original_automargins=$(stty -a | grep -o 'onlcr' || echo 'off')
original_size=$(stty size)
original_rows=$(echo $original_size | cut -d ' ' -f1)
original_cols=$(echo $original_size | cut -d ' ' -f2)
if [ -t 0 ] ; then
original_automargins=$(stty -a | grep -o 'onlcr' || echo 'off')
original_size=$(stty size)
original_rows=$(echo $original_size | cut -d ' ' -f1)
original_cols=$(echo $original_size | cut -d ' ' -f2)
fi

# Function to reset auto margins and terminal size to their original state
reset_settings() {
# Reset auto margins to original state
if [ "$original_automargins" == "on" ]; then
stty onlcr
else
stty -onlcr
fi
if [ -t 0 ] ; then
# Reset auto margins to original state
if [ "$original_automargins" == "on" ]; then
stty onlcr
else
stty -onlcr
fi

# Reset terminal size to original
echo -ne "\e[8;${original_rows};${original_cols}t"
stty cols "$original_cols"
tput smam
echo "Settings reset to original."
# Reset terminal size to original
echo -ne "\e[8;${original_rows};${original_cols}t"
stty cols "$original_cols"
tput smam
echo "Settings reset to original."
fi
}

# Function to disable auto margins and set terminal width to 999 columns
disable_automargins() {
stty -onlcr # Disable auto margins
tput rmam
stty cols 999 # Set columns to a large number to prevent wrapping
echo "Auto margins disabled, terminal width set to 999 columns."
if [ -t 0 ] ; then
stty -onlcr # Disable auto margins
tput rmam
stty cols 999 # Set columns to a large number to prevent wrapping
echo "Auto margins disabled, terminal width set to 999 columns."
fi
}

# Function to set traps for clean exit and interruption
Expand Down Expand Up @@ -901,7 +907,9 @@ TEMP_EXIT_CODE_FILE="$(mktemp)"

# Set a trap to ensure stty sane is run on script exit or interruption
cleanup() {
stty sane
if [ -t 0 ] ; then
stty sane
fi
if [[ -f "$TEMP_EXIT_CODE_FILE" ]]; then
METTA_CMD_EXIT_STATUS=$(<"$TEMP_EXIT_CODE_FILE")
else
Expand Down

0 comments on commit fe96b80

Please sign in to comment.