monotone

monotone Mtn Source Tree

Root/src/ui.hh

1// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef __UI_HH__
11#define __UI_HH__
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
17#include "vector.hh"
18
19struct i18n_format;
20class system_path;
21struct usage;
22struct options;
23
24struct ticker
25{
26 size_t ticks;
27 size_t mod;
28 size_t total;
29 size_t previous_total;
30 bool kilocount;
31 bool use_total;
32 bool may_skip_display;
33 std::string keyname;
34 std::string name; // translated name
35 std::string shortname;
36 size_t count_size;
37 ticker(std::string const & n, std::string const & s, size_t mod = 64,
38 bool kilocount=false, bool skip_display=false);
39 void set_total(size_t tot) { use_total = true; total = tot; }
40 void set_count_size(size_t csiz) { count_size = csiz; }
41 void operator++();
42 void operator+=(size_t t);
43 ~ticker();
44};
45
46struct tick_writer;
47struct tick_write_count;
48struct tick_write_dot;
49struct tick_write_stdio;
50
51struct user_interface
52{
53public:
54 void initialize();
55 void deinitialize();
56 void warn(std::string const & warning);
57 void warn(format_base const & fmt) { warn(fmt.str()); }
58 void fatal(std::string const & fatal);
59 void fatal(format_base const & fmt) { fatal(fmt.str()); }
60 void fatal_db(std::string const & fatal);
61 void fatal_db(format_base const & fmt) { fatal_db(fmt.str()); }
62 void inform(std::string const & line);
63 void inform(format_base const & fmt) { inform(fmt.str()); }
64 void inform_usage(usage const & u, options & opts);
65 int fatal_exception(std::exception const & ex);
66 int fatal_exception();
67 void set_tick_trailer(std::string const & trailer);
68
69 enum ticker_type { count=1, dot, stdio, none };
70 void set_tick_write_dot();
71 void set_tick_write_count();
72 void set_tick_write_stdio();
73 void set_tick_write_nothing();
74 ticker_type set_ticker_type(ticker_type type);
75 ticker_type get_ticker_type() const;
76
77 void ensure_clean_line();
78 void redirect_log_to(system_path const & filename);
79 bool enable_timestamps(bool enable);
80
81 std::string output_prefix();
82
83private:
84 void finish_ticking();
85 void write_ticks();
86
87 struct impl;
88 impl * imp;
89 bool timestamps_enabled;
90 ticker_type tick_type;
91
92 friend struct ticker;
93 friend struct tick_write_count;
94 friend struct tick_write_dot;
95 friend struct tick_write_stdio;
96};
97
98extern struct user_interface ui;
99
100// Wrapper class which ensures proper setup and teardown of the global ui
101// object. (We do not want to use global con/destructors for this, as they
102// execute outside the protection of main.cc's signal handlers.)
103struct ui_library
104{
105 ui_library() { ui.initialize(); }
106 ~ui_library() { ui.deinitialize(); }
107};
108
109// like platform.hh's "terminal_width", but always returns a sensible value
110// (even if there is no terminal)
111unsigned int guess_terminal_width();
112
113std::string format_text(std::string const & text,
114 size_t const col = 0, size_t curcol = 0,
115 bool indent_first_line = false);
116std::string format_text(i18n_format const & text,
117 size_t const col = 0, size_t curcol = 0,
118 bool indent_first_line = false);
119
120#endif // __UI_HH__
121
122// Local Variables:
123// mode: C++
124// fill-column: 76
125// c-file-style: "gnu"
126// indent-tabs-mode: nil
127// End:
128// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

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