Welcome, guest | Sign In | My Account | Store | Cart

Hi all...

Do you remember this little snippet?

http://code.activestate.com/recipes/578079-pure-fun-for-text-mode-python/?in=user-4177147

Well it was voted down, but who cares? I surely don't! So to those that voted this FUN piece of Python coding down, you are now about to see what the aim was.

However although I have subsequently done what I said I would, that is, to create large digits as an _at_a_glance_ digital readout for a project in Python I have decided not to upload it. However I have decided to let this one go as a bash/shell script instead.

It is a nothing but a simple clock, well, maybe not that simple; but as I am into shell stuff at the moment I thought I would share this with you.

The terminal does have its colours changed and the cursor disabled for the session but I expect you big guns to be able to return back to normal in a jiffy.

I am an amateur coder and if that is easy for me then you pros should have no problems.

This code is not like most of my other stuff as is NOT Public Domain...

It is only a DEMO to see what an at a glance display would look like in a terminal.

Move away to a distance and see which of the two time readings you can still read... ;o)

It is for a Macbook Pro 13" OSX 10.7.5 and uses bash imode. It will probably work on most Linux machines too but I haven't tested it...

This is purely a DEMO only and any other special effects, (e.g. flashing colon every second), alram, etc, I have already experimented with and is easy enough to do...

My intention is to use this as a kids level text mode digital voltmeter I am doing.

Enjoy...

Bazza...

Bash, 337 lines
  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
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/bin/bash
#
# Clock_DEMO.sh
# A bash DEMO to create a 6 x 7 character set using the whitespace character.
# It is a functional digital clock but this is not important as I want this
# method for an _at_a_glance_ digital display for a kids level shell digital
# voltmeter I am in the process of doing.
#
# The clock in normal size is white on black near the top. The extra large clock
# is green on black and in the centre of the terminal..
#
# $VER: Clock.sh_Version_1.00.00_(C)2013_B.Walker_G0LCU.
#
# Written so the anyone can understand how it works.

# Set the window to white foreground on black background.
printf "\x1B[0;37;40m"
clear
# Remove the cursor.
tput civis
# Set up all _variables_ as is required.
TIME=`date "+%H:%M"`
char="0"
# The plot _variable_ "p".
p="(C)2013, B.Walker, G0LCU."
# The background colours.
bg="\x1B[0;37;40m"
# The foreground colours.
fg="\x1B[0;37;42m"
# The initial character plotting points.
horiz=10
vert=9
# This function reads the time and stores it in "TIME".
clock()
{
	TIME=`date "+%H:%M"`
	printf "\x1B[2;32f$bg The time is $TIME.\n"
}
# This function is required to coreectly print out the large characters.
plot()
{
	p="\x1B["$vert";"$horiz"f"
	vert=$[ ( $vert + 1 ) ]
}
# *********************************************************
# The eleven characters required for this DEMO are 0 to 9
# and the : colon character.
zero()
{
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$fg $bg  $fg  $bg "
	plot
	printf "$p$fg $bg $fg $bg $fg $bg "
	plot
	printf "$p$fg  $bg  $fg $bg "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
}
one()
{
	plot
	printf "$p$bg   $fg $bg  "
	plot
	printf "$p$bg  $fg  $bg  "
	plot
	printf "$p$bg   $fg $bg  "
	plot
	printf "$p$bg   $fg $bg  "
	plot
	printf "$p$bg   $fg $bg  "
	plot
	printf "$p$bg   $fg $bg  "
	plot
	printf "$p$bg  $fg   $bg "
}
two()
{
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg    $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg     "
	plot
	printf "$p$fg $bg     "
	plot
	printf "$p$fg     $bg "
}
three()
{
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg    $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$bg    $fg $bg "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
}
four()
{
	plot
	printf "$p$bg   $fg $bg  "
	plot
	printf "$p$bg  $fg  $bg  "
	plot
	printf "$p$bg $fg $bg $fg $bg  "
	plot
	printf "$p$fg $bg  $fg $bg  "
	plot
	printf "$p$fg     $bg "
	plot
	printf "$p$bg   $fg $bg "
	plot
	printf "$p$bg   $fg $bg "
}
five()
{
	plot
	printf "$p$fg     $bg "
	plot
	printf "$p$fg $bg     "
	plot
	printf "$p$fg $bg     "
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$bg    $fg $bg "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
}
six()
{
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg     "
	plot
	printf "$p$fg $bg     "
	plot
	printf "$p$fg    $bg  "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
}
seven()
{
	plot
	printf "$p$fg     $bg "
	plot
	printf "$p$bg    $fg $bg "
	plot
	printf "$p$bg   $fg $bg  "
	plot
	printf "$p$bg  $fg $bg   "
	plot
	printf "$p$bg $fg $bg    "
	plot
	printf "$p$fg $bg     "
	plot
	printf "$p$fg $bg     "
}
eight()
{
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
}
nine()
{
	plot
	printf "$p$bg $fg   $bg  "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$fg $bg   $fg $bg "
	plot
	printf "$p$bg $fg    $bg "
	plot
	printf "$p$bg    $fg $bg "
	plot
	printf "$p$bg    $fg $bg "
	plot
	printf "$p$bg $fg   $bg  "
}
colon()
{
	plot
	printf "$p$bg      "
	plot
	printf "$p$bg      "
	plot
	printf "$p$bg  $fg $bg   "
	plot
	printf "$p$bg      "
	plot
	printf "$p$bg  $fg $bg   "
	plot
	printf "$p$bg      "
	plot
	printf "$p$bg      "
}
# End of the character set.
# *********************************************************
# Print all of these characters first just to display them.
# This will last for 5 seconds only...
# Done longhand purely for fun...
horiz=10
vert=9
zero
horiz=16
vert=9
one
horiz=22
vert=9
two
horiz=28
vert=9
three
horiz=34
vert=9
four
horiz=40
vert=9
five
horiz=46
vert=9
six
horiz=52
vert=9
seven
horiz=58
vert=9
eight
horiz=64
vert=9
nine
horiz=70
vert=9
colon
# Now display the clock in the normal character size...
clock
sleep 5
# Now clear the screen and display the big digits.
clear
while true
do
	clock
	for subscript in $( seq 0 1 4)
	do
		# Take each character in turn and do the plots of them.
		char="${TIME:${subscript}:1}"
		horiz=$[ ( 26 + ( $subscript * 6 ) ) ]
		vert=9
		if [ "$char" == ":" ]
		then
			colon
		fi
		if [ "$char" == "0" ]
		then
			zero
		fi
		if [ "$char" == "1" ]
		then
			one
		fi
		if [ "$char" == "2" ]
		then
			two
		fi
		if [ "$char" == "3" ]
		then
			three
		fi
		if [ "$char" == "4" ]
		then
			four
		fi
		if [ "$char" == "5" ]
		then
			five
		fi
		if [ "$char" == "6" ]
		then
			six
		fi
		if [ "$char" == "7" ]
		then
			seven
		fi
		if [ "$char" == "8" ]
		then
			eight
		fi
		if [ "$char" == "9" ]
		then
			nine
		fi
	done
	sleep 1
done
# There is no code to clean up the terminal for this session in this DEMO.
# It is SOOO easy to do it manually that I expect you to be able to do
# that yourselves.
# Enjoy finding simple solutions to often very difficult questions.

The Python version will be uploaded elsewhere when I decide to release it...

Enjoy finding simple solutions to often very difficult problems...

Bazza, G0LCU...

1 comment

Barry Walker (author) 10 years, 9 months ago  # | flag

This is what it looks like:-

http://wisecracker.host22.com/public/Clock.jpg

Enjoy...