-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient
More file actions
executable file
·46 lines (39 loc) · 988 Bytes
/
client
File metadata and controls
executable file
·46 lines (39 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
get_size(){ read -r LINES COLUMNS < <(stty size); }
send(){ echo -e "\r\e[K$u> $cht" >&3; }
client(){
printf '\e[%sH' "$LINES"
while IFS= read -rsn1 -p $'\r\e[K'"-- NORMAL -- ($u): " chat; do
case $chat in
i) compose ;;
q) exit ;;
esac
done
}
compose(){
while IFS= read -rsn1 -p $'\r\e[K'"-- INSERT -- ($u): $cht" chat; do
printf '\e[%sH' "$LINES"
case "$chat" in
$'\177') [[ $cht ]] && { echo "delete" >&3; cht="${cht%?}"; } ;;
$'\033') send; break ;;
$'\015'|'') send; echo "enter" >&3; cht="" ;;
" "|*) cht+="$chat" ;;
esac
send
done
}
main(){
trap 'exec 3-&-' EXIT
#trap "printf '\e[?1049l'" EXIT
#printf '\e[?1049h'
trap "printf '\e[m\e[2J\e[H\e[?25h'" EXIT
trap "get_size" WINCH
server=chat
exec 3>$server
[[ $1 ]] && u="$1" || read -p "Choose a username: " u
echo -e "\n\r\e[K$u er tilføjet\n" >&3
echo -e "useradd" >&3
client
}
clear
main "$@"