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
17#include <map>
18#include <set>
19#include <string>
20
21#include "paths.hh"
22#include "sanity.hh"
23
24struct user_interface;
25
26struct ticker
27{
28 size_t ticks;
29 size_t mod;
30 size_t total;
31 size_t previous_total;
32 bool kilocount;
33 bool use_total;
34 std::string keyname;
35 std::string name; // translated name
36 std::string shortname;
37 size_t count_size;
38 ticker(std::string const & n, std::string const & s, size_t mod = 64,
39 bool kilocount=false);
40 void set_total(size_t tot) { use_total = true; total = tot; }
41 void set_count_size(size_t csiz) { count_size = csiz; }
42 void operator++();
43 void operator+=(size_t t);
44 ~ticker();
45};
46
47struct tick_writer
48{
49public:
50 tick_writer() {}
51 virtual ~tick_writer() {}
52 virtual void write_ticks() = 0;
53 virtual void clear_line() = 0;
54};
55
56struct tick_write_count : virtual public tick_writer
57{
58public:
59 tick_write_count();
60 ~tick_write_count();
61 void write_ticks();
62 void clear_line();
63private:
64 std::vector<size_t> last_tick_widths;
65 size_t last_tick_len;
66};
67
68struct tick_write_dot : virtual public tick_writer
69{
70public:
71 tick_write_dot();
72 ~tick_write_dot();
73 void write_ticks();
74 void clear_line();
75private:
76 std::map<std::string,size_t> last_ticks;
77 unsigned int chars_on_line;
78};
79
80struct tick_write_nothing : virtual public tick_writer
81{
82public:
83 void write_ticks() {}
84 void clear_line() {}
85};
86
87struct user_interface
88{
89public:
90 user_interface();
91 ~user_interface();
92 void initialize();
93 void deinitialize();
94 void warn(std::string const & warning);
95 void warn(format_base const & fmt) { warn(fmt.str()); }
96 void fatal(std::string const & fatal);
97 void fatal(format_base const & fmt) { fatal(fmt.str()); }
98 void inform(std::string const & line);
99 void inform(format_base const & fmt) { inform(fmt.str()); }
100 void fatal_exception(std::exception const & ex);
101 void fatal_exception();
102 void set_tick_trailer(std::string const & trailer);
103 void set_tick_writer(tick_writer * t_writer);
104 void ensure_clean_line();
105 void redirect_log_to(system_path const & filename);
106
107 std::string output_prefix();
108 std::string prog_name;
109
110private:
111 std::set<std::string> issued_warnings;
112
113 bool some_tick_is_dirty; // At least one tick needs being printed
114 bool last_write_was_a_tick;
115 std::map<std::string,ticker *> tickers;
116 tick_writer * t_writer;
117 void finish_ticking();
118 void write_ticks();
119 std::string tick_trailer;
120
121 friend struct tick_write_dot;
122 friend struct tick_write_count;
123 friend struct ticker;
124};
125
126extern struct user_interface ui;
127
128// like platform.hh's "terminal_width", but always returns a sensible value
129// (even if there is no terminal)
130unsigned int guess_terminal_width();
131
132// Local Variables:
133// mode: C++
134// fill-column: 76
135// c-file-style: "gnu"
136// indent-tabs-mode: nil
137// End:
138// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
139
140#endif // __UI_HH__

Archive Download this file

Branches

Tags

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