diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-04-19 15:02:54 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-04-19 15:02:54 +0000 |
| commit | 8b9d1ac65083c201d4ce86d1c6950ea02d7b95f3 (patch) | |
| tree | d550ea40181899ea3aa601728f7afdd04ea4cb7b /bin | |
| parent | also pack source rocks (diff) | |
| download | alive-8b9d1ac65083c201d4ce86d1c6950ea02d7b95f3.tar.gz alive-8b9d1ac65083c201d4ce86d1c6950ea02d7b95f3.zip | |
add wxLua alv-wx
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/alv-copilot | 20 | ||||
| -rwxr-xr-x | bin/alv-wx | 140 |
2 files changed, 140 insertions, 20 deletions
diff --git a/bin/alv-copilot b/bin/alv-copilot deleted file mode 100755 index 9f2f113..0000000 --- a/bin/alv-copilot +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -set -e - -tmpdir=$(mktemp -d) -trap 'rm -rf "$tmpdir"' EXIT INT TERM HUP - -ARGS=$* -FIFO=$tmpdir/fifo -CONF=$tmpdir/conf - -cat > "$CONF" << 'EOF' -split -screen -t evaltime sh -c 'tty > "$FIFO"; read done < "$FIFO"; screen -X quit' -focus -screen -t runtime sh -c 'read tty < "$FIFO"; "alv" $ARGS 2> "$tty"; echo "[press enter to exit]"; read prompt; screen -X quit' -EOF - -mkfifo "$FIFO" -export FIFO ARGS -exec screen -mc "$CONF" diff --git a/bin/alv-wx b/bin/alv-wx new file mode 100755 index 0000000..85d1875 --- /dev/null +++ b/bin/alv-wx @@ -0,0 +1,140 @@ +#!/usr/bin/env moon +import Copilot, Logger, version from require 'alv' +import sleep from require 'system' + +require 'wx' +import + wxID_ABOUT, wxID_OPEN, wxID_EXIT, wxID_ANY, wxVERTICAL, + wxFrame, wxMenuBar, wxMenu, wxPanel, wxBoxSizer, wxTextCtrl, wxSplitterWindow +from wx + +STARTSTOP = 100 + +class GUIStream + new: (@ctrl) => + + write: (...) => + message = table.concat {...}, '' + @ctrl\AppendText message + + flush: => + +class GUICopilot extends Copilot + new: (...) => + super ... + + @app = wx.wxGetApp! + @app.VendorName = 'alive' + @app.AppName = 'alive wxCopilot' + + fileMenu = wxMenu { + { wxID_ABOUT, '&About', 'About alive wxCopilot' } + { wxID_OPEN, '&Open\tCtrl-O', 'Open Script' } + { } + { wxID_EXIT, 'E&xit\tCtrl-Q', 'Exit Program' } + } + runMenu = wxMenu { + { STARTSTOP, '&Start/Stop\tCtrl-P', 'Start/Stop Script Execution' } + } + @menuBar = with wxMenuBar! + \Append fileMenu, '&File' + \Append runMenu, '&Run' + + @frame = wxFrame wx.NULL, wxID_ANY, @app\GetAppName! + @frame\SetMenuBar @menuBar + @status = @frame\CreateStatusBar 1 + + @update_status! + + splitter = wxSplitterWindow @frame, wx.wxID_ANY + + eval, ctrl = @mkPanel splitter, 'eval-time messages' + @eval_stream = GUIStream ctrl + + run, ctrl = @mkPanel splitter, 'run-time messages' + @run_stream = GUIStream ctrl + + splitter\SetMinimumPaneSize 60 + splitter\SplitHorizontally eval, run, 0 + + sizer = with wxBoxSizer wx.wxVERTICAL + \Add splitter, 1, wx.wxEXPAND + wx.wxALL, 10 + + @frame\SetAutoLayout true + @frame\SetSizer sizer + @frame\Show true + + @frame\Connect wxID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, @\do_about + @frame\Connect wxID_OPEN, wx.wxEVT_COMMAND_MENU_SELECTED, @\do_open + @frame\Connect wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED, -> @frame\Close! + @frame\Connect STARTSTOP, wx.wxEVT_COMMAND_MENU_SELECTED, @\do_startstop + @frame\Connect wxID_ANY, wx.wxEVT_IDLE, @\do_idle + + do_about: => + wx.wxMessageBox "alive #{version.tag} wxCopilot. + +built using #{wxlua.wxLUA_VERSION_STRING} on #{wx.wxVERSION_STRING}", + "About wxCopilot", + wx.wxOK + wx.wxICON_INFORMATION, + @frame + + do_open: => + dialog = wx.wxFileDialog @frame, 'Change Script', '', '', + 'Alive scripts (*.alv)|*.alv|All files (*)|*', + wx.wxFD_OPEN + wx.wxFD_FILE_MUST_EXIST + + if dialog\ShowModal! == wx.wxID_OK + @paused = false + @open dialog\GetPath! + @update_status! + + dialog\Destroy! + + do_startstop: (event) => + if @file + @paused = not @paused + @update_status! + + do_idle: (event) => + if @file and not @paused + event\RequestMore true + @tick! + + update_status: => + startstop = @menuBar\FindItem STARTSTOP + if not @file + @status\SetStatusText "No script loaded." + startstop\Enable false + else + startstop\Enable true + if @paused + @status\SetStatusText "Paused." + else + @status\SetStatusText "Running." + + mkPanel: (parent, name) => + panel = wxPanel parent, wxID_ANY + sizer = wxBoxSizer wxVERTICAL + panel\SetSizer sizer + + sizer\Add wx.wxStaticText panel, wx.wxID_ANY, name + log = wxTextCtrl panel, wxID_ANY, '', wx.wxDefaultPosition, + wx.wxDefaultSize, wx.wxTE_MULTILINE + wx.wxTE_READONLY + sizer\Add log, 1, wx.wxEXPAND | wx.wxBOTTOM, 5 + + panel, log + +arguments, key = {} +for a in *arg + if match = a\match '^%-%-(.*)' + key = match + arguments[key] = true + elseif key + arguments[key] = a + key = nil + else + table.insert arguments, a + +copilot = GUICopilot arguments[1] +Logger.init arguments.log, copilot.eval_stream +copilot.app\MainLoop! |
