git.s-ol.nu alive / 8b9d1ac
add wxLua alv-wx s-ol 1 year, 2 months ago
6 changed file(s) with 239 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
2525 --- create a new Copilot.
2626 -- @classmethod
2727 -- @tparam string file name/path of the alive file to watch and execute
28 new: (@file) =>
28 new: (file) =>
2929 @registry = Registry!
30 @eval_stream, @run_stream = io.stderr, io.stdout
31 @open file if file
32
33 open: (file) =>
34 mode = lfs.attributes file, 'mode'
35 if mode != 'file'
36 error "not a file: #{file}"
3037
3138 @last_modification = 0
32
33 mode = lfs.attributes @file, 'mode'
34 if mode != 'file'
35 error "not a file: #{@file}"
39 @file = file
3640
3741 --- members
3842 -- @section members
3943
4044 --- poll for changes and tick.
4145 tick: =>
46 return unless @file
47
4248 @poll!
4349
4450 if @root
7581 return
7682
7783 if @last_modification < modification
78 L.stream = io.stderr
84 L.stream = @eval_stream
7985 L\log "#{@file} changed at #{modification}"
8086 @eval!
81 L.stream = io.stdout
87 L.stream = @run_stream
8288 @last_modification = os.time!
8389
8490 {
88 error msg
99 a, msg, ...
1010
11 version = require 'alv.version'
1112 import Logger from require 'alv.logger'
1213 import ValueStream, EventStream, IOStream from require 'alv.stream'
1314 import Result from require 'alv.result'
2728
2829 --- exports
2930 -- @table exports
31 -- @tfield version version
3032 -- @tfield ValueStream ValueStream
3133 -- @tfield EventStream EventStream
3234 -- @tfield IOStream IOStream
4244 -- @tfield Scope globals global definitons
4345 -- @tfield parse function to turn a `string` into a root `Cell`
4446 {
47 :version
48
4549 :ValueStream, :EventStream, :IOStream
4650 :Cell, :RootCell
4751 :Result, :Scope, :Error
+0
-20
bin/alv-copilot less more
0 #!/bin/sh
1 set -e
2
3 tmpdir=$(mktemp -d)
4 trap 'rm -rf "$tmpdir"' EXIT INT TERM HUP
5
6 ARGS=$*
7 FIFO=$tmpdir/fifo
8 CONF=$tmpdir/conf
9
10 cat > "$CONF" << 'EOF'
11 split
12 screen -t evaltime sh -c 'tty > "$FIFO"; read done < "$FIFO"; screen -X quit'
13 focus
14 screen -t runtime sh -c 'read tty < "$FIFO"; "alv" $ARGS 2> "$tty"; echo "[press enter to exit]"; read prompt; screen -X quit'
15 EOF
16
17 mkfifo "$FIFO"
18 export FIFO ARGS
19 exec screen -mc "$CONF"
0 #!/usr/bin/env moon
1 import Copilot, Logger, version from require 'alv'
2 import sleep from require 'system'
3
4 require 'wx'
5 import
6 wxID_ABOUT, wxID_OPEN, wxID_EXIT, wxID_ANY, wxVERTICAL,
7 wxFrame, wxMenuBar, wxMenu, wxPanel, wxBoxSizer, wxTextCtrl, wxSplitterWindow
8 from wx
9
10 STARTSTOP = 100
11
12 class GUIStream
13 new: (@ctrl) =>
14
15 write: (...) =>
16 message = table.concat {...}, ''
17 @ctrl\AppendText message
18
19 flush: =>
20
21 class GUICopilot extends Copilot
22 new: (...) =>
23 super ...
24
25 @app = wx.wxGetApp!
26 @app.VendorName = 'alive'
27 @app.AppName = 'alive wxCopilot'
28
29 fileMenu = wxMenu {
30 { wxID_ABOUT, '&About', 'About alive wxCopilot' }
31 { wxID_OPEN, '&Open\tCtrl-O', 'Open Script' }
32 { }
33 { wxID_EXIT, 'E&xit\tCtrl-Q', 'Exit Program' }
34 }
35 runMenu = wxMenu {
36 { STARTSTOP, '&Start/Stop\tCtrl-P', 'Start/Stop Script Execution' }
37 }
38 @menuBar = with wxMenuBar!
39 \Append fileMenu, '&File'
40 \Append runMenu, '&Run'
41
42 @frame = wxFrame wx.NULL, wxID_ANY, @app\GetAppName!
43 @frame\SetMenuBar @menuBar
44 @status = @frame\CreateStatusBar 1
45
46 @update_status!
47
48 splitter = wxSplitterWindow @frame, wx.wxID_ANY
49
50 eval, ctrl = @mkPanel splitter, 'eval-time messages'
51 @eval_stream = GUIStream ctrl
52
53 run, ctrl = @mkPanel splitter, 'run-time messages'
54 @run_stream = GUIStream ctrl
55
56 splitter\SetMinimumPaneSize 60
57 splitter\SplitHorizontally eval, run, 0
58
59 sizer = with wxBoxSizer wx.wxVERTICAL
60 \Add splitter, 1, wx.wxEXPAND + wx.wxALL, 10
61
62 @frame\SetAutoLayout true
63 @frame\SetSizer sizer
64 @frame\Show true
65
66 @frame\Connect wxID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, @\do_about
67 @frame\Connect wxID_OPEN, wx.wxEVT_COMMAND_MENU_SELECTED, @\do_open
68 @frame\Connect wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED, -> @frame\Close!
69 @frame\Connect STARTSTOP, wx.wxEVT_COMMAND_MENU_SELECTED, @\do_startstop
70 @frame\Connect wxID_ANY, wx.wxEVT_IDLE, @\do_idle
71
72 do_about: =>
73 wx.wxMessageBox "alive #{version.tag} wxCopilot.
74
75 built using #{wxlua.wxLUA_VERSION_STRING} on #{wx.wxVERSION_STRING}",
76 "About wxCopilot",
77 wx.wxOK + wx.wxICON_INFORMATION,
78 @frame
79
80 do_open: =>
81 dialog = wx.wxFileDialog @frame, 'Change Script', '', '',
82 'Alive scripts (*.alv)|*.alv|All files (*)|*',
83 wx.wxFD_OPEN + wx.wxFD_FILE_MUST_EXIST
84
85 if dialog\ShowModal! == wx.wxID_OK
86 @paused = false
87 @open dialog\GetPath!
88 @update_status!
89
90 dialog\Destroy!
91
92 do_startstop: (event) =>
93 if @file
94 @paused = not @paused
95 @update_status!
96
97 do_idle: (event) =>
98 if @file and not @paused
99 event\RequestMore true
100 @tick!
101
102 update_status: =>
103 startstop = @menuBar\FindItem STARTSTOP
104 if not @file
105 @status\SetStatusText "No script loaded."
106 startstop\Enable false
107 else
108 startstop\Enable true
109 if @paused
110 @status\SetStatusText "Paused."
111 else
112 @status\SetStatusText "Running."
113
114 mkPanel: (parent, name) =>
115 panel = wxPanel parent, wxID_ANY
116 sizer = wxBoxSizer wxVERTICAL
117 panel\SetSizer sizer
118
119 sizer\Add wx.wxStaticText panel, wx.wxID_ANY, name
120 log = wxTextCtrl panel, wxID_ANY, '', wx.wxDefaultPosition,
121 wx.wxDefaultSize, wx.wxTE_MULTILINE + wx.wxTE_READONLY
122 sizer\Add log, 1, wx.wxEXPAND | wx.wxBOTTOM, 5
123
124 panel, log
125
126 arguments, key = {}
127 for a in *arg
128 if match = a\match '^%-%-(.*)'
129 key = match
130 arguments[key] = true
131 elseif key
132 arguments[key] = a
133 key = nil
134 else
135 table.insert arguments, a
136
137 copilot = GUICopilot arguments[1]
138 Logger.init arguments.log, copilot.eval_stream
139 copilot.app\MainLoop!
8989 },
9090 bin = {
9191 "bin/alv",
92 "bin/alv-copilot"
92 "bin/alv-wx"
9393 },
9494 },
9595 }
0 package = "alive"
1 version = "scm-2"
2
3 source = {
4 url = "git://github.com/s-ol/alive.git",
5 }
6
7 description = {
8 summary = "Experimental livecoding environment with persistent expressions",
9 detailed = [[
10 This is an experimental livecoding language and environment, in which
11 expressions persist and update until they are removed from the source code, and
12 the interpreter keeps no state that you cannot manipulate directly in the
13 source. This yields a direct-manipulation like experience with a purely
14 text-based language and works without special editor support.]],
15 homepage = "https://alive.s-ol.nu",
16 license = "GPL-3",
17 }
18
19 dependencies = {
20 "lua >= 5.3",
21 "moonscript >= 0.5.0",
22 "lpeg ~> 0.10",
23 "luafilesystem",
24 "luasystem",
25 "luasocket",
26 "osc",
27 }
28
29 build = {
30 type = "builtin",
31 modules = {},
32 copy_directories = { "docs" },
33 install = {
34 lua = {
35 ["alv.ast"] = "alv/ast.moon",
36 ["alv.base.builtin"] = "alv/base/builtin.moon",
37 ["alv.base.fndef"] = "alv/base/fndef.moon",
38 ["alv.base.init"] = "alv/base/init.moon",
39 ["alv.base.input"] = "alv/base/input.moon",
40 ["alv.base.match"] = "alv/base/match.moon",
41 ["alv.base.op"] = "alv/base/op.moon",
42 ["alv.builtin"] = "alv/builtin.moon",
43 ["alv.cell"] = "alv/cell.moon",
44 ["alv.copilot"] = "alv/copilot.moon",
45 ["alv.cycle"] = "alv/cycle.moon",
46 ["alv.error"] = "alv/error.moon",
47 ["alv.init"] = "alv/init.moon",
48 ["alv.invoke"] = "alv/invoke.moon",
49 ["alv.logger"] = "alv/logger.moon",
50 ["alv.parsing"] = "alv/parsing.moon",
51 ["alv.registry"] = "alv/registry.moon",
52 ["alv.result"] = "alv/result.moon",
53 ["alv.scope"] = "alv/scope.moon",
54 ["alv.stream.base"] = "alv/stream/base.moon",
55 ["alv.stream.event"] = "alv/stream/event.moon",
56 ["alv.stream.init"] = "alv/stream/init.moon",
57 ["alv.stream.io"] = "alv/stream/io.moon",
58 ["alv.stream.value"] = "alv/stream/value.moon",
59 ["alv.tag"] = "alv/tag.moon",
60 ["alv.version"] = "alv/version.moon",
61
62 ["alv-lib.logic"] = "alv-lib/logic.moon",
63 ["alv-lib.math"] = "alv-lib/math.moon",
64 ["alv-lib.midi"] = "alv-lib/midi.moon",
65 ["alv-lib.midi.core"] = "alv-lib/midi/core.moon",
66 ["alv-lib.midi.launchctl"] = "alv-lib/midi/launchctl.moon",
67 ["alv-lib.osc"] = "alv-lib/osc.moon",
68 ["alv-lib.pilot"] = "alv-lib/pilot.moon",
69 ["alv-lib.random"] = "alv-lib/random.moon",
70 ["alv-lib.sc"] = "alv-lib/sc.moon",
71 ["alv-lib.string"] = "alv-lib/string.moon",
72 ["alv-lib.time"] = "alv-lib/time.moon",
73 ["alv-lib.util"] = "alv-lib/util.moon",
74 },
75 bin = {
76 "bin/alv",
77 "bin/alv-wx"
78 },
79 },
80 }