monotone

monotone Mtn Source Tree

Root/ui.hh

1#ifndef __UI_HH__
2#define __UI_HH__
3
4// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13// this file contains a couple utilities to deal with the user
14// interface. the global user_interface object 'ui' owns cerr, so
15// no writing to it directly!
16
17struct i18n_format;
18class system_path;
19
20struct ticker
21{
22 size_t ticks;
23 size_t mod;
24 size_t total;
25 size_t previous_total;
26 bool kilocount;
27 bool use_total;
28 std::string keyname;
29 std::string name; // translated name
30 std::string shortname;
31 size_t count_size;
32 ticker(std::string const & n, std::string const & s, size_t mod = 64,
33 bool kilocount=false);
34 void set_total(size_t tot) { use_total = true; total = tot; }
35 void set_count_size(size_t csiz) { count_size = csiz; }
36 void operator++();
37 void operator+=(size_t t);
38 ~ticker();
39};
40
41struct tick_writer;
42struct tick_write_count;
43struct tick_write_dot;
44
45struct user_interface
46{
47public:
48 user_interface();
49 ~user_interface();
50 void initialize();
51 void deinitialize();
52 void warn(std::string const & warning);
53 void warn(format_base const & fmt) { warn(fmt.str()); }
54 void fatal(std::string const & fatal);
55 void fatal(format_base const & fmt) { fatal(fmt.str()); }
56 void inform(std::string const & line);
57 void inform(format_base const & fmt) { inform(fmt.str()); }
58 void fatal_exception(std::exception const & ex);
59 void fatal_exception();
60 void set_tick_trailer(std::string const & trailer);
61 void set_tick_write_dot();
62 void set_tick_write_count();
63 void set_tick_write_nothing();
64 void ensure_clean_line();
65 void redirect_log_to(system_path const & filename);
66
67 std::string output_prefix();
68 std::string prog_name;
69
70private:
71 void finish_ticking();
72 void write_ticks();
73
74 struct impl;
75 impl * imp;
76
77 friend struct ticker;
78 friend struct tick_write_count;
79 friend struct tick_write_dot;
80};
81
82extern struct user_interface ui;
83
84// like platform.hh's "terminal_width", but always returns a sensible value
85// (even if there is no terminal)
86unsigned int guess_terminal_width();
87
88std::string format_text(std::string const & text,
89 size_t const col = 0, size_t curcol = 0);
90std::string format_text(i18n_format const & text,
91 size_t const col = 0, size_t curcol = 0);
92
93// Local Variables:
94// mode: C++
95// fill-column: 76
96// c-file-style: "gnu"
97// indent-tabs-mode: nil
98// End:
99// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
100
101#endif // __UI_HH__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status