4 .
/pipeglade
-i calc.
in -o calc.out
-b -u calc.ui
-O calc.err
-l calc.log
>/dev
/null
6 NUMKEYS
=(0 1 2 3 4 5 6 7 8 9 A B C D E F
)
7 NUMPAD
=("${NUMKEYS[@]}" neg point div mul minus plus squareroot power
)
8 STORAGEKEYS
=(recall store
)
9 OTHERKEYS
=(enter edit swap
clear drop cancel
)
10 VARKEYS
=(var_2 var_3 var_a var_b var_c var_d var_e var_f var_g var_h var_i \
11 var_j var_k var_l var_m var_n var_o var_p var_q var_r var_s \
12 var_t var_u var_v var_w var_x var_y var_z
)
15 # expose second keybord level
17 for i
in "${VARKEYS[@]}"; do
18 echo "$i:set_visible $1" >calc.
in
24 echo "entry:set_placeholder_text" >calc.
in
25 # tell dc to print its stack
29 # read dc's response, which may include error messages
30 while read -t .1 DC_OUT
[$i]; do (( i
++ )); done
31 # check for specific errors
32 if [[ "${DC_OUT[0]}" =~
"stack" ||
"${DC_OUT[0]}" =~
"zero" ]]; then
33 echo "entry:set_placeholder_text ${DC_OUT[0]}"
34 echo "stack:grab_focus" # unfocussing entry
36 # display stack in a GtkTreeView
40 while [[ $i -gt 0 ]]; do
43 echo "stack:set $ROW 0 $i"
44 echo "stack:set $ROW 1 ${DC_OUT[$i]}"
46 echo "stack:scroll $ROW 1"
51 # put top of stack into GtkEntry
53 echo "p s!" # talking to dc,
54 read -t .1 DC_OUT
# reading dc's response,
55 # and sending it to pipeglade
56 echo "entry:set_text $DC_OUT" >calc.
in
60 # initial window dressing
61 echo "precision:set_value 5" >calc.
in
62 for i
in "${NUMPAD[@]}"; do
63 echo "$i:style border-radius:20px; border-color:darkblue; font-weight:bold; font-size:16px"
65 for i
in "${OTHERKEYS[@]}"; do
66 echo "$i:style border-radius:20px; font-weight:bold"
68 for i
in "${STORAGEKEYS[@]}"; do
69 echo "$i:style border-radius:20px; border-color:darkgreen; font-weight:bold"
71 for i
in "${VARKEYS[@]}"; do
72 echo "$i:style border-radius:10px; border-color:darkgreen; font-style:italic; font-size:16px"
74 echo "off:style color:darkred; border-radius:20px; border-color:darkred; font-weight:bold" >calc.
in
75 echo "entry:style font:monospace 12" >calc.
in
76 echo "main:style border-radius:20px" >calc.
in
80 # main loop; stdin and stdout are connected to the dc coprocess
83 # receive feedback from GUI
85 # if feedback came from a button, it ends ":clicked"
86 C
="${IN%:clicked}" # remove ":clicked"
87 if [[ "${#C}" -eq 1 ]]; then
88 # our digit buttons all have one-character names
89 # string the digits together
91 # and put them into our GtkEntry
92 echo "entry:set_text $NUM" >calc.
in
93 elif [[ "$IN" =~
"entry:text " ]]; then
94 # feedback from our GtkEntry
95 CURRENT_ENTRY
="${IN#entry:text }"
97 # dc uses '_' as a negative sign
98 CURRENT_ENTRY
="${CURRENT_ENTRY//-/_}"
99 elif [[ "$IN" =~
"var_" ]]; then
100 # freedback from variable buttons
102 VAR
="${VAR%:clicked}"
103 if [[ "$VARMODE" == "recall" ]]; then
105 elif [[ "$VARMODE" == "store" ]]; then
109 varkeys_set_visible
0
110 elif [[ "$IN" =~
"radix:value " ]]; then
111 # feedback from the radix scale
112 RADIX
="${IN#radix:value }"
113 RADIX
="${RADIX/.[0-9]*}"
114 # telling dc what to do
115 echo "A i $RADIX o $RADIX i"
117 # graying out meaningless digit keys
118 for i
in "${NUMKEYS[@]:2:(( $RADIX - 1 ))}"; do
119 echo "$i:set_sensitive 1" >calc.
in
121 for i
in "${NUMKEYS[@]:$RADIX}"; do
122 echo "$i:set_sensitive 0" >calc.
in
124 elif [[ $IN =~
"precision:value " ]]; then
125 # feedback from the precision scale
126 PRECISION
="${IN#precision:value }"
127 PRECISION
="${PRECISION/.[0-9]*}"
129 elif [[ $IN == "main:closed" ]]; then
130 # exit gracefully when GUI gets killed by window manager
132 elif [[ -n $C ]]; then
133 # here, $C is a multi-character button name that doesn't look like "var_x"
137 echo "entry:set_text $NUM" >calc.
in
140 if [[ -n "$CURRENT_ENTRY" ]]; then
141 echo "$CURRENT_ENTRY _1 *"
155 if [[ -n "$CURRENT_ENTRY" ]]; then
156 echo "$CURRENT_ENTRY"
157 echo "entry:set_text" >calc.
in
166 if [[ -n "$CURRENT_ENTRY" ]]; then
167 echo "$CURRENT_ENTRY"
168 echo "entry:set_text" >calc.
in
176 if [[ -n "$CURRENT_ENTRY" ]]; then
177 echo "$CURRENT_ENTRY"
178 echo "entry:set_text" >calc.
in
186 if [[ -n "$CURRENT_ENTRY" ]]; then
187 echo "$CURRENT_ENTRY"
188 echo "entry:set_text" >calc.
in
196 if [[ -n "$CURRENT_ENTRY" ]]; then
197 echo "$CURRENT_ENTRY"
198 echo "entry:set_text" >calc.
in
206 if [[ -n "$CURRENT_ENTRY" ]]; then
207 echo "$CURRENT_ENTRY"
208 echo "entry:set_text" >calc.
in
216 if [[ -n "$CURRENT_ENTRY" ]]; then
217 echo "$CURRENT_ENTRY"
218 echo "entry:set_text" >calc.
in
226 if [[ -n "$CURRENT_ENTRY" ]]; then
227 echo "$CURRENT_ENTRY"
228 echo "entry:set_text" >calc.
in
230 # portability kludge. The parentheses are dc variable names
237 if [[ -z "$CURRENT_ENTRY" ]]; then
238 # portabilty kludge (and memory leak)
241 echo "entry:set_text" >calc.
in
248 echo "entry:set_text" >calc.
in
254 varkeys_set_visible
0
255 echo "entry:set_text" >calc.
in
262 varkeys_set_visible
1
266 if [[ -n "$CURRENT_ENTRY" ]]; then
267 echo "LE: $CURRENT_ENTRY" >>ttt
268 echo "$CURRENT_ENTRY"
269 echo "entry:set_text" >calc.
in
273 varkeys_set_visible
1
276 echo "_:main_quit" >calc.
in
282 } <&"${COPROC[0]}" >&"${COPROC[1]}"