PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/red-system/tests/hello.reds

http://github.com/dockimbel/Red
Unknown | 109 lines | 96 code | 13 blank | 0 comment | 0 complexity | f12f446cefaf6672bb611ff99468b657 MD5 | raw file
  1Red/System [
  2	Title:   "Red/System small demo app"
  3	Author:  "Nenad Rakocevic"
  4	File: 	 %hello.reds
  5	Rights:  "Copyright (C) 2011 Nenad Rakocevic. All rights reserved."
  6	License: "BSD-3 - https://github.com/dockimbel/Red/blob/master/BSD-3-License.txt"
  7]
  8
  9#either OS = 'Windows [
 10	#import [
 11		"kernel32.dll" stdcall [
 12			SetConsoleTextAttribute: "SetConsoleTextAttribute" [
 13				handle 		[integer!]
 14				attributes  [integer!]
 15				return:		[integer!]
 16			]
 17		]
 18	]
 19	
 20	set-pen-color: func [color [integer!]][
 21		SetConsoleTextAttribute stdout color
 22	]
 23
 24	black:   0
 25	blue: 	 1
 26	green:	 2
 27	red:	 4
 28][
 29	set-pen-color: func [color [integer!]][
 30		either color = white [
 31			print "^[[0m"
 32		][ 
 33			print [
 34				"^[[" either color >= 7 [1][0] ";3"
 35				color and 7	"m"					;-- mask only right 3 bits for color
 36			]
 37		]
 38	]
 39	
 40	black:   0
 41	red: 	 1
 42	green:	 2
 43	blue:	 4
 44]
 45
 46cyan:  	 blue or green
 47magenta: blue or red
 48yellow:  green or red
 49white:   blue or green or red
 50
 51light-blue:  blue  or 8
 52light-green: green or 8
 53light-red: 	 red   or 8
 54
 55print-logo: does [
 56	set-pen-color light-red
 57	print "R"
 58	set-pen-color white
 59	print "ed"
 60]
 61
 62draw-hline: func [size [integer!] alt [integer!] /local c [integer!]][
 63	c: size							;-- local variable is not necessary, just for the demo
 64	until [
 65		either positive? alt [		;-- print * and - alternatively
 66			alt: either alt = 1 [
 67				print "*"
 68				2
 69			][
 70				print "-" 
 71				1
 72			]
 73		][
 74			print "-"				;-- print - only
 75		]
 76		c: c - 1
 77		zero? c
 78	]
 79	print newline
 80]
 81
 82draw-vline: does [print "|"]
 83
 84pad: func [n [integer!]][
 85	while [n > 0][print space n: n - 1] ;-- could have used UNTIL, just for the demo
 86]
 87
 88banner: func [width [integer!]][
 89	draw-hline width 1
 90	draw-vline
 91	pad (width - 16) / 2 - 1
 92	print "Hello " 
 93	print-logo
 94	print " World!"
 95	pad ((width - 16) / 2) - 1		;-- just showing nested parenthesis support
 96	draw-vline
 97	print newline
 98	draw-hline width 0
 99]
100
101print-logo
102print ["/System v0.2.3 beta" lf lf]
103
104size: 20
105until [
106	banner size
107	size: size + 2
108	size = 40
109]