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:
Akib Azmain Turja 2022-11-28 18:48:38 +06:00
parent 6271968c86
commit 6a94082eff
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

86
eat.el
View file

@ -2362,6 +2362,53 @@ character or its the internal invisible spaces."
(insert (propertize " " 'face face))
(backward-char)))))
(defconst eat--t-dec-line-drawing-chars
(eval-and-compile
(let ((alist '((?+ . ?→)
(?, . ?←)
(?- . ?↑)
(?. . ?↓)
(?0 . ?█)
(?\` . ?<3F>)
(?a . ?▒)
(?b . ?␉)
(?c . ?␌)
(?d . ?␍)
(?e . ?␊)
(?f . )
(?g . )
(?h . ?░)
(?i . ?#)
(?j . ?┘)
(?k . ?┐)
(?l . ?┌)
(?m . ?└)
(?n . ?┼)
(?o . ?⎺)
(?p . ?⎻)
(?q . ?─)
(?r . ?⎼)
(?s . ?⎽)
(?t . ?├)
(?u . ?┤)
(?v . ?┴)
(?w . ?┬)
(?x . ?│)
(?y . ?≤)
(?z . ?≥)
(?{ . )
(?| . ?≠)
(?} . )
(?~ . ?•)))
(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)))
@ -2387,43 +2434,8 @@ character or its the internal invisible spaces."
;; `us-ascii'.
('dec-line-drawing
(dotimes (i (length str))
(let ((replacement (alist-get (aref str i)
'((?+ . ?→)
(?, . ?←)
(?- . ?↑)
(?. . ?↓)
(?0 . ?█)
(?\` . ?<3F>)
(?a . ?▒)
(?b . ?␉)
(?c . ?␌)
(?d . ?␍)
(?e . ?␊)
(?f . )
(?g . )
(?h . ?░)
(?i . ?#)
(?j . ?┘)
(?k . ?┐)
(?l . ?┌)
(?m . ?└)
(?n . ?┼)
(?o . ?⎺)
(?p . ?⎻)
(?q . ?─)
(?r . ?⎼)
(?s . ?⎽)
(?t . ?├)
(?u . ?┤)
(?v . ?┴)
(?w . ?┬)
(?x . ?│)
(?y . ?≤)
(?z . ?≥)
(?{ . )
(?| . ?≠)
(?} . )
(?~ . ?•)))))
(let ((replacement
(gethash (aref str i) eat--t-dec-line-drawing-chars)))
(when replacement
(aset str i replacement))))))
;; Find all the multi-column wide characters in STR, using a