1
0
mirror of https://codeberg.org/cage/tinmop/ synced 2024-12-13 22:46:13 +01:00

Compare commits

...

3 Commits

Author SHA1 Message Date
cage
23742186db - fixed default in config file. 2021-11-10 19:35:52 +01:00
cage
e6f92f3621 - [gemini] ensured opening files with an external program if the size of the file is smaller than the cache size. 2021-11-10 16:21:18 +01:00
cage
2782317bb7 - [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.
2021-11-10 16:12:08 +01:00
4 changed files with 83 additions and 26 deletions

View File

@ -43,7 +43,7 @@ post-allowed-language = ".*"
# update gemlog subscriptions when program starts
# (default 'no', change to 'yes' if desired)
start.update.gemlog = yes
start.update.gemlog = no
# directory to scan for gempub files, default the same as
# $XDG_DATA_HOME (usually something like %HOME/.local/share/tinmop/").
@ -194,6 +194,11 @@ color-regexp = ":rendering" cyan
# 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
# following: valid values are "tinmop" "me" "internal"
# ▼▼▼▼▼▼▼▼

View File

@ -19,12 +19,9 @@
(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")
(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* ())
(defun push-db-stream (stream-object)
@ -480,7 +477,10 @@
(labels ((download-completed-p (buffer read-so-far)
(< read-so-far (length buffer)))
(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 ()
(declare (optimize (debug 0) (speed 3)))
(when (downloading-allowed-p wrapper-object)
@ -498,7 +498,8 @@
(force-output file-stream)
(setf (stream-status wrapper-object) :completed)
(gemini-client:close-ssl-socket socket)
(when wait-for-download
(when (or wait-for-download
partial-content-not-opened)
(os-utils:open-resource-with-external-program support-file
nil)))
(progn

View File

@ -1159,6 +1159,7 @@
:+key-data+
:+key-data-leaf+
:+key-purge-history-days-offset+
:+buffer-minimum-size-to-open+
:*allowed-status-visibility*
:*allowed-attachment-type*
:*software-configuration*
@ -1229,6 +1230,7 @@
:config-password-echo-character
:config-win-focus-mark
:link-regex->program-to-use
:link-regex->program-to-use-buffer-size
:use-tinmop-as-external-program-p
:thread-message-symbol
:thread-message-read-colors

View File

@ -47,7 +47,7 @@
;; FILEPATH := QUOTED-STRING
;; PROGRAM-NAME := QUOTED-STRING
;; USE-CACHE := USE BLANKS CACHE
;; NOWAIT := NO BLANKS WAIT
;; NOWAIT := NO BLANKS WAIT BLANKS (BUFFER-LABEL BLANKS DIGIT+)?
;; NO := "no"
;; WAIT := "wait"
;; CACHE := "cache"
@ -59,6 +59,7 @@
;; OPEN := "open"
;; OPEN-LINK-HELPER-KEY := OPEN
;; WITH-KEY := "with"
;; BUFFER-LABEL := "buffer"
;; REGEXP := QUOTED-STRING
;; QUOTED-STRING := #\" (not #\") #\"
;; FIELD := ( (or ESCAPED-CHARACTER
@ -80,6 +81,7 @@
;; HEX-DIGIT := (and (character-ranges #\0 #\9)
;; (character-ranges #\a #\f)
;; (character-ranges #\A #\f)
;; DIGIT := (character-ranges #\0 #\9)
;; ATTRIBUTE-VALUE := "bold"
;; | "italic"
;; | "underline"
@ -117,6 +119,9 @@
(defrule hexcolor-prefix #\#)
(defrule digit (character-ranges (#\0 #\9))
(:text t))
(defrule hex-digit
(or (character-ranges (#\0 #\9))
(character-ranges (#\a #\f))
@ -289,6 +294,11 @@
(and username-key blanks assign blanks generic-value blanks)
(: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 ()
((re
:initform nil
@ -304,27 +314,40 @@
:reader use-cache-p
:writer (setf use-cache))
(wait
:initform t
:initarg :wait
:reader waitp
:writer (setf wait)))
:initform t
:initarg :wait
:reader waitp
: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'"))
(defmethod print-object ((object open-link-helper) stream)
(print-unreadable-object (object stream :type t :identity nil)
(with-accessors ((re re)
(program-name program-name)
(use-cache-p use-cache-p)) object
(format stream "re: ~s program: ~s use cache? ~a" re program-name use-cache-p))))
(use-cache-p 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 re))
(assert (integerp buffer-size))
(assert (> buffer-size 0))
(make-instance 'open-link-helper
:re re
:program-name program-name
:use-cache use-cache
:wait wait))
:wait wait
:buffer-size buffer-size))
(defrule use "use"
(:text t))
@ -338,6 +361,9 @@
(defrule wait "wait"
(:text t))
(defrule buffer-label "buffer"
(:text t))
(defrule use-cache (and use blanks cache)
(:constant t))
@ -355,14 +381,30 @@
blanks
(? (and use-cache ; 8 use cache?
blanks))
(? (and no-wait ; 9 wait download?
(? (and no-wait ; 9 wait download? Buffer size?
blanks
(? (and buffer-label blanks (+ digit)))
blanks)))
(:function (lambda (args)
(list :open-link-helper
(make-open-link-helper (elt args 2)
(elt args 6)
(elt args 8)
:wait (not (elt args 9)))))))
(let* ((use-cache (elt args 8))
(wait-parameters (elt args 9))
(waitp (not (and wait-parameters (elt wait-parameters 0))))
(buffer-size (if (and wait-parameters
(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)
(:function remove-if-null))
@ -964,13 +1006,20 @@
(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)
(when-let ((found (find-if (lambda (a)
(cl-ppcre:scan (re a) link))
(config-all-link-open-program))))
(when-let ((found (link-regex->program-to-use-parameters link)))
(values (program-name 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)
(cl-ppcre:scan "(^me$)|(^internal$)|(tinmop)" program))