Browse Source

Seems we can't get color and style. Choosed color

Leo 10 years ago
parent
commit
75aac08b2f
12 changed files with 137 additions and 17 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. 1 0
      src/command_def.ml
  9. 7 2
      src/list_rc.ml
  10. 104 0
      src/messages.ml
  11. 2 1
      src/oclaunch.ml
  12. 2 1
      src/state.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 ();;

+ 1 - 0
src/command_def.ml

@@ -84,6 +84,7 @@ let commands =
     args
     args
 
 
     (fun rc_file_name reset_tmp list_commands add delete number modify num_cmd () ->
     (fun rc_file_name reset_tmp list_commands add delete number modify num_cmd () ->
+        Messages.info "Parsed command line arguments";
        (* Use given rc file, should run the nth argument if present *)
        (* Use given rc file, should run the nth argument if present *)
        Const.rc_file := rc_file_name;
        Const.rc_file := rc_file_name;
        (* Obtain data from rc_file *)
        (* Obtain data from rc_file *)

+ 7 - 2
src/list_rc.ml

@@ -38,11 +38,16 @@ open Core.Std;;
 
 
 (* This modules contains function to list the content of the rc file *)
 (* This modules contains function to list the content of the rc file *)
 
 
-(* Display the command with its number, with a '*' if it is the current one *)
+(* Display the command with its number, with a '*' and different color if it is the current one *)
 let disp_cmd_num current_number number command =
 let disp_cmd_num current_number number command =
     (* If number is the global current one print a '*' *)
     (* If number is the global current one print a '*' *)
     let prepend = (if current_number = number then "* " else "  ") in
     let prepend = (if current_number = number then "* " else "  ") in
-    printf "%s%i: %s\n" prepend number command
+    sprintf "%s%i: %s\n" prepend number command
+    |> (fun concatenated_msg ->
+            match prepend with
+            | "* " -> Messages.ok concatenated_msg
+            | "  " -> Messages.info concatenated_msg
+            | _ -> assert false)
 ;;
 ;;
 
 
 (* Function which list *)
 (* Function which list *)

+ 104 - 0
src/messages.ml

@@ -0,0 +1,104 @@
+(******************************************************************************)
+(* 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 style and then color, color only works *)
+    style |>
+    (function
+        | Bold -> Color_print.bold message
+        | Underline -> Color_print.underline message
+        | Normal -> Color_print.normal message
+    ) |>
+    (fun styled_message ->
+        match color with
+        | 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
+    ) |> (* 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
 ;;
 ;;

+ 2 - 1
src/state.ml

@@ -49,5 +49,6 @@ let get_current () =
 (* Display current number *)
 (* Display current number *)
 let print_current () =
 let print_current () =
     (* Display the number *)
     (* Display the number *)
-    printf "Current state: %i\n" (get_current ())
+    sprintf "Current state: %i\n" (get_current ())
+    |> Messages.ok
 ;;
 ;;