61 lines
1.3 KiB
Bash
Executable File
61 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
if [[ "$1" == '' ]]; then
|
|
echo "usage: $0 <train_id>"
|
|
fi
|
|
|
|
source func.sh
|
|
|
|
function drawLine() {
|
|
printf "%"$1"s" | tr ' ' '*'
|
|
echo ""
|
|
}
|
|
|
|
getTrainInfo $1
|
|
getCurrentStation res currentId
|
|
|
|
declare -A start_station end_station current_station
|
|
|
|
parseStationInfo "${res[0]}" start_station
|
|
parseStationInfo "${res[-1]}" end_station
|
|
parseStationInfo "${res[$currentId]}" current_station
|
|
|
|
declare -A train
|
|
train[name]="${start_station[train_number]}"
|
|
train[from]="${start_station[name]}"
|
|
train[to]="${end_station[name]}"
|
|
train[current]="${current_station[name]}"
|
|
train[delay]="${current_station}"
|
|
|
|
display+=("${train[name]}")
|
|
display+=("${train[from]} ---> ${train[to]}")
|
|
display+=("")
|
|
display+=("${train[current]} (${current_station[arrival]} - ${current_station[departure]})")
|
|
display+=("Delayed: ${current_station[arrival_delay]}")
|
|
display+=("")
|
|
display+=("Luna is cute:3")
|
|
|
|
|
|
for i in "${display[@]}"; do
|
|
length=$(wc -m <<< "$i")
|
|
if [[ "$length" -gt "$maxlength" ]]; then
|
|
maxlength=$length
|
|
fi
|
|
done
|
|
maxlength=$((maxlength-1))
|
|
|
|
for (( i=0; i<${#display[@]}; i++ )); do
|
|
l="$(wc -m <<< "${display[$i]}")"
|
|
space=$(((maxlength-l)/2))
|
|
display[$i]="$(printf "%"$space"s")${display[$i]}$(printf "%"$space"s")"
|
|
done
|
|
|
|
drawLine $maxlength
|
|
|
|
IFS=$'\n'
|
|
for i in "${display[@]}"; do
|
|
echo "$i"
|
|
done
|
|
|
|
drawLine $maxlength
|