Вот мой сценарий center.sh
:
#!/bin/bash
readarray message < <(expand)
width="${1:-$(tput cols)}"
margin=$(awk -v "width=$width" '
{ max_len = length > width ? width : length > max_len ? length : max_len }
END { printf "%" int((width - max_len + 1) / 2) "s", "" }
' <<< "${message[@]}")
printf "%s" "${message[@]/#/$margin}"
Как это работает:
stdin
в массиве сообщение
после преобразования таблиц в пробелы (благодаря @NominalAnimal) width
. Если параметр не указан, используется фактическая ширина клеммы.
на awk
, чтобы создать левое поле в виде строки пробелов, которая помещается в переменную margin
. { {1}}
max_len
, длину самой длинной строки ввода (ограниченную до width
) (ширина - max_len) / 2
символов пробела сообщения
после добавления к ним поля
Тест:
$ fortune | cowthink | center.sh
_______________________________________
( English literature's performing flea. )
( )
( -- Sean O'Casey on P. G. Wodehouse )
---------------------------------------
o ^__^
o (oo)\_______
(__)\ )\/\
||----w |
|| ||
$ echo $'|\tTAB\t|' | center.sh 20
| TAB |
$ echo "A line exceeding the maximum width" | center.sh 10
A line exceeding the maximum width
Наконец, если вы хотите завершить отображение разделительной линией, как в вашем скрипте Python, добавьте эту строку перед последней командой printf
:
message+=( $(IFS=''; sed s/./─/g <<< "${message[*]}" | sort | tail -n1)$'\n' )
Она заменяет каждый символ в каждой строке с ─
, выберите самый длинный с помощью sort | tail -n1
и добавьте его в конец сообщения.
Тест:
$ fortune | center.sh 60
Tuesday is the Wednesday of the rest of your life.
──────────────────────────────────────────────────
Если я прав, это может помочь:
Создать этот файл:
xorg.conf.new2
Скопируйте и вставьте с помощью вашего редактора, например. nano
следующее:
Section "ServerLayout"
Identifier "X.org Configured"
Screen 0 "Screen0" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection
Section "Files"
ModulePath "/usr/lib/xorg/modules"
FontPath "/usr/share/fonts/X11/misc"
FontPath "/usr/share/fonts/X11/cyrillic"
FontPath "/usr/share/fonts/X11/100dpi/:unscaled"
FontPath "/usr/share/fonts/X11/75dpi/:unscaled"
FontPath "/usr/share/fonts/X11/Type1"
FontPath "/usr/share/fonts/X11/100dpi"
FontPath "/usr/share/fonts/X11/75dpi"
FontPath "built-ins"
EndSection
Section "Module"
Load "glx"
EndSection
Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
EndSection
Section "InputDevice"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/input/mice"
Option "ZAxisMapping" "4 5 6 7"
EndSection
Section "Monitor"
Identifier "Monitor0"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
EndSection
Section "Device"
Identifier "Card0"
Driver "amdgpu"
BusID "PCI:0:1:0"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
SubSection "Display"
Viewport 0 0
Depth 1
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 4
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 8
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 15
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 16
EndSubSection
SubSection "Display"
Viewport 0 0
Depth 24
EndSubSection
EndSection
Сохраните файл где угодно, например. как:
/root/xorg.conf.new2
И выполнить:
X -config /root/xorg.conf.new2
Тогда:
sudo cp /root/xorg.conf.new2 /etc/X11/xorg.conf
И перезапустите с помощью:
sudo reboot
У меня была точно такая же проблема.
Случайное обновление с 3.16 до 4.9. После обновления при загрузке на новую версию показывало:
[FAILED] failed to start light display manager
Но предыдущая версия работала нормально.
У меня есть графическая карта NVIDIA GeForce GTX 750 Ti. Поэтому я очень подозреваю, что проблема связана с выделенной графической картой.
С этим подозрением я просто скачал новейшие драйвера NVIDIA с официальной страницы, установил их, и все заработало нормально. Вы можете сделать то же самое с драйверами AMD. Чтобы установить драйверы, мне пришлось установить новые заголовки :
.apt-get install linux-headers-$(uname -r)