Skip to content

Commit f4a26fc

Browse files
authored
support ANSI color output (#13)
* add arduino-cli-compile-color option; apply compilation ansi colors * document arduino-cli-compile-color variable
1 parent 1e1eb61 commit f4a26fc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ You can enable the major flags from `arduino-cli` using similar enumerations.
5858
| `arduino-cli-warnings` | `nil` (default), `'default`, `'more`, `'all` |
5959
| `arduino-cli-verbosity` | `nil` (default), `'quiet`, `'verbose` |
6060
| `arduino-cli-compile-only-verbosity` | `nil`, `t` (default) |
61+
| `arduino-cli-compile-color` | `nil`, `t` (default) |
6162

6263
If you want to automatically enable `arduino-cli-mode` on `.ino` files, you have to get [auto-minor-mode](https://github.com/joewreschnig/auto-minor-mode).
6364
Once that is installed, add the following to your init:

arduino-cli-mode.el

+19-2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,22 @@
9797
:group 'arduino-cli
9898
:type 'boolean)
9999

100+
(defcustom arduino-cli-compile-color t
101+
"If true (default), apply ANSI colors from compilation output."
102+
:group 'arduino-cli
103+
:type 'boolean)
104+
100105
;;; Internal functions
106+
(defun arduino-cli--compilation-filter ()
107+
"Filter function for applying ANSI colors in compilation output."
108+
(when arduino-cli-compile-color
109+
(ansi-color-apply-on-region compilation-filter-start (point-max))))
110+
101111
(define-compilation-mode arduino-cli-compilation-mode "arduino-cli-compilation"
102112
"Arduino-cli specific `compilation-mode' derivative."
103113
(setq-local compilation-scroll-output t)
104-
(require 'ansi-color))
114+
(require 'ansi-color)
115+
(add-hook 'compilation-filter-hook #'arduino-cli--compilation-filter))
105116

106117
(defun arduino-cli--?map-put (m v k)
107118
"Puts V in M under K when V, else return M."
@@ -122,6 +133,11 @@
122133
(when arduino-cli-warnings
123134
(concat " --warnings " (symbol-name arduino-cli-warnings))))
124135

136+
(defun arduino-cli--compile-color ()
137+
"Get the current compilation color setting."
138+
(when (not arduino-cli-compile-color)
139+
" --no-color"))
140+
125141
(defun arduino-cli--general-flags ()
126142
"Add flags to CMD, if set."
127143
(concat (unless arduino-cli-compile-only-verbosity
@@ -131,7 +147,8 @@
131147
"Add flags to CMD, if set."
132148
(concat (arduino-cli--verify)
133149
(arduino-cli--warnings)
134-
(arduino-cli--verbosity)))
150+
(arduino-cli--verbosity)
151+
(arduino-cli--compile-color)))
135152

136153
(defun arduino-cli--add-flags (mode cmd)
137154
"Add general and MODE flags to CMD, if set."

0 commit comments

Comments
 (0)