mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 09:14:18 +00:00
vtable fixes for tty rendering (bug#80312)
* lisp/emacs-lisp/vtable.el (vtable--insert-line): Do not produce a divider after the final column. This thinko is more noticeable on a tty. (vtable--insert-header-line): On a tty, nullify indicator padding. (vtable-tty-char-pixel-width): New defconst. (vtable--compute-width): On a tty, adjust column width specified in pixels down by a factor of 'vtable-tty-char-pixel-width'. (vtable--alter-column-width): On a tty, adjust column width in characters, otherwise in pixels.
This commit is contained in:
parent
16f1ca1acc
commit
003962fa5f
1 changed files with 29 additions and 11 deletions
|
|
@ -680,7 +680,7 @@ itself in the new buffer."
|
|||
(add-face-text-property
|
||||
start (point)
|
||||
(elt column-colors (mod index (length column-colors)))))
|
||||
(when divider
|
||||
(when (and divider (not last))
|
||||
(insert divider)
|
||||
(setq start (point))))))
|
||||
(cdr line))
|
||||
|
|
@ -770,10 +770,17 @@ itself in the new buffer."
|
|||
buffer)
|
||||
name))
|
||||
(let* ((indicator-lead-width
|
||||
;; We want the indicator to not be quite flush right.
|
||||
(/ (vtable--char-width table) 2.0))
|
||||
(indicator-pad-width (- (vtable--char-width table)
|
||||
indicator-lead-width))
|
||||
(if (display-graphic-p)
|
||||
;; On a graphical frame, we want the indicator to
|
||||
;; not be quite flush right...
|
||||
(/ (vtable--char-width table) 2.0)
|
||||
0))
|
||||
(indicator-pad-width
|
||||
(if (display-graphic-p)
|
||||
;; ...and adjust its padding.
|
||||
(- (vtable--char-width table)
|
||||
indicator-lead-width)
|
||||
0))
|
||||
(fill-width
|
||||
(+ (- (elt widths index)
|
||||
(string-pixel-width displayed buffer)
|
||||
|
|
@ -885,6 +892,13 @@ If NEXT, do the next column."
|
|||
(string-pixel-width (propertize "x" 'face (vtable-face table))
|
||||
(vtable-buffer table)))
|
||||
|
||||
(defconst vtable-tty-char-pixel-width 10
|
||||
"This is a conversion factor from pixels to characters for tty terminals.
|
||||
This represents the average number of pixels of a character displayed on
|
||||
a tty terminal.
|
||||
This is applied if a column's width is specified in pixels and the
|
||||
vtable is being rendered on a tty terminal.")
|
||||
|
||||
(defun vtable--compute-width (table spec)
|
||||
(cond
|
||||
((numberp spec)
|
||||
|
|
@ -892,7 +906,9 @@ If NEXT, do the next column."
|
|||
((string-match "\\([0-9.]+\\)ex" spec)
|
||||
(* (string-to-number (match-string 1 spec)) (vtable--char-width table)))
|
||||
((string-match "\\([0-9.]+\\)px" spec)
|
||||
(string-to-number (match-string 1 spec)))
|
||||
(/ (string-to-number (match-string 1 spec))
|
||||
;; Adjust pixels down by a factor for tty terminals.
|
||||
(if (display-graphic-p) 1 vtable-tty-char-pixel-width)))
|
||||
((string-match "\\([0-9.]+\\)%" spec)
|
||||
(/ (* (string-to-number (match-string 1 spec)) (window-width nil t))
|
||||
100))
|
||||
|
|
@ -1034,13 +1050,15 @@ Interactively, N is the prefix argument."
|
|||
(- (* (vtable--char-width table) (or n 1))))))
|
||||
|
||||
(defun vtable--alter-column-width (table column delta)
|
||||
(let ((widths (vtable--cache-widths (vtable--current-cache table))))
|
||||
(setf (aref widths column)
|
||||
(max (* (vtable--char-width table) 2)
|
||||
(+ (aref widths column) delta)))
|
||||
(let* ((widths (vtable--cache-widths (vtable--current-cache table)))
|
||||
(new-width (max (* (vtable--char-width table) 2)
|
||||
(+ (aref widths column) delta))))
|
||||
(setf (aref widths column) new-width)
|
||||
;; Store the width so it'll be respected on a revert.
|
||||
(setf (vtable-column-width (elt (vtable-columns table) column))
|
||||
(format "%dpx" (aref widths column)))
|
||||
(if (display-graphic-p)
|
||||
(format "%dpx" new-width)
|
||||
new-width))
|
||||
(vtable-revert table)))
|
||||
|
||||
(defun vtable-widen-current-column (&optional n)
|
||||
|
|
|
|||
Loading…
Reference in a new issue