1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
(*
* clock.ml
* --------
* Copyright : (c) 2011, Jeremie Dimino <jeremie@dimino.org>
* Licence : BSD3
*
* This file is a part of Lambda-Term.
*)
open Lwt
open LTerm_widget
let get_time () =
let localtime = Unix.localtime (Unix.time ()) in
Printf.sprintf "%02u:%02u:%02u"
localtime.Unix.tm_hour
localtime.Unix.tm_min
localtime.Unix.tm_sec
let main () =
let waiter, wakener = wait () in
let vbox = new vbox in
let clock = new label (get_time ()) in
let button = new button "exit退出" in
vbox#add clock;
vbox#add button;
(* Update the time every second. *)
ignore (Lwt_engine.on_timer 1.0 true (fun _ -> clock#set_text (get_time ())));
(* Quit when the exit button is clicked. *)
button#on_click (wakeup wakener);
(* Run in the standard terminal. *)
Lazy.force LTerm.stdout >>= fun term ->
LTerm.enable_mouse term >>= fun () ->
Lwt.finalize
(fun () -> run term vbox waiter)
(fun () -> LTerm.disable_mouse term)
let () = Lwt_main.run (main ())
|