Browse Source

Polish up qmk-compile-json

skullY 6 years ago
parent
commit
df1df433b4
2 changed files with 9 additions and 8 deletions
  1. 5 4
      lib/python/milc.py
  2. 4 4
      lib/python/qmk/cli/compile/json.py

+ 5 - 4
lib/python/milc.py

@@ -273,7 +273,7 @@ class MILC(object):
         self._description = self._arg_parser.description = self._arg_defaults.description = value
 
     def echo(self, text, *args, **kwargs):
-        """Print a string to stdout after formatting.
+        """Print colorized text to stdout, as long as stdout is a tty.
 
         ANSI color strings (such as {fg-blue}) will be converted into ANSI
         escape sequences, and the ANSI reset sequence will be added to all
@@ -284,10 +284,11 @@ class MILC(object):
         if args and kwargs:
             raise RuntimeError('You can only specify *args or **kwargs, not both!')
 
-        args = args or kwargs
-        text = format_ansi(text)
+        if sys.stdout.isatty():
+            args = args or kwargs
+            text = format_ansi(text)
 
-        print(text % args)
+            print(text % args)
 
     def initialize_argparse(self):
         """Prepare to process arguments from sys.argv.

+ 4 - 4
lib/python/qmk/cli/compile/json.py

@@ -25,12 +25,12 @@ def main(cli):
         user_keymap = json.load(fd)
 
     # Generate the keymap
+    keymap_path = qmk.keymap.find_dir(user_keymap['keyboard'])
+    cli.echo('{fg_blue}[QMK]{style_reset_all} Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path)
     qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers'])
-    if sys.stdout.isatty():
-        keymap_path = qmk.keymap.find_dir(user_keymap['keyboard'])
-        cli.echo('Wrote keymap to %s/%s/keymap.c.', keymap_path, user_keymap['keymap'])
+    cli.echo('{fg_blue}[QMK]{style_reset_all} Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
 
     # Compile the keymap
     command = ['make', ':'.join((user_keymap['keyboard'], user_keymap['keymap']))]
-    cli.echo('Compiling keymap with `%s`:', ' '.join(command))
+    cli.echo('{fg_blue}[QMK]{style_reset_all} Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
     subprocess.run(command)