Added configuration for diff2html

This commit is contained in:
2026-08-13 12:43:44 +02:00
parent d1fe41b5cc
commit 302dc06e89
3 changed files with 68 additions and 5 deletions
+2 -3
View File
@@ -5,6 +5,7 @@
"private/config.rkt" "private/config.rkt"
"private/diff.rkt" "private/diff.rkt"
"private/info.rkt" "private/info.rkt"
"private/utils.rkt"
simple-log simple-log
racket/string racket/string
net/sendurl net/sendurl
@@ -62,9 +63,7 @@
; result : The entered line or an EOF object. ; result : The entered line or an EOF object.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (git-prompt p) (define (git-prompt p)
(display p) (input-prompt p))
(flush-output)
(read-line))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; goal : Add --porcelain to a Git argument list when it is absent. ; goal : Add --porcelain to a Git argument list when it is absent.
+37 -1
View File
@@ -6,10 +6,13 @@
xml xml
racket/string racket/string
"config.rkt" "config.rkt"
"utils.rkt"
) )
(provide diff->html (provide diff->html
show->html) show->html
config-diff2html
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helper functions ;; Helper functions
@@ -57,6 +60,39 @@
;; Exported functions ;; Exported functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (config-diff2html)
(define (checker f)
(λ (inp)
(let ((url (string-trim inp)))
(if (string=? url "")
(f)
(if (valid-http-or-file-url? url)
url
(begin
(displayln "! Not a valid url, please input a valid url")
#f)))))
)
(define (inp name f)
(input-prompt (string-join
(list
(format "Give the url for the ~a" name)
"Enter keeps the current value:"
(string-append " - " (f))
">")
"\n")
#:loop-until (checker f)))
(let ((h-css (inp "Highlighting CSS" highlight-css))
(d-css (inp "Diff2Html CSS" diff2html-min-css))
(d-js (inp "Diff2Html UI Javascript" diff2html-ui-min-js))
)
(cfg-set! 'diff 'highlight-css h-css)
(cfg-set! 'diff 'diff2html-min-css d-css)
(cfg-set! 'diff 'diff2html-ui-min-js d-js))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; goal : Render a Git diff in a temporary HTML file. ; goal : Render a Git diff in a temporary HTML file.
; pre : diff is a unified Git diff string. ; pre : diff is a unified Git diff string.
+29 -1
View File
@@ -1,4 +1,32 @@
#lang racket/base #lang racket/base
(provide config) (require net/url)
(provide input-prompt
valid-http-or-file-url?
)
(define (input-prompt p #:loop-until [until (λ (x) x)])
(let loop ()
(display p)
(flush-output)
(let ((inp (read-line)))
(let ((i (until inp)))
(if i
i
(loop)))
)
)
)
(define (valid-http-or-file-url? value)
(if (not (string? value))
#f
(with-handlers ([exn:fail? (λ (exn) #f)])
(let ((url (string->url value)))
(and
(member (url-scheme url) '("http" "https" "file"))
(string? (url-host url))
(not (string=? (url-host url) "")))))))