shell.l 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. (
  2. (def ls (fn (do
  3. (split (load "/sd/") [0a])
  4. )))
  5. (def draw-logo (fn ox oy (do
  6. (def stroke-color 0xff8e)
  7. (line (pt (+ ox 16) (- oy 38)) (pt (+ ox 16) (- oy 102)))
  8. (line (pt (+ ox 16) (- oy 102)) (pt (+ ox 80) (- oy 38)))
  9. (line (pt (+ ox 80) (- oy 38)) (pt (+ ox 80) (- oy 102)))
  10. (line (pt (+ ox 80) (- oy 102)) (pt (+ ox 144) (- oy 38)))
  11. (line (pt (+ ox 144) (- oy 38)) (pt (+ ox 144) (- oy 102)))
  12. (line (pt (+ ox 144) (- oy 102)) (pt (+ ox 208) (- oy 38)))
  13. (line (pt (+ ox 208) (- oy 38)) (pt (+ ox 208) (- oy 102)))
  14. (line (pt (+ ox 208) (- oy 102)) (pt (+ ox 272) (- oy 102)))
  15. )))
  16. (draw-logo (- (/ screen-width 2) 140) (/ screen-height 2))
  17. (draw-logo (- (/ screen-width 2) 139) (/ screen-height 2))
  18. (draw-logo (- (/ screen-width 2) 140) (+ 1 (/ screen-height 2)))
  19. (send scr 0)
  20. (blit-str "Welcome to Interim OS." 32 32)
  21. (send scr 0)
  22. (def evbuf (alloc-str 4096))
  23. (def p (fn xp x y (do
  24. (write xp evbuf)
  25. (blit-str evbuf x y)
  26. )))
  27. (def keyboard (open "/keyboard"))
  28. (def term-x minx)
  29. (def term-y (+ miny 32))
  30. (def history (list))
  31. (def future (list))
  32. (def buffer "")
  33. (def history-back (fn (do
  34. (def buffer (car history))
  35. (def future (cons (car history) future))
  36. (def history (cdr history))
  37. (print (list "history:" history "future:" future))
  38. (def term-x (+ minx (* rune-spacing (strlen buffer))))
  39. (blit-str buffer minx term-y)
  40. )))
  41. (def history-forth (fn (do
  42. (def buffer (car future))
  43. (def history (cons (car future) history))
  44. (def future (cdr future))
  45. (print (list "history:" history "future:" future))
  46. (def term-x (+ minx (* rune-spacing (strlen buffer))))
  47. (blit-str buffer minx term-y)
  48. )))
  49. (def tasks (list))
  50. (def add-task (fn t (do
  51. (def tasks (cons t tasks))
  52. )))
  53. (def mouse (open "/mouse"))
  54. (def mouse-x 0)
  55. (def mouse-y 0)
  56. (def mouse-dx 0)
  57. (def mouse-dy 0)
  58. (def mouse-btn 0)
  59. (def mouse-task (fn (do
  60. (add-task (fn (do
  61. (blit-char 32 mouse-x mouse-y)
  62. (let mouse-info (recv mouse))
  63. (def mouse-dx (car (car mouse-info)))
  64. (def mouse-dy (cdr (car mouse-info)))
  65. (def mouse-x (+ mouse-x mouse-dx))
  66. (def mouse-y (+ mouse-y mouse-dy))
  67. (if (lt mouse-x 0) (def mouse-x 0) 0)
  68. (if (lt mouse-y 0) (def mouse-y 0) 0)
  69. (if (gt mouse-x maxx) (def mouse-x maxx) 0)
  70. (if (gt mouse-y maxy) (def mouse-y maxy) 0)
  71. (def mouse-btn (cdr mouse-info))
  72. (if mouse-btn (blit-char 0x219c mouse-x mouse-y)
  73. (blit-char 0x2196 mouse-x mouse-y))
  74. )))
  75. )))
  76. (def net (open "/net"))
  77. (def net-y 32)
  78. (def temp-minx minx)
  79. (def temp-maxx maxx)
  80. (def irc-msg (fn msg (do
  81. (let ircbuf (concat "PRIVMSG #nodrama.de :" msg))
  82. (send net ircbuf)
  83. (send net [0a])
  84. )))
  85. (def cmdbuf (alloc-str 512))
  86. (def cmd-read (list))
  87. (def remote-cmd (fn msg (do
  88. (let parts (split msg "$"))
  89. (if (gt (list-size parts) 1) (do
  90. (let cmd (concat (concat "(" (item parts 1)) ")"))
  91. (print (list "remote cmd" cmd))
  92. (def cmdbuf (alloc-str 512))
  93. (def cmd-read (read cmd))
  94. (write (eval cmd-read) cmdbuf)
  95. (print (list "result" cmdbuf))
  96. (irc-msg cmdbuf)
  97. ) 0)
  98. 0
  99. )))
  100. (def freenode "/net/tcp/62.231.75.133/6667")
  101. (def sternfreunde "/net/tcp/46.101.207.85/80")
  102. (def interim-os "/net/tcp/91.250.115.15/80")
  103. (def connect (fn net-path (do
  104. (def net (open net-path))
  105. )))
  106. (def net-task (fn (do
  107. (add-task (fn (do
  108. (let packet (recv net))
  109. (if (size packet) (do
  110. (def temp-minx minx)
  111. (def temp-maxx maxx)
  112. (def minx 1000)
  113. (def maxx 1700)
  114. (let msg (bytes->str packet))
  115. (boxfill 1000 net-y 716 64 0xffff)
  116. (let ofsy (+ (blit-str msg minx net-y) rune-h))
  117. (def minx temp-minx)
  118. (def maxx temp-maxx)
  119. (def net-y (+ 0 ofsy))
  120. (if (gt net-y maxy) (def net-y miny) 0)
  121. (remote-cmd msg)
  122. ) 0)
  123. )))
  124. 1
  125. )))
  126. (def http-get (fn host path (do
  127. (boxfill 1000 0 800 1000 0xffff)
  128. (let header (concat (concat "Host: " host) (bytes->str [0d0a0d0a])))
  129. (send net (concat (concat (concat (concat "GET " path) " HTTP/1.1") (bytes->str [0d0a])) header))
  130. )))
  131. (def irc-join (fn nick (do
  132. (send net "PASS *")
  133. (send net [0a])
  134. (send net (concat "NICK " nick))
  135. (send net [0a])
  136. (send net (concat "USER " (concat nick " 8 * :Interim OS")))
  137. (send net [0a])
  138. (send net "JOIN #nodrama.de")
  139. (send net [0a])
  140. )))
  141. (def task-func (fn (print "empty task-func")))
  142. (def run-tasks (fn (do
  143. (let tl tasks)
  144. (while (car tl) (do
  145. (def task-func (car tl))
  146. ; (print (list "run-task " task-func))
  147. (task-func)
  148. (let tl (cdr tl))
  149. ))
  150. )))
  151. (def ed (fn (import "/sd/os/editor.l") ))
  152. (def buffer-read (list))
  153. (def zz (fn (import "/sd/tests/gtn.l")))
  154. (def shell-running 1)
  155. (def main (fn (do
  156. (let blink 0)
  157. (while shell-running (do
  158. (let str (recv keyboard))
  159. (let c (get str 0))
  160. (if (gt c 0) (print c) 0)
  161. ; FIXME this aint working
  162. (if (* (gt c 0x1f) (not (eq 0x7f c))) (do
  163. (def term-y (blit-str str term-x term-y))
  164. (def buffer (concat buffer str))
  165. (def term-x (+ term-x rune-spacing)) ) 0)
  166. (if (eq c 9) ; tab
  167. (do
  168. (blit-char 32 term-x term-y)
  169. (def term-y (+ term-y 16))
  170. (def term-x 32) (def buffer "")) 0)
  171. (if (eq c 10) ; return
  172. (do
  173. (blit-char 32 term-x term-y)
  174. (def history (cons buffer history))
  175. (def buffer-read (list (read buffer))) ; FIXME let here crashes
  176. (let result (eval buffer-read))
  177. (def buffer "")
  178. (def term-x minx)
  179. (def term-y (+ term-y rune-h))
  180. (def term-y (+ rune-h (p result term-x term-y)))
  181. 0
  182. ) 0)
  183. (if (eq c 17) ; cursor up
  184. (history-back) 0)
  185. (if (eq c 18) ; cursor down
  186. (history-forth) 0)
  187. (if (eq c 0x7f) ; bksp
  188. (if (gt (strlen buffer) 0)
  189. (do
  190. (blit-char 32 term-x term-y)
  191. (def term-x (- term-x rune-spacing))
  192. (let nl (- (strlen buffer) 1))
  193. (def buffer (substr buffer 0 nl)) ) 0) 0)
  194. (if (gt term-x maxx) (do (def term-x minx) (def term-y (+ term-y rune-h))) 0)
  195. (if (gt term-y maxy) (def term-y miny) 0)
  196. (if (lt term-x 32) (def term-x minx) 0)
  197. (if (eq blink 3)
  198. (blit-char 0x2588 term-x term-y) 0)
  199. (if (eq blink 0)
  200. (blit-char 32 term-x term-y) 0)
  201. (let blink (% (+ blink 1) 5))
  202. (run-tasks)
  203. (send scr 0)
  204. (gc)
  205. ))
  206. )))
  207. (main)
  208. )