diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-13 14:47:22 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:23:21 +0000 |
| commit | c9a3da0298f10027654744ca83a8c5a8e9b04b0f (patch) | |
| tree | ecc405e5d9d7ac404a9bdc9011e1bd949182e25c | |
| parent | cleanup alv/builtin (diff) | |
| download | alive-c9a3da0298f10027654744ca83a8c5a8e9b04b0f.tar.gz alive-c9a3da0298f10027654744ca83a8c5a8e9b04b0f.zip | |
add fltk4lua copilot UI
| -rw-r--r-- | alv/copilot.moon | 5 | ||||
| -rwxr-xr-x | bin/alv-fltk | 115 |
2 files changed, 120 insertions, 0 deletions
diff --git a/alv/copilot.moon b/alv/copilot.moon index 709a2c3..6c6df8d 100644 --- a/alv/copilot.moon +++ b/alv/copilot.moon @@ -33,12 +33,17 @@ class Copilot --- change the running script. -- @tparam string file open: (file) => + assert not COPILOT, "another Copilot is already running!" + COPILOT = @ + if old = @last_modules.__root old\destroy! @last_modules.__root = Module file @active_module = @last_modules.__root + COPILOT = nil + --- require a module. -- @tparam string name -- @treturn RTNode root diff --git a/bin/alv-fltk b/bin/alv-fltk new file mode 100755 index 0000000..526724c --- /dev/null +++ b/bin/alv-fltk @@ -0,0 +1,115 @@ +#!/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 'https://alv.s-ol.nu' + + 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 alv.s-ol.nu 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 |
