From 8aa83c3c9398489c8e7433c83a12714079473a26 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 25 Jul 2024 19:24:28 -0700 Subject: [PATCH] ui.tools.listener.history: use FACTOR_HISTORY to optionally set history file --- .../ui/tools/listener/history/history.factor | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/basis/ui/tools/listener/history/history.factor b/basis/ui/tools/listener/history/history.factor index 4ce7cc8e431..d843ff42cf3 100644 --- a/basis/ui/tools/listener/history/history.factor +++ b/basis/ui/tools/listener/history/history.factor @@ -1,24 +1,30 @@ ! Copyright (C) 2009 Slava Pestov. ! See https://factorcode.org/license.txt for BSD license. -USING: accessors continuations documents io io.encodings.utf8 +USING: accessors documents environment io io.encodings.utf8 io.files io.styles kernel math math.order namespaces -prettyprint.backend prettyprint.config sequences strings.parser ; +prettyprint.backend prettyprint.config sequences strings.parser +; IN: ui.tools.listener.history TUPLE: history document elements start index ; -CONSTANT: history-file "~/.factor-history" +: history-file ( -- path ) + "FACTOR_HISTORY" os-env [ "~/.factor-history" ] unless* ; : read-history ( -- elements ) - history-file file-exists? [ history-file utf8 file-lines [ unescape-string ] V{ } map-as ] [ V{ } clone ] if ; + history-file file-exists? [ + history-file utf8 file-lines + [ unescape-string ] V{ } map-as + ] [ V{ } clone ] if ; : append-history ( history -- ) - history-file file-exists? - [ + history-file file-exists? [ [ history-file utf8 [ f string-limit? [ - [ elements>> ] [ start>> ] bi [ string>> f f unparse-string print ] swap each-from + [ elements>> ] [ start>> ] bi + [ string>> f f unparse-string print ] swap + each-from ] with-variable ] with-file-appender ] [ [ index>> ] keep start<< ] bi