forked from rabbibotton/clog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
25-tutorial.lisp
69 lines (65 loc) · 3.14 KB
/
25-tutorial.lisp
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
;;;; In this tutorial we are going to use clog-web for a local app.
;;;;
;;;; -------------------------- -------
;;;; |ls -l | | Run |
;;;; -------------------------- -------
;;;; ---------------------------------------------------------
;;;; | ls -l |
;;;; | total 434 |
;;;; | -rw------- 1 me user 246562 Dec 8 18:20 sample1.jpeg |
;;;; | -rw------- 1 me user 160290 Dec 8 18:21 sample2.jpeg |
;;;; | |
;;;; | |
;;;; | |
;;;; | |
;;;; | |
;;;; | |
;;;; ---------------------------------------------------------
(defpackage #:clog-tut-25
(:use #:cl #:clog #:clog-web)
(:export start-tutorial))
(in-package :clog-tut-25)
(defun on-new-window (body)
(clog-web-initialize body)
(setf (title (html-document body)) "Tutorial 25")
;; Setup two sections = command and result
(let ((command-section (create-web-content body))
(results-section (create-web-content body :class "w3-monospace")))
;; Setup command section
(let* ((form (create-form command-section))
(command (create-form-element form :text :class "w3-input w3-border"
:label (create-label form
:content "Enter Command: ")))
(button (create-form-element form :submit)))
(declare (ignore button))
(set-on-submit form
(lambda (obj)
(declare (ignore obj))
(handler-case
(progn
(setf (inner-html results-section)
(format nil "~A<br><span style='color:blue'>~A</span><br>~A"
(inner-html results-section)
(value command)
(lf-to-br (uiop/run-program:run-program
(value command)
:force-shell t :output :string))))
(setf (scroll-top results-section)
(scroll-height results-section)))
(error (c)
(clog-web-alert command-section "Error" c :time-out 5)))
(setf (value command) ""))))
(setf (overflow results-section) :scroll)
(set-border results-section :thin :solid :black)
(flet ((set-height ()
(setf (height results-section) (- (inner-height (window body))
(height command-section)
20))))
(set-height)
(set-on-resize (window body) (lambda (obj)
(declare (ignore obj))
(set-height))))))
(defun start-tutorial ()
"Start turtorial."
(initialize 'on-new-window)
(open-browser))