]> gitweb.factorcode.org Git - factor.git/commitdiff
gemini.cli: split history and forward/backward stack.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 12 Mar 2021 20:36:53 +0000 (12:36 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 12 Mar 2021 20:36:53 +0000 (12:36 -0800)
extra/gemini/cli/cli.factor

index 6ff87637551dce250154eb8df9cb1881fb8e5cb7..b05827c8fc10a8aa560d166c8fdfc72bdf3a04a6 100644 (file)
@@ -36,8 +36,24 @@ CONSTANT: COMMANDS H{
 
 CONSTANT: HISTORY V{ }
 CONSTANT: LINKS V{ }
+CONSTANT: STACK V{ }
 CONSTANT: URL V{ }
 
+: add-stack ( args -- )
+    URL ?first STACK index [
+        1 + dup STACK ?nth pick = [
+            2drop
+        ] [
+            STACK [ length ] [ delete-slice ] bi
+            STACK push
+            STACK length 10 > [
+                0 STACK remove-nth! drop
+            ] when
+        ] if
+    ] [
+        STACK push
+    ] if* ;
+
 : add-history ( args -- )
     HISTORY dup length 10 > [
         0 swap remove-nth!
@@ -75,20 +91,20 @@ CONSTANT: URL V{ }
     { [ "://" over subseq? ] [ "gemini://" head? ] } 1||
     [ "gemini://" prepend ] unless
     dup "gemini://" head? [
-        dup add-history gemini-get
+        [ add-history ] [ add-stack ] [ gemini-get ] tri
     ] [ open-url ] if ;
 
 : gemini-reload ( -- )
     HISTORY ?last gemini-go ;
 
 : gemini-back ( -- )
-    URL ?first HISTORY index [
-        1 - HISTORY ?nth [ gemini-get ] when*
+    URL ?first STACK index [
+        1 - STACK ?nth [ gemini-get ] when*
     ] when* ;
 
 : gemini-forward ( -- )
-    URL ?first HISTORY index [
-        1 + HISTORY ?nth [ gemini-get ] when*
+    URL ?first STACK index [
+        1 + STACK ?nth [ gemini-get ] when*
     ] when* ;
 
 : gemini-up ( -- )