diff --git a/alv/builtin.moon b/alv/builtin.moon index 98b4198..ab3a9a0 100644 --- a/alv/builtin.moon +++ b/alv/builtin.moon @@ -296,9 +296,9 @@ print = ValueStream.meta tick: => if @inputs.value\metatype! == 'event' for msg in *@inputs.value! - print msg + L\print msg else - print @inputs.value! + L\print @inputs.value! { :doc diff --git a/alv/copilot.moon b/alv/copilot.moon index 478cbae..a1dc811 100644 --- a/alv/copilot.moon +++ b/alv/copilot.moon @@ -48,21 +48,21 @@ class Copilot @root\tick_io! @root\tick! if not ok - print error + L\print error @registry\end_tick! eval: => @registry\begin_eval! ok, ast = Error.try "parsing '#{@file}'", program\match, slurp @file if not (ok and ast) - print ast or Error 'syntax', "failed to parse" + L\print ast or Error 'syntax', "failed to parse" @registry\rollback_eval! return scope = Scope globals ok, root = Error.try "evaluating '#{@file}'", ast\eval, scope, @registry if not ok - print root + L\print root @registry\rollback_eval! return @@ -76,8 +76,10 @@ class Copilot return if @last_modification < modification + L.stream = io.stderr L\log "#{@file} changed at #{modification}" @eval! + L.stream = io.stdout @last_modification = os.time! { diff --git a/alv/logger.moon b/alv/logger.moon index 973e8b5..26126ac 100644 --- a/alv/logger.moon +++ b/alv/logger.moon @@ -37,26 +37,30 @@ class Logger else error unpack res + --- the stream to write to. + -- @tfield file stream + --- static functions -- @section static --- create a new Logger. -- @classmethod -- @tparam string level the log-level to log at. - new: (level='log') => + -- @tparam file stream the stream to write to. + new: (level='log', @stream=io.stdout) => @level = levels[level] or level @prefix = '' for name, level in pairs levels - @[name] = (first, ...) => + @[name] = (msg) => return unless @level <= level - where = debug.traceback '', 2 + msg = tostring msg + @stream\write @prefix, msg, '\n' if level == levels.error or @level == levels.debug - print @prefix .. first, ... - print where - else - print @prefix .. first, ... + where = debug.traceback '', 2 + @stream\write where, '\n' + @stream\flush! if level == levels.print @push = (fn, ...) => fn ... @@ -74,6 +78,7 @@ class Logger -- - `'silent'` -- -- @tparam ?string level the level to initialize the logger at. + -- @tparam ?file stream the output stream (stdout). @init: (...) -> L = Logger ... diff --git a/bin/alv-copilot b/bin/alv-copilot index 9a0cf40..9f2f113 100755 --- a/bin/alv-copilot +++ b/bin/alv-copilot @@ -10,10 +10,9 @@ CONF=$tmpdir/conf cat > "$CONF" << 'EOF' split +screen -t evaltime sh -c 'tty > "$FIFO"; read done < "$FIFO"; screen -X quit' focus -screen -t evaltime sh -c 'tty > "$FIFO"; read done < "$FIFO"' -focus -screen -t runtime sh -c 'read tty < "$FIFO"; "alv" $ARGS 2> "$tty"; echo "[press enter to exit]"; read prompt; echo done > "$FIFO"' +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"