monotone

monotone Mtn Source Tree

Root/ui.hh

1#ifndef __UI_HH__
2#define __UI_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9// this file contains a couple utilities to deal with the user
10// interface. the global user_interface object 'ui' owns cerr, so
11// no writing to it directly!
12
13#include <map>
14#include <set>
15#include <string>
16#include <boost/format.hpp>
17
18struct user_interface;
19
20struct ticker
21{
22 size_t ticks;
23 size_t mod;
24 bool kilocount;
25 std::string name;
26 std::string shortname;
27 ticker(std::string const & n, std::string const & s, size_t mod = 64,
28 bool kilocount=false);
29 void operator++();
30 void operator+=(size_t t);
31 ~ticker();
32};
33
34struct tick_writer
35{
36public:
37 tick_writer() {}
38 virtual ~tick_writer() {}
39 virtual void write_ticks() = 0;
40 virtual void clear_line() = 0;
41};
42
43struct tick_write_count : virtual public tick_writer
44{
45public:
46 tick_write_count();
47 ~tick_write_count();
48 void write_ticks();
49 void clear_line();
50private:
51 size_t last_tick_len;
52};
53
54struct tick_write_dot : virtual public tick_writer
55{
56public:
57 tick_write_dot();
58 ~tick_write_dot();
59 void write_ticks();
60 void clear_line();
61private:
62 std::map<std::string,size_t> last_ticks;
63};
64
65struct tick_write_nothing : virtual public tick_writer
66{
67public:
68 void write_ticks() {}
69 void clear_line() {}
70};
71
72struct user_interface
73{
74public:
75 user_interface();
76 ~user_interface();
77 void warn(std::string const & warning);
78 void warn(boost::format const & fmt) { warn(fmt.str()); }
79 void fatal(std::string const & warning);
80 void fatal(boost::format const & fmt) { warn(fmt.str()); }
81 void inform(std::string const & line);
82 void inform(boost::format const & fmt) { inform(fmt.str()); }
83 void set_tick_trailer(std::string const & trailer);
84 void set_tick_writer(tick_writer * t_writer);
85 void ensure_clean_line();
86
87private:
88 std::set<std::string> issued_warnings;
89
90 bool some_tick_is_dirty; // At least one tick needs being printed
91 bool last_write_was_a_tick;
92 std::map<std::string,ticker *> tickers;
93 tick_writer * t_writer;
94 void finish_ticking();
95 void write_ticks();
96 std::string tick_trailer;
97
98 friend struct tick_write_dot;
99 friend struct tick_write_count;
100 friend struct ticker;
101};
102
103extern struct user_interface ui;
104
105
106#endif // __UI_HH__

Archive Download this file

Branches

Tags

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