/red-system/tests/hello.reds

http://github.com/dockimbel/Red · Redscript · 109 lines · 96 code · 13 blank · 0 comment · 9 complexity · f12f446cefaf6672bb611ff99468b657 MD5 · raw file

  1. Red/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. #either OS = 'Windows [
  9. #import [
  10. "kernel32.dll" stdcall [
  11. SetConsoleTextAttribute: "SetConsoleTextAttribute" [
  12. handle [integer!]
  13. attributes [integer!]
  14. return: [integer!]
  15. ]
  16. ]
  17. ]
  18. set-pen-color: func [color [integer!]][
  19. SetConsoleTextAttribute stdout color
  20. ]
  21. black: 0
  22. blue: 1
  23. green: 2
  24. red: 4
  25. ][
  26. set-pen-color: func [color [integer!]][
  27. either color = white [
  28. print "^[[0m"
  29. ][
  30. print [
  31. "^[[" either color >= 7 [1][0] ";3"
  32. color and 7 "m" ;-- mask only right 3 bits for color
  33. ]
  34. ]
  35. ]
  36. black: 0
  37. red: 1
  38. green: 2
  39. blue: 4
  40. ]
  41. cyan: blue or green
  42. magenta: blue or red
  43. yellow: green or red
  44. white: blue or green or red
  45. light-blue: blue or 8
  46. light-green: green or 8
  47. light-red: red or 8
  48. print-logo: does [
  49. set-pen-color light-red
  50. print "R"
  51. set-pen-color white
  52. print "ed"
  53. ]
  54. draw-hline: func [size [integer!] alt [integer!] /local c [integer!]][
  55. c: size ;-- local variable is not necessary, just for the demo
  56. until [
  57. either positive? alt [ ;-- print * and - alternatively
  58. alt: either alt = 1 [
  59. print "*"
  60. 2
  61. ][
  62. print "-"
  63. 1
  64. ]
  65. ][
  66. print "-" ;-- print - only
  67. ]
  68. c: c - 1
  69. zero? c
  70. ]
  71. print newline
  72. ]
  73. draw-vline: does [print "|"]
  74. pad: func [n [integer!]][
  75. while [n > 0][print space n: n - 1] ;-- could have used UNTIL, just for the demo
  76. ]
  77. banner: func [width [integer!]][
  78. draw-hline width 1
  79. draw-vline
  80. pad (width - 16) / 2 - 1
  81. print "Hello "
  82. print-logo
  83. print " World!"
  84. pad ((width - 16) / 2) - 1 ;-- just showing nested parenthesis support
  85. draw-vline
  86. print newline
  87. draw-hline width 0
  88. ]
  89. print-logo
  90. print ["/System v0.2.3 beta" lf lf]
  91. size: 20
  92. until [
  93. banner size
  94. size: size + 2
  95. size = 40
  96. ]