1
0
Fork 0

- allowed users (via caonfiguration directive) to use (or not) cache when opening a link with a custom program.

This commit is contained in:
cage 2021-02-13 12:37:37 +01:00
parent bc3e7685a7
commit 8f757b563b
4 changed files with 233 additions and 195 deletions

View File

@ -20,106 +20,106 @@
# - blink
# The text that starts the title section of a window
window.title.left.stopper.value = "╼▌"
window.title.left.stopper.value = "╼▌"
# The text taht end the title section of a window
window.title.right.stopper.value = "▐╾"
window.title.right.stopper.value = "▐╾"
# default background color of terminal
main-window.background = black
main-window.background = black
# default foreground color (text) of terminal
main-window.foreground = white
main-window.foreground = white
# shown when a message was trasmitted in crypted form
crypted.mark.value = " 🔏👌"
crypted.mark.value = " 🔏👌"
# the string to be drawn instead of actual character when input password
password-echo-character = "•"
password-echo-character = "•"
# the character used to draw the vote's horizontal histogram
# note: keeps it one character wide
vote-vertical-bar = "⯀"
vote-vertical-bar = "⯀"
# quick help window style
quick-help.header.foreground = white
quick-help.header.foreground = white
quick-help.header.background = red
quick-help.header.background = red
quick-help.header.attribute = bold
quick-help.header.attribute = bold
# help dialog style
help-dialog.background = white
help-dialog.background = white
help-dialog.foreground = red
help-dialog.foreground = red
# info dialog style
info-dialog.background = blue
info-dialog.background = blue
info-dialog.foreground = yellow
info-dialog.foreground = yellow
# error dialog style
error-dialog.background = red
error-dialog.background = red
error-dialog.foreground = yellow
error-dialog.foreground = yellow
# input dialog style
input-dialog.background = blue
input-dialog.background = blue
input-dialog.foreground = white
input-dialog.foreground = white
# this color specifies the style for form of the dialog
input-dialog.input.foreground = black
input-dialog.input.foreground = black
input-dialog.input.background = #aaaaaa
input-dialog.input.background = #aaaaaa
# this color specify the style for active form of the dialog
input-dialog.input.selected.foreground = black
input-dialog.input.selected.foreground = black
input-dialog.input.selected.background = white
input-dialog.input.selected.background = white
# the notify window shows useful information to the user
notify-window.background = #0219A2
notify-window.background = #0219A2
notify-window.foreground = #55D67C
notify-window.foreground = #55D67C
notify-window.life = 2
notify-window.life = 2
# a window shows this text in the top left corner to indicate that it
# has focus
window.focus.mark.value = "📌"
window.focus.mark.value = "📌"
window.focus.mark.foreground = white
window.focus.mark.foreground = white
window.focus.mark.background = black
window.focus.mark.background = black
# this specify style for the thread window
thread-window.background = black
thread-window.background = black
thread-window.foreground = blue
thread-window.foreground = blue
# the modeline window is a small section on the very bottom of the
# thread window that shows some information about the threads see
# below.
thread-window.modeline.background = blue
thread-window.modeline.background = blue
thread-window.modeline.foreground = yellow
thread-window.modeline.foreground = yellow
# this variable customize the information that the modeline will
# shows, values prefixed with a '%' will be expanded, allowe values to
@ -134,120 +134,120 @@ thread-window.modeline.foreground = yellow
# - %tags in selected messages (if any)
# - %% a percent sign
thread-window.modeline.value = "%u@%s ◈ %k %r/%t ◈ folder: %f ◈ tags: %h"
thread-window.modeline.value = "%u@%s ◈ %k %r/%t ◈ folder: %f ◈ tags: %h"
# this is the only width you have to specify as the others windows
# just fills the void left by this one
thread-window.width = 5/6
thread-window.width = 5/6
thread-window.height = 1/4
thread-window.height = 1/4
# colors for selected messages in thread window
thread-window.message.selected.background = cyan
thread-window.message.selected.background = cyan
thread-window.message.selected.foreground = black
thread-window.message.selected.foreground = black
#thread-window.message.selected.attribute = bold
#thread-window.message.selected.attribute = bold
# colors for messages marked for deletion in thread window
thread-window.message.deleted.background = red
thread-window.message.deleted.background = red
thread-window.message.deleted.foreground = white
thread-window.message.deleted.foreground = white
thread-window.message.deleted.attribute = bold
thread-window.message.deleted.attribute = bold
# colors for already read messages in thread window
thread-window.message.read.background = black
thread-window.message.read.background = black
thread-window.message.read.foreground = #aaaaaa
thread-window.message.read.foreground = #aaaaaa
thread-window.message.read.attribute = italic
thread-window.message.read.attribute = italic
# colors for new (not read) messages in thread window
thread-window.message.unread.background = black
thread-window.message.unread.background = black
thread-window.message.unread.foreground = cyan
thread-window.message.unread.foreground = cyan
#thread-window.message.unread.attribute = bold
#thread-window.message.unread.attribute = bold
# text to signal that you favourited this message
thread-window.message.favourite.value = "★"
thread-window.message.favourite.value = "★"
# color of the text that signals that you favourited this message
thread-window.message.favourite.foreground = yellow
thread-window.message.favourite.foreground = yellow
# text to signal that this message is marked as sensible
thread-window.message.sensitive.value = "⚠"
thread-window.message.sensitive.value = "⚠"
# color of the text that signals that this message is marked as sensible
thread-window.message.sensitive.foreground = blue
thread-window.message.sensitive.foreground = blue
# text that signals that you boosted this message
thread-window.message.boosted.value = "♻"
thread-window.message.boosted.value = "♻"
# color of the text that signals that you boosted this message
thread-window.message.boosted.foreground = cyan
thread-window.message.boosted.foreground = cyan
# text to signal that this message is the root (on the server) of the
# thread
thread-window.message.root.value = "↓ "
thread-window.message.root.value = "↓ "
# color of the text that signals that this message is the root (on the server)
# of the thread
thread-window.message.root.foreground = blue
thread-window.message.root.foreground = blue
# the messages are organized in trees
# color of the branch of the tree (the segments that connect messages)
thread-window.tree.branch.foreground = red
thread-window.tree.branch.foreground = red
# color of the arrow in the tree that points to a single message
thread-window.tree.arrow.foreground = magenta
thread-window.tree.arrow.foreground = magenta
# color of the subject of the message (AKA sensistive text) for a
# message
thread-window.tree.data.foreground = white
thread-window.tree.data.foreground = white
# color of the subject of the message (AKA sensistive text) for
# message with no replies
thread-window.tree.data-leaf.foreground = white
thread-window.tree.data-leaf.foreground = white
# color of the subject of the message (AKA sensistive text) for
# message with no parents
thread-window.tree.root.foreground = yellow
thread-window.tree.root.foreground = yellow
# arrow that point to a message
thread-window.tree.arrow.value = "🞂 "
thread-window.tree.arrow.value = "🞂 "
# segment that connect a message with no replies to the tree
thread-window.tree.leaf.value = "╰"
thread-window.tree.leaf.value = "╰"
# segment that connect a message with replies to the tree
thread-window.tree.branch.value = "├"
thread-window.tree.branch.value = "├"
# segment that push to the left a message subject
thread-window.tree.spacer.value = "─"
thread-window.tree.spacer.value = "─"
# vertical segment that connect tree branches
thread-window.tree.vertical-line.value = "│"
thread-window.tree.vertical-line.value = "│"
# a message shows the composition date, specify the format:
# values starting with '%' will be expanded, allowed values are:
@ -264,145 +264,145 @@ thread-window.tree.vertical-line.value = "│"
# - %short-month Jan to Dec
# - %% a percent sign
thread-window.date-format.value = "%year %short-month %day %hour:%min"
thread-window.date-format.value = "%year %short-month %day %hour:%min"
# the windows that shows tags subscriptions
tags-window.height = 1/2
tags-window.height = 1/2
tags-window.background = black
tags-window.background = black
tags-window.foreground = #67998B
tags-window.foreground = #67998B
# the colors for currently selected tags
tags-window.input.selected.background = black
tags-window.input.selected.background = black
tags-window.input.selected.foreground = #71AF8C
tags-window.input.selected.foreground = #71AF8C
# tags shows a little histogram (note that some servers do not provide
# this information) for number of messages posted every day that
# contains this tag
tags-window.histogram.foreground = yellow
tags-window.histogram.foreground = yellow
# test to indicate that this tags got new messages
tags-window.new-message.mark.value = " 📬"
tags-window.new-message.mark.value = " 📬"
# this is the window that shows active conversation (a conversation is
# active until the user chooses to ignore it)
conversations-window.background = black
conversations-window.background = black
conversations-window.foreground = #B48B21
conversations-window.foreground = #B48B21
# the colors for currently selected conversation
conversations-window.input.selected.background = #4B0301
conversations-window.input.selected.background = #4B0301
conversations-window.input.selected.foreground = #B27DE5
conversations-window.input.selected.foreground = #B27DE5
#colors for count of read messages for conversation
#conversations-window.read.background = black
#conversations-window.read.background = black
#conversations-window.read.foreground = blue
#conversations-window.read.foreground = blue
#colors for count of unreaded messages for conversation
conversations-window.unread.background = black
conversations-window.unread.background = black
conversations-window.unread.foreground = red
conversations-window.unread.foreground = red
# this is the message that shows available keybindings
keybindings-window.background = black
keybindings-window.background = black
keybindings-window.foreground = #E2BE6F
keybindings-window.foreground = #E2BE6F
keybindings-window.height = 1/2
keybindings-window.height = 1/2
# see configuration for tree in thread window above
keybindings-window.tree.branch.foreground = red
keybindings-window.tree.branch.foreground = red
keybindings-window.tree.arrow.foreground = magenta
keybindings-window.tree.arrow.foreground = magenta
keybindings-window.tree.root.foreground = #ffff00
keybindings-window.tree.root.foreground = #ffff00
keybindings-window.tree.data.foreground = white
keybindings-window.tree.data.foreground = white
keybindings-window.tree.data-leaf.foreground = cyan
keybindings-window.tree.data-leaf.foreground = cyan
keybindings-window.tree.arrow.value = "🞂 "
keybindings-window.tree.arrow.value = "🞂 "
keybindings-window.tree.leaf.value = "╰"
keybindings-window.tree.leaf.value = "╰"
keybindings-window.tree.branch.value = "├"
keybindings-window.tree.branch.value = "├"
keybindings-window.tree.spacer.value = "─"
keybindings-window.tree.spacer.value = "─"
keybindings-window.tree.vertical-line.value = "│"
keybindings-window.tree.vertical-line.value = "│"
# autocomplete window
suggestions-window.background = blue
suggestions-window.background = blue
suggestions-window.foreground = yellow
suggestions-window.foreground = yellow
suggestions-window.height = 1/4
suggestions-window.height = 1/4
# the directive belows configure the window at the very bottom of the
# screen that user uses to give command to the program, also is used
# to shows some input errors or other informations
command-window.background = black
command-window.background = black
command-window.foreground = white
command-window.foreground = white
# text to separate keybindig added so far by the user
command-window.command-separator.value = " → "
command-window.command-separator.value = " → "
# colors of the separator above
command-window.command-separator.foreground = yellow
command-window.command-separator.foreground = yellow
command-window.command-separator.background = black
command-window.command-separator.background = black
# color for error message shown in command window
command-window.error.message.background = black
command-window.error.message.background = black
command-window.error.message.foreground = red
command-window.error.message.foreground = red
command-window.error.message.attribute = bold
command-window.error.message.attribute = bold
# color for info message shown in command window
command-window.info.message.foreground = yellow
command-window.info.message.foreground = yellow
command-window.info.message.background = black
command-window.info.message.background = black
command-window.info.message.attribute = bold
command-window.info.message.attribute = bold
# this is the window that show the content of a message
message-window.background = black
message-window.background = black
message-window.foreground = #c9c0c0
message-window.foreground = #c9c0c0
# a marker on the right side of the window to show the position of the
# message is visualized in repect of the message lines length (similar
# to scrollbar in GUI)
message-window.line-position-mark.foreground = white
message-window.line-position-mark.foreground = white
message-window.line-position-mark.background = black
message-window.line-position-mark.background = black
# the text for the marker above
message-window.line-position-mark.value = "⧫"
message-window.line-position-mark.value = "⧫"
# the date format for message
# values starting with '%' will be expanded, allowed values are:
@ -419,15 +419,15 @@ message-window.line-position-mark.value = "⧫"
# - %short-month Jan to Dec
# - %% a percent sign
message-window.date-format.value = "%year %short-month %day %hour:%min"
message-window.date-format.value = "%year %short-month %day %hour:%min"
message-window.attachment-header.prefix.value = "~%──── "
message-window.attachment-header.prefix.value = "~%──── "
message-window.attachment-header.postfix.value = " ────~%"
message-window.attachment-header.postfix.value = " ────~%"
message-window.account.locked.mark.value = " 🔒"
message-window.account.locked.mark.value = " 🔒"
message-window.account.unlocked.mark.value = " 🔓"
message-window.account.unlocked.mark.value = " 🔓"
# the string for the header of attachments in a message, if not
# specified a default is chosen by the software.
@ -437,67 +437,67 @@ message-window.account.unlocked.mark.value = " 🔓"
# below the text printed for toot's visibility level: public,
# unlisted, private or direct
message-window.visibility.public = "🌐"
message-window.visibility.public = "🌐"
message-window.visibility.unlisted = "🔓"
message-window.visibility.unlisted = "🔓"
message-window.visibility.private = "🔒"
message-window.visibility.private = "🔒"
message-window.visibility.direct = "📧"
message-window.visibility.direct = "📧"
# this is the window that allow to browse the attachments of a message
open-attach-window.background = black
open-attach-window.background = black
open-attach-window.foreground = #67998B
open-attach-window.foreground = #67998B
# the colors of selected attachment
open-attach-window.input.selected.background = black
open-attach-window.input.selected.background = black
open-attach-window.input.selected.foreground = #71AF8C
open-attach-window.input.selected.foreground = #71AF8C
# this is the window that allow to browse the links of a message
open-message-link-window.background = black
open-message-link-window.background = black
open-message-link-window.foreground = #FEB200
open-message-link-window.foreground = #FEB200
# the colors of selected link
open-message-link-window.input.selected.background = black
open-message-link-window.input.selected.background = black
open-message-link-window.input.selected.foreground = #FFB200
open-message-link-window.input.selected.foreground = #FFB200
# gemini browser
gemini.favicon = "🌍"
gemini.favicon = "🌍"
gemini.link.scheme.gemini.prefix = "→ "
gemini.link.scheme.gemini.prefix = "→ "
gemini.link.scheme.other.prefix = "➶ "
gemini.link.scheme.other.prefix = "➶ "
gemini.quote.prefix = "🞂 "
gemini.quote.prefix = "🞂 "
gemini.bullet.prefix = "• "
gemini.bullet.prefix = "• "
gemini.h1.prefix = "🞓 "
gemini.h1.prefix = "🞓 "
gemini.h2.prefix = "🞐 "
gemini.h2.prefix = "🞐 "
gemini.h3.prefix = "🞎 "
gemini.h3.prefix = "🞎 "
# this is the window that allow to browse the gemini streams
open-gemini-stream-window.background = black
open-gemini-stream-window.background = black
open-gemini-stream-window.foreground = #FEB200
open-gemini-stream-window.foreground = #FEB200
# the colors of selected stream
open-gemini-stream-window.input.selected.background = black
open-gemini-stream-window.input.selected.background = black
open-gemini-stream-window.input.selected.foreground = #FFB200
open-gemini-stream-window.input.selected.foreground = #FFB200
# window for managing gemini certificate
@ -519,33 +519,26 @@ gemini-certificates-window.access-time.foreground = green
#chat list window
chats-list-window.background = black
chats-list-window.background = black
chats-list-window.foreground = red
chats-list-window.foreground = red
# the colors for currently selected chat
chats-list-window.input.selected.background = yellow
chats-list-window.input.selected.background = yellow
chats-list-window.input.selected.foreground = black
chats-list-window.input.selected.foreground = black
# actual chat window
chat-window.date-format.value = "[%hour:%min]"
chat-window.date-format.value = "[%hour:%min]"
# gemlog subscriptions
gemini-subscription-window.background = black
gemini-subscription-window.background = black
gemini-subscription-window.foreground = cyan
gemini-subscription-window.foreground = cyan
gemini-subscription-window.input.selected.background = cyan
gemini-subscription-window.input.selected.background = cyan
gemini-subscription-window.input.selected.foreground = black
# you can instruct the program to open some non gemini link with a
# program installed with your system like below
# syntax open "REGEXP" with "PROGRAM-NAME"
# example:
#
# open "https?://.+mp3" with "mpv"
gemini-subscription-window.input.selected.foreground = black

View File

@ -153,4 +153,19 @@ color-regexp = ":rendering" cyan
# ignore-user-regexp = "@domain-name$"
# ignore-user-regexp = "^user-name@domain-name"
# ignore-user-regexp = "^user-name@domain-name"
# you can instruct the program to open some non gemini link with a
# program installed with your system like below
# syntax open "REGEXP" with "PROGRAM-NAME" [use cache]
# example:
#
# open "https?://.+mp3" with "mpv"
#
# you can open mpv in a new terminal this way:
#
# open "https?://.+mp3" with "xterm -e mpv"
#
# open png files with gimp but cache them before
# ▼▼▼▼▼▼▼▼▼
# open "https?://png$" with "gimp" use cache

View File

@ -105,27 +105,37 @@
(first-elt res))))
(defun open-attachment (url)
(flet ((add-extension (cached-value)
(strcat (to-s cached-value) (get-extension url))))
(let ((cached (db:cache-get-value url)))
(if (not cached)
(let* ((cached-file-name (add-extension (db:cache-put url)))
(cached-output-file (os-utils:cached-file-path cached-file-name))
(stream (get-url-content url)))
(fs:create-file cached-output-file :skip-if-exists t)
(with-open-file (out-stream
cached-output-file
:element-type '(unsigned-byte 8)
:if-does-not-exist :error
:if-exists :supersede
:direction :output)
(loop for byte = (read-byte stream nil nil) while byte do
(write-byte byte out-stream)))
(open-attachment url))
(let ((cached-file (os-utils:cached-file-path (add-extension cached))))
(if (or (not (fs:file-exists-p cached-file))
(<= (fs:file-size cached-file) 0))
(labels ((add-extension (cached-value)
(strcat (to-s cached-value) (get-extension url)))
(fill-cache (url)
(let* ((cached-file-name (add-extension (db:cache-put url)))
(cached-output-file (os-utils:cached-file-path cached-file-name))
(stream (get-url-content url)))
(fs:create-file cached-output-file :skip-if-exists t)
(with-open-file (out-stream
cached-output-file
:element-type '(unsigned-byte 8)
:if-does-not-exist :error
:if-exists :supersede
:direction :output)
(loop for byte = (read-byte stream nil nil) while byte do
(write-byte byte out-stream))))))
(multiple-value-bind (program use-cache-p)
(swconf:link-regex->program-to-use url)
(let ((cached (db:cache-get-value url)))
(if (not cached)
(if (and program
(not use-cache-p))
(os-utils:open-link-with-program program url)
(progn
(db:cache-invalidate url)
(open-attachment url))
(os-utils:xdg-open cached-file)))))))
(fill-cache url)
(open-attachment url)))
(let ((cached-file (os-utils:cached-file-path (add-extension cached))))
(if (or (not (fs:file-exists-p cached-file))
(<= (fs:file-size cached-file) 0))
(progn
(db:cache-invalidate url)
(open-attachment url))
(if program
(os-utils:open-link-with-program program url)
(os-utils:xdg-open cached-file)))))))))

View File

@ -29,7 +29,7 @@
;; COMMENT*
;; SERVER-ASSIGN := SERVER-KEY BLANKS ASSIGN BLANKS GENERIC-VALUE BLANKS
;; USERNAME-ASSIGN := USERNAME-KEY BLANKS WITH BLANKS GENERIC-VALUE BLANKS
;; OPEN-LINK-HELPER := OPEN-LINK-HELPER-KEY BLANKS ASSIGN BLANKS REGEXP PROGRAM-NAME
;; OPEN-LINK-HELPER := OPEN-LINK-HELPER-KEY BLANKS ASSIGN BLANKS REGEXP PROGRAM-NAME BLANKS USE-CACHE
;; GENERIC-ASSIGN := (and key blanks assign blanks
;; (or quoted-string
;; hexcolor
@ -43,6 +43,8 @@
;; BLANKS := (BLANK)*
;; FILEPATH := QUOTED-STRING
;; PROGRAM-NAME := QUOTED-STRING
;; USE-CACHE := USE BLANKS CACHE
;; CACHE := "cache"
;; USE := "use"
;; SERVER-KEY := "server"
;; USERNAME-KEY := "username"
@ -287,40 +289,57 @@
(program-name
:initform nil
:initarg :program-name
:accessor program-name))
:accessor program-name)
(use-cache
:initform t
:initarg :use-cache
:reader use-cache-p
:writer (setf use-cache)))
(: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)) object
(format stream "re: ~s program: ~s" re program-name))))
(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))))
(defun make-open-link-helper (re program-name)
(defun make-open-link-helper (re program-name use-cache)
(assert (stringp program-name))
(assert (stringp re))
(make-instance 'open-link-helper
:re re
:program-name program-name))
:re re
:program-name program-name
:use-cache use-cache))
(defrule use "use"
(:text t))
(defrule cache "cache"
(:text t))
(defrule use-cache (and use blanks cache))
(defrule open-link-helper
(and open-link-helper-key
blanks
regexp ; 2
regexp ; 2 link-pattern
blanks
with
blanks
regexp ; 6
blanks)
regexp ; 6 program to use
blanks
(? (and use-cache ; 8 use cache?
blanks)))
(:function (lambda (args)
(list :open-link-helper
(make-open-link-helper (elt args 2) (elt args 6))))))
(make-open-link-helper (elt args 2) (elt args 6) (elt args 8))))))
(defrule filepath quoted-string)
(defparameter *already-included-files* ())
(defrule use-file (and "use" blanks filepath blanks)
(defrule use-file (and use blanks filepath blanks)
(:function (lambda (a)
(let ((file (third a)))
(if (find file *already-included-files* :test #'string=)
@ -772,7 +791,8 @@
(when-let ((found (find-if (lambda (a)
(cl-ppcre:scan (re a) link))
(config-all-link-open-program))))
(program-name found)))
(values (program-name found)
(use-cache-p found))))
(defun config-win-focus-mark ()
(values (access:accesses *software-configuration*