Skip to content

Commit

Permalink
ui.tools.listener.history: use FACTOR_HISTORY to optionally set histo…
Browse files Browse the repository at this point in the history
…ry file
  • Loading branch information
mrjbq7 committed Jul 26, 2024
1 parent c890a67 commit 8aa83c3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions basis/ui/tools/listener/history/history.factor
Original file line number Diff line number Diff line change
@@ -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 <input> ] V{ } map-as ] [ V{ } clone ] if ;
history-file file-exists? [
history-file utf8 file-lines
[ unescape-string <input> ] 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
Expand Down

0 comments on commit 8aa83c3

Please sign in to comment.