libvirt: Handle VIR_DOMAIN_PMSUSPENDED state.
[virt-top.git] / src / screen.ml
1 (* 'top'-like tool for libvirt domains.
2    (C) Copyright 2007-2017 Richard W.M. Jones, Red Hat Inc.
3    http://libvirt.org/
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *)
19
20 (* The virt-top screen layout. *)
21
22 open Curses
23
24 module D = Libvirt.Domain
25
26 (* Line numbers. *)
27 let top_lineno = 0
28 let summary_lineno = 1 (* this takes 2 lines *)
29 let message_lineno = 3
30 let header_lineno = 4
31 let domains_lineno = 5
32
33 (* Easier to use versions of curses functions addstr, mvaddstr, etc. *)
34 let move y x = ignore (move y x)
35 let refresh () = ignore (refresh ())
36 let addch c = ignore (addch (int_of_char c))
37 let addstr s = ignore (addstr s)
38 let mvaddstr y x s = ignore (mvaddstr y x s)
39
40 (* Print in the "message area". *)
41 let clear_msg () = move message_lineno 0; clrtoeol ()
42 let print_msg str = clear_msg (); mvaddstr message_lineno 0 str
43
44 (* Show a libvirt domain state (the 'S' column). *)
45 let show_state = function
46   | D.InfoNoState -> '?'
47   | D.InfoRunning -> 'R'
48   | D.InfoBlocked -> 'S'
49   | D.InfoPaused -> 'P'
50   | D.InfoShutdown -> 'D'
51   | D.InfoShutoff -> 'O'
52   | D.InfoCrashed -> 'X'
53   | D.InfoPMSuspended -> 'M'