Browse Source

Add basic message styling

Leo 10 years ago
parent
commit
746715ae78
9 changed files with 128 additions and 14 deletions
  1. 1 0
      CHANGELOG.md
  2. 2 1
      INSTALL.md
  3. 3 3
      README.md
  4. 1 1
      VERSION
  5. 2 2
      _oasis
  6. 4 0
      dev.json
  7. 8 6
      setup.ml
  8. 105 0
      src/messages.ml
  9. 2 1
      src/oclaunch.ml

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 ### v0.2.2
 ### v0.2.2
  + Locking tmp file to prevent launching two times the same item (**not tested
  + Locking tmp file to prevent launching two times the same item (**not tested
    enough**)
    enough**)
+ + Messages displayed with bold, underline and colors.
 
 
 ### v0.2.1
 ### v0.2.1
  + Add new command line option:
  + Add new command line option:

+ 2 - 1
INSTALL.md

@@ -1,5 +1,5 @@
 <!--- OASIS_START --->
 <!--- OASIS_START --->
-<!--- DO NOT EDIT (digest: 788c36d836a82ea33e30031012ae594a) --->
+<!--- DO NOT EDIT (digest: 9e32abada3d7ab0ee6974517a830cab5) --->
 
 
 This is the INSTALL file for the OcLaunch distribution.
 This is the INSTALL file for the OcLaunch distribution.
 
 
@@ -14,6 +14,7 @@ In order to compile this package, you will need:
 * ocaml
 * ocaml
 * findlib
 * findlib
 * core
 * core
+* core_extended
 * atdgen
 * atdgen
 
 
 Installing
 Installing

+ 3 - 3
README.md

@@ -1,13 +1,13 @@
 <!--- OASIS_START --->
 <!--- OASIS_START --->
-<!--- DO NOT EDIT (digest: f75668d8c51e2897d85573696c9f54a7) --->
+<!--- DO NOT EDIT (digest: a582ff5eef328f0f8ccffbe2c68e80aa) --->
 
 
-OcLaunch - Launch commands automatically
+OcLaunch - Launch commands automagically
 ========================================
 ========================================
 
 
 OcLaunch is a command-line tool to launch successively (each time the program
 OcLaunch is a command-line tool to launch successively (each time the program
 is called) commands. It is designed to be used with any program, interactive
 is called) commands. It is designed to be used with any program, interactive
 or not. Feedback is welcome at leowzukw@vmail.me. Help at
 or not. Feedback is welcome at leowzukw@vmail.me. Help at
-https://gitlab.com/WzukW/oclaunch/wikis/home. Try it, it works automatically!
+https://gitlab.com/WzukW/oclaunch/wikis/home. Try it, it works automagically!
 
 
 See the file [INSTALL.md](INSTALL.md) for building and installation
 See the file [INSTALL.md](INSTALL.md) for building and installation
 instructions.
 instructions.

+ 1 - 1
VERSION

@@ -1 +1 @@
-0.2.2-rc1
+0.2.2

+ 2 - 2
_oasis

@@ -1,6 +1,6 @@
 OASISFormat: 0.4
 OASISFormat: 0.4
 Name:        OcLaunch
 Name:        OcLaunch
-Version:     0.2.2-rc1
+Version:     0.2.2
 Synopsis:    Launch commands automagically
 Synopsis:    Launch commands automagically
 Authors:     Joly Clément <leowzukw@vmail.me>
 Authors:     Joly Clément <leowzukw@vmail.me>
 Maintainers: Joly Clément <leowzukw@vmail.me>
 Maintainers: Joly Clément <leowzukw@vmail.me>
@@ -28,5 +28,5 @@ PreBuildCommand: echo "Atdgen executed"
 Executable oclaunch
 Executable oclaunch
   Path:       src
   Path:       src
   MainIs:     oclaunch.ml
   MainIs:     oclaunch.ml
-  BuildDepends: core, atdgen, threads
+  BuildDepends: core, core_extended, atdgen, threads
   CompiledObject: best
   CompiledObject: best

+ 4 - 0
dev.json

@@ -0,0 +1,4 @@
+{
+  "progs": [ "task", "task +next", "task +rdv", "echo \"Finish\"" ],
+  "settings": []
+}

+ 8 - 6
setup.ml

@@ -1,7 +1,7 @@
 (* setup.ml generated for the first time by OASIS v0.4.5 *)
 (* setup.ml generated for the first time by OASIS v0.4.5 *)
 
 
 (* OASIS_START *)
 (* OASIS_START *)
-(* DO NOT EDIT (digest: bb79ecfef01ee1df940bd23f58193b7b) *)
+(* DO NOT EDIT (digest: f08446edf2e3b491355f76e0fc2fb353) *)
 (*
 (*
    Regenerated by OASIS v0.4.5
    Regenerated by OASIS v0.4.5
    Visit http://oasis.forge.ocamlcore.org for more information and
    Visit http://oasis.forge.ocamlcore.org for more information and
@@ -6673,7 +6673,7 @@ let setup_t =
           alpha_features = ["stdfiles_markdown"; "compiled_setup_ml"];
           alpha_features = ["stdfiles_markdown"; "compiled_setup_ml"];
           beta_features = [];
           beta_features = [];
           name = "OcLaunch";
           name = "OcLaunch";
-          version = "0.2.1-rc1";
+          version = "0.2.2-rc1";
           license =
           license =
             OASISLicense.DEP5License
             OASISLicense.DEP5License
               (OASISLicense.DEP5Unit
               (OASISLicense.DEP5Unit
@@ -6687,12 +6687,12 @@ let setup_t =
           maintainers = ["Joly Cl\195\169ment <leowzukw@vmail.me>"];
           maintainers = ["Joly Cl\195\169ment <leowzukw@vmail.me>"];
           authors = ["Joly Cl\195\169ment <leowzukw@vmail.me>"];
           authors = ["Joly Cl\195\169ment <leowzukw@vmail.me>"];
           homepage = Some "http://www.oclaunch.tuxfamily.org";
           homepage = Some "http://www.oclaunch.tuxfamily.org";
-          synopsis = "Launch commands automatically";
+          synopsis = "Launch commands automagically";
           description =
           description =
             Some
             Some
               [
               [
                  OASISText.Para
                  OASISText.Para
-                   "OcLaunch is a command-line tool to launch successively (each time the program is called) commands. It is designed to be used with any program, interactive or not. Feedback is welcome at leowzukw@vmail.me. Help at https://gitlab.com/WzukW/oclaunch/wikis/home. Try it, it works automatically!"
+                   "OcLaunch is a command-line tool to launch successively (each time the program is called) commands. It is designed to be used with any program, interactive or not. Feedback is welcome at leowzukw@vmail.me. Help at https://gitlab.com/WzukW/oclaunch/wikis/home. Try it, it works automagically!"
               ];
               ];
           categories = [];
           categories = [];
           conf_type = (`Configure, "internal", Some "0.4");
           conf_type = (`Configure, "internal", Some "0.4");
@@ -6749,6 +6749,7 @@ let setup_t =
                       bs_build_depends =
                       bs_build_depends =
                         [
                         [
                            FindlibPackage ("core", None);
                            FindlibPackage ("core", None);
+                           FindlibPackage ("core_extended", None);
                            FindlibPackage ("atdgen", None);
                            FindlibPackage ("atdgen", None);
                            FindlibPackage ("threads", None)
                            FindlibPackage ("threads", None)
                         ];
                         ];
@@ -6776,7 +6777,8 @@ let setup_t =
        };
        };
      oasis_fn = Some "_oasis";
      oasis_fn = Some "_oasis";
      oasis_version = "0.4.5";
      oasis_version = "0.4.5";
-     oasis_digest = Some "H\166\135\234\129e\007T\151XUH\024+\138\149";
+     oasis_digest =
+       Some "\213\002\026\240\142!\131\164/\176u\007\235\131\004\188";
      oasis_exec = None;
      oasis_exec = None;
      oasis_setup_args = [];
      oasis_setup_args = [];
      setup_update = false
      setup_update = false
@@ -6784,6 +6786,6 @@ let setup_t =
 
 
 let setup () = BaseSetup.setup setup_t;;
 let setup () = BaseSetup.setup setup_t;;
 
 
-# 6788 "setup.ml"
+# 6790 "setup.ml"
 (* OASIS_STOP *)
 (* OASIS_STOP *)
 let () = setup ();;
 let () = setup ();;

+ 105 - 0
src/messages.ml

@@ -0,0 +1,105 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014-2015                                        *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+open Core.Std;;
+
+(* Modules to manage output messages, with color *)
+
+(* TODO
+    * allow to set verbosity
+    * allow to toggle colors
+    * allow to display bold & underlined messages *)
+
+(* Types corresponding to some colors & style of the Core_extended.Color_print
+ * library *)
+type color =
+    | Green
+    | Red
+    | Yellow
+    | White
+;;
+
+type style =
+    | Bold
+    | Underline
+    | Normal
+;;
+
+(* General function to print things *)
+let print ~color ~style message =
+    let open Core_extended in
+    (* This module create proper escapement to display text with bold/color... *)
+    (* Define color and then style *)
+    color |>
+    (function
+        | Green -> Color_print.color ~color:`Green message
+        | Red -> Color_print.color ~color:`Red message
+        | Yellow -> Color_print.color ~color:`Yellow message
+        | White -> Color_print.color ~color:`White message)
+    |>
+    (fun colored_message ->
+        match style with
+        | Bold -> Color_print.bold colored_message
+        | Underline -> Color_print.underline colored_message
+        | Normal -> Color_print.normal colored_message
+    )
+    |> (* Finaly print escaped string *)
+    (* XXX End-line automatically inserted, maybe not the best option *)
+    printf "%s\n"
+;;
+
+(* Print debugging, information, important... messages *)
+(* XXX Partial applications *)
+let debug message =
+    let mess = (Time.now()|> Time.to_string) ^ " " ^ message in
+    print ~color:White ~style:Bold mess
+;;
+
+let info =
+    print ~color:White ~style:Normal
+;;
+
+let warning =
+    print ~color:Red ~style:Bold
+;;
+
+let ok =
+    print ~color:Green ~style:Bold
+;;
+
+let tips =
+    print ~color:Yellow ~style:Normal
+;;

+ 2 - 1
src/oclaunch.ml

@@ -38,7 +38,7 @@ open Core.Std;;
 
 
 (* Variable to store version number *)
 (* Variable to store version number *)
 (* TODO Get value from file *)
 (* TODO Get value from file *)
-let version_number = "0.2.2-rc1";;
+let version_number = "0.2.2";;
 
 
 (* Variable store building information *)
 (* Variable store building information *)
 (* XXX This is fake value, it corresponds to the running
 (* XXX This is fake value, it corresponds to the running
@@ -46,5 +46,6 @@ let version_number = "0.2.2-rc1";;
 let build_info = ( "Build with OCaml version " ^ (Sys.ocaml_version) ^ " on " ^ (Sys.os_type) );;
 let build_info = ( "Build with OCaml version " ^ (Sys.ocaml_version) ^ " on " ^ (Sys.os_type) );;
 
 
 let () =
 let () =
+  Messages.debug "Started";
   Command.run ~version:version_number ~build_info:build_info Command_def.commands
   Command.run ~version:version_number ~build_info:build_info Command_def.commands
 ;;
 ;;