mirror of
https://codeberg.org/cage/tinmop/
synced 2025-02-09 07:18:39 +01:00
- [gemini] added customizable buffer size when opening partial gemini
content with an external program. using "no wait" directive can be followed by "buffer NUMBER" to customize the cache (in Mib) to be cached before opening the partial downloaded data.
This commit is contained in:
parent
60a66d6ea9
commit
2782317bb7
@ -194,6 +194,11 @@ color-regexp = ":rendering" cyan
|
|||||||
# open "mp3$" with "xterm -e mpv" no wait
|
# open "mp3$" with "xterm -e mpv" no wait
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# using "buffer NUMBER" after "no wait" allow to customize the cache
|
||||||
|
# (in Mib) to be cached before opening the partial downloaded data
|
||||||
|
|
||||||
|
# open "mp4$" with "xterm -e mpv" no wait buffer 20
|
||||||
|
|
||||||
# finally if you want to open some kind of file with tinmop try the
|
# finally if you want to open some kind of file with tinmop try the
|
||||||
# following: valid values are "tinmop" "me" "internal"
|
# following: valid values are "tinmop" "me" "internal"
|
||||||
# ▼▼▼▼▼▼▼▼
|
# ▼▼▼▼▼▼▼▼
|
||||||
|
@ -19,12 +19,9 @@
|
|||||||
|
|
||||||
(defparameter *gemini-db-streams-lock* (bt:make-recursive-lock))
|
(defparameter *gemini-db-streams-lock* (bt:make-recursive-lock))
|
||||||
|
|
||||||
(define-constant +read-buffer-size+ 2048
|
(define-constant +read-buffer-size+ 2048 :test #'=
|
||||||
:documentation "Chunk's size of the buffer when reading non gemini contents from stream")
|
:documentation "Chunk's size of the buffer when reading non gemini contents from stream")
|
||||||
|
|
||||||
(define-constant +buffer-minimum-size-to-open+ 4096
|
|
||||||
:documentation "Minimum size of the saved contents (non gemini text) before attempt to opening with an user defined program: see configuration directive 'use program foo *no wait*'")
|
|
||||||
|
|
||||||
(defparameter *gemini-streams-db* ())
|
(defparameter *gemini-streams-db* ())
|
||||||
|
|
||||||
(defun push-db-stream (stream-object)
|
(defun push-db-stream (stream-object)
|
||||||
@ -480,7 +477,10 @@
|
|||||||
(labels ((download-completed-p (buffer read-so-far)
|
(labels ((download-completed-p (buffer read-so-far)
|
||||||
(< read-so-far (length buffer)))
|
(< read-so-far (length buffer)))
|
||||||
(opening-partial-contents-p (read-so-far)
|
(opening-partial-contents-p (read-so-far)
|
||||||
(> read-so-far +buffer-minimum-size-to-open+))
|
(let ((buffer-size (swconf:link-regex->program-to-use-buffer-size path)))
|
||||||
|
(if buffer-size
|
||||||
|
(> read-so-far buffer-size)
|
||||||
|
(> read-so-far swconf:+buffer-minimum-size-to-open+))))
|
||||||
(%fill-buffer ()
|
(%fill-buffer ()
|
||||||
(declare (optimize (debug 0) (speed 3)))
|
(declare (optimize (debug 0) (speed 3)))
|
||||||
(when (downloading-allowed-p wrapper-object)
|
(when (downloading-allowed-p wrapper-object)
|
||||||
|
@ -1159,6 +1159,7 @@
|
|||||||
:+key-data+
|
:+key-data+
|
||||||
:+key-data-leaf+
|
:+key-data-leaf+
|
||||||
:+key-purge-history-days-offset+
|
:+key-purge-history-days-offset+
|
||||||
|
:+buffer-minimum-size-to-open+
|
||||||
:*allowed-status-visibility*
|
:*allowed-status-visibility*
|
||||||
:*allowed-attachment-type*
|
:*allowed-attachment-type*
|
||||||
:*software-configuration*
|
:*software-configuration*
|
||||||
@ -1229,6 +1230,7 @@
|
|||||||
:config-password-echo-character
|
:config-password-echo-character
|
||||||
:config-win-focus-mark
|
:config-win-focus-mark
|
||||||
:link-regex->program-to-use
|
:link-regex->program-to-use
|
||||||
|
:link-regex->program-to-use-buffer-size
|
||||||
:use-tinmop-as-external-program-p
|
:use-tinmop-as-external-program-p
|
||||||
:thread-message-symbol
|
:thread-message-symbol
|
||||||
:thread-message-read-colors
|
:thread-message-read-colors
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
;; FILEPATH := QUOTED-STRING
|
;; FILEPATH := QUOTED-STRING
|
||||||
;; PROGRAM-NAME := QUOTED-STRING
|
;; PROGRAM-NAME := QUOTED-STRING
|
||||||
;; USE-CACHE := USE BLANKS CACHE
|
;; USE-CACHE := USE BLANKS CACHE
|
||||||
;; NOWAIT := NO BLANKS WAIT
|
;; NOWAIT := NO BLANKS WAIT BLANKS (BUFFER-LABEL BLANKS DIGIT+)?
|
||||||
;; NO := "no"
|
;; NO := "no"
|
||||||
;; WAIT := "wait"
|
;; WAIT := "wait"
|
||||||
;; CACHE := "cache"
|
;; CACHE := "cache"
|
||||||
@ -59,6 +59,7 @@
|
|||||||
;; OPEN := "open"
|
;; OPEN := "open"
|
||||||
;; OPEN-LINK-HELPER-KEY := OPEN
|
;; OPEN-LINK-HELPER-KEY := OPEN
|
||||||
;; WITH-KEY := "with"
|
;; WITH-KEY := "with"
|
||||||
|
;; BUFFER-LABEL := "buffer"
|
||||||
;; REGEXP := QUOTED-STRING
|
;; REGEXP := QUOTED-STRING
|
||||||
;; QUOTED-STRING := #\" (not #\") #\"
|
;; QUOTED-STRING := #\" (not #\") #\"
|
||||||
;; FIELD := ( (or ESCAPED-CHARACTER
|
;; FIELD := ( (or ESCAPED-CHARACTER
|
||||||
@ -80,6 +81,7 @@
|
|||||||
;; HEX-DIGIT := (and (character-ranges #\0 #\9)
|
;; HEX-DIGIT := (and (character-ranges #\0 #\9)
|
||||||
;; (character-ranges #\a #\f)
|
;; (character-ranges #\a #\f)
|
||||||
;; (character-ranges #\A #\f)
|
;; (character-ranges #\A #\f)
|
||||||
|
;; DIGIT := (character-ranges #\0 #\9)
|
||||||
;; ATTRIBUTE-VALUE := "bold"
|
;; ATTRIBUTE-VALUE := "bold"
|
||||||
;; | "italic"
|
;; | "italic"
|
||||||
;; | "underline"
|
;; | "underline"
|
||||||
@ -117,6 +119,9 @@
|
|||||||
|
|
||||||
(defrule hexcolor-prefix #\#)
|
(defrule hexcolor-prefix #\#)
|
||||||
|
|
||||||
|
(defrule digit (character-ranges (#\0 #\9))
|
||||||
|
(:text t))
|
||||||
|
|
||||||
(defrule hex-digit
|
(defrule hex-digit
|
||||||
(or (character-ranges (#\0 #\9))
|
(or (character-ranges (#\0 #\9))
|
||||||
(character-ranges (#\a #\f))
|
(character-ranges (#\a #\f))
|
||||||
@ -289,6 +294,11 @@
|
|||||||
(and username-key blanks assign blanks generic-value blanks)
|
(and username-key blanks assign blanks generic-value blanks)
|
||||||
(:function remove-if-null))
|
(:function remove-if-null))
|
||||||
|
|
||||||
|
(define-constant +buffer-minimum-size-to-open+ (expt 1024 2) :test #'=
|
||||||
|
:documentation "Minimum size of the saved contents (non gemini text)
|
||||||
|
before attempt to opening with an user defined program: see
|
||||||
|
configuration directive 'use program foo *no wait*'")
|
||||||
|
|
||||||
(defclass open-link-helper ()
|
(defclass open-link-helper ()
|
||||||
((re
|
((re
|
||||||
:initform nil
|
:initform nil
|
||||||
@ -304,27 +314,40 @@
|
|||||||
:reader use-cache-p
|
:reader use-cache-p
|
||||||
:writer (setf use-cache))
|
:writer (setf use-cache))
|
||||||
(wait
|
(wait
|
||||||
:initform t
|
:initform t
|
||||||
:initarg :wait
|
:initarg :wait
|
||||||
:reader waitp
|
:reader waitp
|
||||||
:writer (setf wait)))
|
:writer (setf wait))
|
||||||
|
(buffer-size
|
||||||
|
:initform +buffer-minimum-size-to-open+
|
||||||
|
:initarg :buffer-size
|
||||||
|
:accessor buffer-size))
|
||||||
(:documentation "When a gemini link matches `re' try to open it with 'program-name'"))
|
(:documentation "When a gemini link matches `re' try to open it with 'program-name'"))
|
||||||
|
|
||||||
(defmethod print-object ((object open-link-helper) stream)
|
(defmethod print-object ((object open-link-helper) stream)
|
||||||
(print-unreadable-object (object stream :type t :identity nil)
|
(print-unreadable-object (object stream :type t :identity nil)
|
||||||
(with-accessors ((re re)
|
(with-accessors ((re re)
|
||||||
(program-name program-name)
|
(program-name program-name)
|
||||||
(use-cache-p use-cache-p)) object
|
(use-cache-p use-cache-p)
|
||||||
(format stream "re: ~s program: ~s use cache? ~a" re program-name use-cache-p))))
|
(waitp waitp)
|
||||||
|
(buffer-size buffer-size)) object
|
||||||
|
(format stream
|
||||||
|
"re: ~s program: ~s use cache? ~a wait? ~a buffer size: ~a"
|
||||||
|
re program-name use-cache-p waitp buffer-size))))
|
||||||
|
|
||||||
|
(defun make-open-link-helper (re program-name use-cache
|
||||||
|
&key (wait t) (buffer-size +buffer-minimum-size-to-open+))
|
||||||
|
|
||||||
(defun make-open-link-helper (re program-name use-cache &key (wait t))
|
|
||||||
(assert (stringp program-name))
|
(assert (stringp program-name))
|
||||||
(assert (stringp re))
|
(assert (stringp re))
|
||||||
|
(assert (integerp buffer-size))
|
||||||
|
(assert (> buffer-size 0))
|
||||||
(make-instance 'open-link-helper
|
(make-instance 'open-link-helper
|
||||||
:re re
|
:re re
|
||||||
:program-name program-name
|
:program-name program-name
|
||||||
:use-cache use-cache
|
:use-cache use-cache
|
||||||
:wait wait))
|
:wait wait
|
||||||
|
:buffer-size buffer-size))
|
||||||
|
|
||||||
(defrule use "use"
|
(defrule use "use"
|
||||||
(:text t))
|
(:text t))
|
||||||
@ -338,6 +361,9 @@
|
|||||||
(defrule wait "wait"
|
(defrule wait "wait"
|
||||||
(:text t))
|
(:text t))
|
||||||
|
|
||||||
|
(defrule buffer-label "buffer"
|
||||||
|
(:text t))
|
||||||
|
|
||||||
(defrule use-cache (and use blanks cache)
|
(defrule use-cache (and use blanks cache)
|
||||||
(:constant t))
|
(:constant t))
|
||||||
|
|
||||||
@ -355,14 +381,30 @@
|
|||||||
blanks
|
blanks
|
||||||
(? (and use-cache ; 8 use cache?
|
(? (and use-cache ; 8 use cache?
|
||||||
blanks))
|
blanks))
|
||||||
(? (and no-wait ; 9 wait download?
|
(? (and no-wait ; 9 wait download? Buffer size?
|
||||||
|
blanks
|
||||||
|
(? (and buffer-label blanks (+ digit)))
|
||||||
blanks)))
|
blanks)))
|
||||||
(:function (lambda (args)
|
(:function (lambda (args)
|
||||||
(list :open-link-helper
|
(let* ((use-cache (elt args 8))
|
||||||
(make-open-link-helper (elt args 2)
|
(wait-parameters (elt args 9))
|
||||||
(elt args 6)
|
(waitp (not (and wait-parameters (elt wait-parameters 0))))
|
||||||
(elt args 8)
|
(buffer-size (if (and wait-parameters
|
||||||
:wait (not (elt args 9)))))))
|
(elt wait-parameters 2))
|
||||||
|
(let* ((buffer-parameters (elt wait-parameters 2))
|
||||||
|
(buffer-string-list (elt buffer-parameters 2))
|
||||||
|
(mebibyte-string (reduce #'strcat
|
||||||
|
buffer-string-list))
|
||||||
|
(mebimytes (parse-integer mebibyte-string))
|
||||||
|
(bytes (* 1024 1024 mebimytes)))
|
||||||
|
(abs bytes))
|
||||||
|
swconf:+buffer-minimum-size-to-open+)))
|
||||||
|
(list :open-link-helper
|
||||||
|
(make-open-link-helper (elt args 2)
|
||||||
|
(elt args 6)
|
||||||
|
use-cache
|
||||||
|
:wait waitp
|
||||||
|
:buffer-size buffer-size))))))
|
||||||
|
|
||||||
(defrule post-allowed-language (and "post-allowed-language" blanks assign regexp)
|
(defrule post-allowed-language (and "post-allowed-language" blanks assign regexp)
|
||||||
(:function remove-if-null))
|
(:function remove-if-null))
|
||||||
@ -964,13 +1006,20 @@
|
|||||||
|
|
||||||
(gen-simple-access (all-link-open-program) +key-open-link-helper+)
|
(gen-simple-access (all-link-open-program) +key-open-link-helper+)
|
||||||
|
|
||||||
|
(defun link-regex->program-to-use-parameters (link)
|
||||||
|
(find-if (lambda (a) (cl-ppcre:scan (re a) link))
|
||||||
|
(config-all-link-open-program)))
|
||||||
|
|
||||||
(defun link-regex->program-to-use (link)
|
(defun link-regex->program-to-use (link)
|
||||||
(when-let ((found (find-if (lambda (a)
|
(when-let ((found (link-regex->program-to-use-parameters link)))
|
||||||
(cl-ppcre:scan (re a) link))
|
|
||||||
(config-all-link-open-program))))
|
|
||||||
(values (program-name found)
|
(values (program-name found)
|
||||||
(use-cache-p found)
|
(use-cache-p found)
|
||||||
(waitp found))))
|
(waitp found)
|
||||||
|
(buffer-size found))))
|
||||||
|
|
||||||
|
(defun link-regex->program-to-use-buffer-size (link)
|
||||||
|
(when-let ((found (link-regex->program-to-use-parameters link)))
|
||||||
|
(buffer-size found)))
|
||||||
|
|
||||||
(defun use-tinmop-as-external-program-p (program)
|
(defun use-tinmop-as-external-program-p (program)
|
||||||
(cl-ppcre:scan "(^me$)|(^internal$)|(tinmop)" program))
|
(cl-ppcre:scan "(^me$)|(^internal$)|(tinmop)" program))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user