Skip to content

Commit afa74da

Browse files
committed
code: Implements color
1 parent bd4144c commit afa74da

6 files changed

Lines changed: 71 additions & 59 deletions

File tree

lisp/_prepare.el

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
458458
:type 'boolean
459459
:group 'eask)
460460

461+
(defcustom eask-level-color
462+
'((debug . ansi-blue)
463+
(log . ansi-white)
464+
(info . ansi-cyan)
465+
(warn . ansi-yellow)
466+
(error . ansi-red))
467+
"Alist of each log level's color, in (SYMBOL . ANSI-FUNCTION)."
468+
:type 'alist
469+
:group 'eask)
470+
461471
(defun eask--verb2lvl (symbol)
462472
"Convert verbosity SYMBOL to level."
463473
(cl-case symbol
@@ -493,15 +503,12 @@ and the BODY will be executed silently."
493503
(defun eask-warn (msg &rest args) (apply #'eask--msg 'warn "[WARNING]" msg args))
494504
(defun eask-error (msg &rest args) (apply #'eask--msg 'error "[ERROR]" msg args))
495505

496-
(defmacro eask-log-2 (msg &rest args)
497-
""
498-
(declare (indent 2) (debug t))
499-
`(eask--msg 'log "[LOG]" (eask-with-ansi ,msg ,@args)))
500-
501-
(defun eask--msg (level prefix msg &rest args)
506+
(defun eask--msg (symbol prefix msg &rest args)
502507
"If LEVEL is at or below `eask-verbosity', log message."
503-
(eask-with-verbosity level
504-
(message "%s" (apply #'eask--format prefix msg args))))
508+
(eask-with-verbosity symbol
509+
(let* ((ansi-function (cdr (assq symbol eask-level-color)))
510+
(output (funcall ansi-function (apply #'eask--format prefix msg args))))
511+
(message "%s" output))))
505512

506513
(defun eask--format (prefix fmt &rest args)
507514
"Format Eask messages."
@@ -511,15 +518,6 @@ and the BODY will be executed silently."
511518
fmt)
512519
args))
513520

514-
(defmacro eask-with-ansi (fmt &rest args)
515-
"Simply wrapper for macro `with-ansi'."
516-
`(with-ansi (format ,fmt ,@args)))
517-
518-
(defmacro eask-message (fmt &rest args)
519-
"Like function `message' but with color."
520-
(declare (indent 2) (debug t))
521-
`(message (concat (eask-with-ansi ,fmt ,@args) "\n")))
522-
523521
;;
524522
;;; File
525523

lisp/checkdoc.el

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
;;
1010
;; Initialization options:
1111
;;
12-
;; [names..] files you want checkdoc to run on
12+
;; [files..] files you want checkdoc to run on
1313
;;
1414

1515
;;; Code:
@@ -19,6 +19,17 @@
1919
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
2020
nil t)
2121

22+
(defun eask--help-checkdoc ()
23+
"Print help if command failed"
24+
(message "")
25+
(message "You need to specify file(s) you want the checkdoc to run on")
26+
(message "")
27+
(message " $ eask %s FILE-1 FILE-2" (eask-command))
28+
(message "")
29+
(message "Or edit Eask file with [files] specifier")
30+
(message "")
31+
(message " [+] (files \"FILE-1\" \"FILE-2\")"))
32+
2233
(defun eask--checkdoc-print-error (text start end &optional unfixable)
2334
"Print error for checkdoc."
2435
(let ((msg (concat (checkdoc-buffer-label) ":"
@@ -41,17 +52,6 @@
4152
(if-let ((files (or (eask-args) (eask-package-el-files))))
4253
(mapcar #'eask--checkdoc-file files)
4354
(eask-info "(No files have been checked (checkdoc)")
44-
(eask--checkdoc-help)))
45-
46-
(defun eask--checkdoc-help ()
47-
"Print help if command failed"
48-
(message "")
49-
(message "You need to specify file(s) you want the checkdoc to run on")
50-
(message "")
51-
(message " $ eask %s FILE-1 FILE-2" (eask-command))
52-
(message "")
53-
(message "Or edit Eask file with [files] specifier")
54-
(message "")
55-
(message " [+] (files \"FILE-1\" \"FILE-2\")"))
55+
(eask--help-checkdoc)))
5656

5757
;;; checkdoc.el ends here

lisp/compile.el

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
2020
nil t)
2121

22+
(defun eask--help-compile ()
23+
"Print help if command failed"
24+
(message "")
25+
(message "You need to specify file(s) you want to compile")
26+
(message "")
27+
(message " $ eask %s FILE-1 FILE-2" (eask-command))
28+
(message "")
29+
(message "Or edit Eask file with [files] specifier")
30+
(message "")
31+
(message " [+] (files \"FILE-1\" \"FILE-2\")"))
32+
2233
;; Handle options
2334
(when (eask-strict-p) (setq byte-compile-error-on-warn t))
2435
(when (= eask-verbosity 4) (setq byte-compile-verbose t))
@@ -41,17 +52,6 @@
4152
(when (eask--byte-compile-file filename) (push filename compiled))))
4253
(eask-info "(Total of %s files compiled)" (length compiled)))
4354
(eask-info "(No files have been compiled)")
44-
(eask--compile-help)))
45-
46-
(defun eask--compile-help ()
47-
"Print help if command failed"
48-
(message "")
49-
(message "You need to specify file(s) you want to compile")
50-
(message "")
51-
(message " $ eask %s FILE-1 FILE-2" (eask-command))
52-
(message "")
53-
(message "Or edit Eask file with [files] specifier")
54-
(message "")
55-
(message " [+] (files \"FILE-1\" \"FILE-2\")"))
55+
(eask--help-compile)))
5656

5757
;;; compile.el ends here

lisp/extern/ansi.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ This variable affects `with-ansi', `with-ansi-princ'."
130130
`(,alias (string &rest objects)
131131
,(list 'backquote (list fn ',string ',@objects)))))
132132
(append
133-
(mapcar 'car ansi-colors)
134-
(mapcar 'car ansi-on-colors)
135-
(mapcar 'car ansi-styles)
136-
(mapcar 'car ansi-csis)))
133+
(mapcar 'car ansi-colors)
134+
(mapcar 'car ansi-on-colors)
135+
(mapcar 'car ansi-styles)
136+
(mapcar 'car ansi-csis)))
137137
,(cons 'ansi--concat body))))
138138

139139
(defmacro with-ansi-princ (&rest body)
@@ -149,7 +149,8 @@ FORMAT-STRING and OBJECTS are processed same as `apply'."
149149
effect-or-code
150150
(ansi--code effect-or-code)))
151151
(text (apply 'format format-string objects)))
152-
(format "\e[%dm%s\e[%sm" code text ansi-reset)))
152+
(if ansi-inhibit-ansi text
153+
(format "\e[%dm%s\e[%sm" code text ansi-reset))))
153154

154155
(defun ansi-csi-apply (effect-or-char &optional reps)
155156
"Apply EFFECT-OR-CHAR REPS (1 default) number of times."

lisp/info.el

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@
1414
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
1515
nil t)
1616

17+
(defun eask--help-info ()
18+
"Print help if command failed"
19+
)
20+
1721
(defun eask--print-info (key)
1822
"Print package information."
1923
(when-let ((info (eask-package-get key)))
2024
(message " %s" info)))
2125

2226
(eask-start
23-
(eask--print-info :name)
24-
(eask--print-info :version)
25-
(eask--print-info :description))
27+
(if eask-package
28+
(progn
29+
(eask--print-info :name)
30+
(eask--print-info :version)
31+
(eask--print-info :description))
32+
(eask-info "(Eask file has no package information)")
33+
(eask--help-info)))
2634

2735
;;; info.el ends here

lisp/install.el

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,25 @@
2323

2424
(eask-load "package") ; load dist path
2525

26+
(defun eask--help-install ()
27+
"Print help if command failed"
28+
)
29+
2630
(eask-start
2731
(eask-pkg-init)
2832
(if-let ((names (eask-args)))
2933
;; If package [name..] are specified, we try to install it
3034
(eask-progress "Installing" names "... done!" #'eask-package-install)
3135
;; Else we try to install package from the working directory
32-
(let* ((packaged (eask-packaged-file))
33-
(target (or packaged
34-
eask-package-file
35-
(expand-file-name "./"))))
36-
(if packaged
37-
(eask-info "✓ Loading packaged artefact in %s... done!" target)
38-
(eask-info "? Packaged artefact not found, install directly to %s..." target))
39-
(add-to-list 'load-path (expand-file-name (eask-packaged-name) package-user-dir))
40-
(package-install-file target))))
36+
(if-let* ((packaged (eask-packaged-file))
37+
(target (or packaged eask-package-file)))
38+
(progn
39+
(if packaged
40+
(eask-info "✓ Loading packaged artefact in %s... done!" target)
41+
(eask-info "? Packaged artefact not found, install directly to %s..." target))
42+
(add-to-list 'load-path (expand-file-name (eask-packaged-name) package-user-dir))
43+
(package-install-file target))
44+
(eask-info "(No files have been intalled)")
45+
(eask--help-install))))
4146

4247
;;; install.el ends here

0 commit comments

Comments
 (0)