Use hash table to convert from charset
* eat.el (eat--t-dec-line-drawing-chars): New constant containing the hash table. * eat.el (eat--t-write): Use hash-table instead alist while converting from DEC Line Drawing charset.
This commit is contained in:
parent
6271968c86
commit
6a94082eff
1 changed files with 49 additions and 37 deletions
68
eat.el
68
eat.el
|
@ -2362,33 +2362,9 @@ character or its the internal invisible spaces."
|
||||||
(insert (propertize " " 'face face))
|
(insert (propertize " " 'face face))
|
||||||
(backward-char)))))
|
(backward-char)))))
|
||||||
|
|
||||||
(defun eat--t-write (str)
|
(defconst eat--t-dec-line-drawing-chars
|
||||||
"Write STR on display."
|
(eval-and-compile
|
||||||
(let ((face (eat--t-face-face (eat--t-term-face eat--t-term)))
|
(let ((alist '((?+ . ?→)
|
||||||
;; Alist of indices and width of multi-column characters.
|
|
||||||
(multi-col-char-indices nil)
|
|
||||||
(inserted-till 0))
|
|
||||||
;; Copy STR and add face to it.
|
|
||||||
(setq str (propertize str 'face face))
|
|
||||||
;; Convert STR to Unicode according to the current character
|
|
||||||
;; set.
|
|
||||||
(pcase-exhaustive
|
|
||||||
(alist-get (car (eat--t-term-charset eat--t-term))
|
|
||||||
(cdr (eat--t-term-charset eat--t-term)))
|
|
||||||
;; For `us-ascii', the default, no conversion is
|
|
||||||
;; necessary.
|
|
||||||
('us-ascii
|
|
||||||
str)
|
|
||||||
;; `dec-line-drawing' contains various characters useful
|
|
||||||
;; for drawing line diagram, so it is a must. This is
|
|
||||||
;; also possible with `us-ascii', thanks to Unicode, but
|
|
||||||
;; the character set `dec-line-drawing' is usually less
|
|
||||||
;; expensive in terms of bytes needed to transfer than
|
|
||||||
;; `us-ascii'.
|
|
||||||
('dec-line-drawing
|
|
||||||
(dotimes (i (length str))
|
|
||||||
(let ((replacement (alist-get (aref str i)
|
|
||||||
'((?+ . ?→)
|
|
||||||
(?, . ?←)
|
(?, . ?←)
|
||||||
(?- . ?↑)
|
(?- . ?↑)
|
||||||
(?. . ?↓)
|
(?. . ?↓)
|
||||||
|
@ -2423,7 +2399,43 @@ character or its the internal invisible spaces."
|
||||||
(?{ . ?π)
|
(?{ . ?π)
|
||||||
(?| . ?≠)
|
(?| . ?≠)
|
||||||
(?} . ?£)
|
(?} . ?£)
|
||||||
(?~ . ?•)))))
|
(?~ . ?•)))
|
||||||
|
(table (make-hash-table :purecopy t)))
|
||||||
|
(dolist (pair alist)
|
||||||
|
(puthash (car pair) (cdr pair) table))
|
||||||
|
table))
|
||||||
|
"Hash table for DEC Line Drawing charset.
|
||||||
|
|
||||||
|
The key is the output character from client, and value of the
|
||||||
|
character to actually show.")
|
||||||
|
|
||||||
|
(defun eat--t-write (str)
|
||||||
|
"Write STR on display."
|
||||||
|
(let ((face (eat--t-face-face (eat--t-term-face eat--t-term)))
|
||||||
|
;; Alist of indices and width of multi-column characters.
|
||||||
|
(multi-col-char-indices nil)
|
||||||
|
(inserted-till 0))
|
||||||
|
;; Copy STR and add face to it.
|
||||||
|
(setq str (propertize str 'face face))
|
||||||
|
;; Convert STR to Unicode according to the current character
|
||||||
|
;; set.
|
||||||
|
(pcase-exhaustive
|
||||||
|
(alist-get (car (eat--t-term-charset eat--t-term))
|
||||||
|
(cdr (eat--t-term-charset eat--t-term)))
|
||||||
|
;; For `us-ascii', the default, no conversion is
|
||||||
|
;; necessary.
|
||||||
|
('us-ascii
|
||||||
|
str)
|
||||||
|
;; `dec-line-drawing' contains various characters useful
|
||||||
|
;; for drawing line diagram, so it is a must. This is
|
||||||
|
;; also possible with `us-ascii', thanks to Unicode, but
|
||||||
|
;; the character set `dec-line-drawing' is usually less
|
||||||
|
;; expensive in terms of bytes needed to transfer than
|
||||||
|
;; `us-ascii'.
|
||||||
|
('dec-line-drawing
|
||||||
|
(dotimes (i (length str))
|
||||||
|
(let ((replacement
|
||||||
|
(gethash (aref str i) eat--t-dec-line-drawing-chars)))
|
||||||
(when replacement
|
(when replacement
|
||||||
(aset str i replacement))))))
|
(aset str i replacement))))))
|
||||||
;; Find all the multi-column wide characters in STR, using a
|
;; Find all the multi-column wide characters in STR, using a
|
||||||
|
|
Loading…
Add table
Reference in a new issue