(defgroup chess-plain nil
"A minimal, customizable ASCII display."
- :group 'chess-ascii)
+ :group 'chess-display)
(defcustom chess-plain-draw-border nil
"*Non-nil if a border should be drawn (using `chess-plain-border-chars')."
(defcustom chess-plain-border-chars '(?+ ?- ?+ ?| ?| ?+ ?- ?+)
"*Characters used to draw borders."
:group 'chess-plain
- :type '(list character character character character
- character character character character))
+ :type '(list (character :tag "Upper left corner")
+ (character :tag "Upper border")
+ (character :tag "Upper right corner")
+ (character :tag "Left border")
+ (character :tag "Right border")
+ (character :tag "Lower left corner")
+ (character :tag "Lowwer border")
+ (character :tag "Lower right corner")))
(defcustom chess-plain-black-square-char ?.
"*Character used to indicate black squares."
:type '(choice (const 'color) (const 'square-color)))
;; fails somehow
-(defun chess-plain-draw ()
+(defcustom chess-plain-spacing 0
+ "*Number of spaces between pieces."
+ :group 'chess-plain
+ :type 'integer)
+
+(defcustom chess-plain-popup-function 'chess-display-popup-in-window
+ "The function used to popup a chess-plain display."
+ :type 'function
+ :group 'chess-plain)
+
+;;; Code:
+
+(defun chess-plain-handler (event &rest args)
+ (cond
+ ((eq event 'initialize) t)
+ ((eq event 'popup)
+ (if chess-display-popup
+ (funcall chess-plain-popup-function)))
+ ((eq event 'draw)
+ (apply 'chess-plain-draw args))
+ ((eq event 'highlight)
+ (apply 'chess-plain-highlight args))))
+
+(defun chess-plain-draw (position perspective)
"Draw the given POSITION from PERSPECTIVE's point of view.
PERSPECTIVE is t for white or nil for black."
- (if (null (get-buffer-window (current-buffer) t))
- (pop-to-buffer (current-buffer)))
(let ((inhibit-redisplay t)
(pos (point)))
(erase-buffer)
- (let* ((position (chess-display-position nil))
- (inverted (not (chess-display-perspective nil)))
+ (let* ((inverted (not perspective))
(rank (if inverted 7 0))
(file (if inverted 7 0))
beg)
(if chess-plain-draw-border
(insert ? (nth 0 chess-plain-border-chars)
- (make-string 8 (nth 1 chess-plain-border-chars))
+ (make-string (+ 8 (* 7 chess-plain-spacing))
+ (nth 1 chess-plain-border-chars))
(nth 2 chess-plain-border-chars) ?\n))
(while (if inverted (>= rank 0) (< rank 8))
(if chess-plain-draw-border
(t pchar)))))
(add-text-properties begin (point)
(list 'chess-coord
- (chess-rf-to-index rank file))))
+ (chess-rf-to-index rank file)))
+ (when (if inverted (>= file 1) (< file 7))
+ (insert (make-string chess-plain-spacing ? ))))
(setq file (if inverted (1- file) (1+ file))))
(if chess-plain-draw-border
(insert (nth 4 chess-plain-border-chars)))
rank (if inverted (1- rank) (1+ rank))))
(if chess-plain-draw-border
(insert ? (nth 5 chess-plain-border-chars)
- (make-string 8 (nth 6 chess-plain-border-chars))
+ (make-string (+ 8 (* 7 chess-plain-spacing))
+ (nth 6 chess-plain-border-chars))
(nth 7 chess-plain-border-chars) ?\n
? ? (if (not inverted) "abcdefgh" "hgfedcba")))
(set-buffer-modified-p nil)
(goto-char pos))))
(defun chess-plain-highlight (index &optional mode)
- (if (null (get-buffer-window (current-buffer) t))
- (pop-to-buffer (current-buffer)))
(let ((inverted (not (chess-display-perspective nil))))
(save-excursion
(beginning-of-line)
(1+ file)
file)))
(put-text-property (point) (1+ (point)) 'face
- 'chess-display-highlight-face))))
+ (cond
+ ((eq mode :selected)
+ 'chess-plain-highlight-face)
+ (t
+ (chess-display-get-face mode)))))))
(provide 'chess-plain)