diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-15 11:22:56 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-05-15 11:23:51 +0000 |
| commit | f506a5271fb4326caa3ad990c691e1bb81bd4e3c (patch) | |
| tree | 4a01b4be5be7e4d38872bdc75c8d1930f413c8b7 /bin | |
| parent | add array and struct constructors (diff) | |
| download | alive-f506a5271fb4326caa3ad990c691e1bb81bd4e3c.tar.gz alive-f506a5271fb4326caa3ad990c691e1bb81bd4e3c.zip | |
move copilot logic, make startup scripts lua
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/alv | 40 | ||||
| -rwxr-xr-x | bin/alv-fltk | 119 | ||||
| -rwxr-xr-x | bin/alv-wx | 146 |
3 files changed, 12 insertions, 293 deletions
@@ -1,36 +1,4 @@ -#!/usr/bin/env moon -import Copilot, Logger from require 'alv' -import sleep from require 'system' - -class ColorLogger extends Logger - set_time: (time) => - super time - @stream\write switch time - when 'eval' then '\27[92m' - when 'run' then '\27[0m' - -arguments, key = { nocolor: false } -for a in *arg - if key - arguments[key] = a - key = nil - else if match = a\match '^%-%-(.*)' - if 'bool' == type arguments[key] - arguments[key] = true - else - key = match - else - table.insert arguments, a -assert not key, "option value missing" - -if arguments.nocolor - Logger\init arguments.log -else - ColorLogger\init arguments.log - -assert arguments[1], "no filename given" -copilot = Copilot arguments[1] - -while true - copilot\tick! - sleep 1 / 1000 +#!/usr/bin/env lua +require('moonscript') +local Copilot = require('alv.copilot.cli').CLICopilot +Copilot(arg):run() diff --git a/bin/alv-fltk b/bin/alv-fltk index 8075540..0837fab 100755 --- a/bin/alv-fltk +++ b/bin/alv-fltk @@ -1,115 +1,4 @@ -#!/usr/bin/env moon -import Copilot, Logger, version from require 'alv' -import sleep from require 'system' -fl = require 'fltk4lua' - -class GUILogger extends Logger - new: (level, @eval, @run) => - super level - - set_time: (time) => - @output = switch time - when 'eval' then @eval - when 'run' then @run - else error "invalid time '#{time}'" - - put: (message) => - @output.browser\add message - if true or @output.sticky.value - @output.browser.bottomline = @output.browser.nitems - -class GUICopilot extends Copilot - new: (...) => - @window = with fl.Window { 400, 220, "alv copilot", xclass: 'alv' } - \size_range 400, 220, nil, nil, 20, 20 - - @menubar = with fl.Menu_Bar 0, 0, 400, 20 - \add "&File/About", nil, @\about, nil, fl.MENU_DIVIDER - \add "&File/&Open script", '^o', -> @open! - \add "&File/&Quit", '^q', -> @window\hide! - @pause = \add "Run (^P)", '^p', @\pause, nil, fl.MENU_TOGGLE - \add "Help", nil, -> fl.open_uri version.web - - tile = fl.Tile 5, 40, 390, 160 - @window.resizable = tile - resize_box = fl.Box { 5, 60, 390, 120, labeltype: fl.NO_LABEL } - tile.resizable = resize_box - - @eval_out = do - browser = fl.Browser { - 5, 40, 390, 80, "eval", - box: fl.GTK_DOWN_BOX, align: fl.ALIGN_TOP_RIGHT - } - -- sticky = fl.Check_Button 5, 20, 80, 20, 'sticky' - -- sticky\set! - :browser, :sticky - - @run_out = do - browser = fl.Browser { - 5, 120, 390, 80, "run", - box: fl.GTK_DOWN_BOX, align: fl.ALIGN_BOTTOM_RIGHT - } - -- sticky = fl.Check_Button 5, 200, 80, 20, 'sticky' - -- sticky\set! - :browser, :sticky - - tile\end_group! - @window\end_group! - - @update_status! - super ... - - run: (opts) => - GUILogger\init opts.log, @eval_out, @run_out - @window\show! - - run = true - while run - run = if @paused - fl.check 1 - else - @tick! - sleep 1 / 1000 - fl.check! - - about: => - fl.alert "alive #{version.tag} fltkCopilot. - -visit #{version.web} for more information." - - open: (file) => - file or= fl.file_chooser "Open Script", '*.alv', 'script.alv' - - if file - @paused = false - super file - @update_status! - - pause: => - @paused = not @paused - @update_status! - - update_status: => - state = fl.MENU_TOGGLE - if not @paused - state += fl.MENU_VALUE - @menubar\menuitem_setp @pause, 'flags', state - - if @paused - "Paused." - else - "Running." - -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] -copilot\run arguments +#!/usr/bin/env lua +require('moonscript') +local Copilot = require('alv.copilot.fltk').FLTKCopilot +Copilot(arg):run() @@ -1,142 +1,4 @@ -#!/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 GUILogger extends Logger - new: (level, @eval_ctrl, @run_ctrl) => - super level - - set_time: (time) => - @ctrl = switch time - when 'eval' then @eval_ctrl - when 'run' then @run_ctrl - else error "invalid time '#{time}'" - - put: (message) => - @ctrl\AppendText message .. '\n' - -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, @eval_ctrl = @mkPanel splitter, 'eval-time messages' - - run, @run_ctrl = @mkPanel splitter, 'run-time messages' - - 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 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] -GUILogger\init arguments.log, copilot.eval_ctrl, copilot.run_ctrl -copilot.app\MainLoop! +#!/usr/bin/env lua +require('moonscript') +local Copilot = require('alv.copilot.wx').WXCopilot +Copilot(arg):run() |
