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 void operator--();
32 ~ticker();
33};
34
35struct tick_writer
36{
37public:
38 tick_writer() {}
39 virtual ~tick_writer() {}
40 virtual void write_ticks() = 0;
41 virtual void clear_line() = 0;
42};
43
44struct tick_write_count : virtual public tick_writer
45{
46public:
47 tick_write_count();
48 ~tick_write_count();
49 void write_ticks();
50 void clear_line();
51private:
52 size_t last_tick_len;
53};
54
55struct tick_write_dot : virtual public tick_writer
56{
57public:
58 tick_write_dot();
59 ~tick_write_dot();
60 void write_ticks();
61 void clear_line();
62private:
63 std::map<std::string,size_t> last_ticks;
64 unsigned int chars_on_line;
65};
66
67struct tick_write_nothing : virtual public tick_writer
68{
69public:
70 void write_ticks() {}
71 void clear_line() {}
72};
73
74struct user_interface
75{
76public:
77 user_interface();
78 ~user_interface();
79 void warn(std::string const & warning);
80 void warn(boost::format const & fmt) { warn(fmt.str()); }
81 void fatal(std::string const & warning);
82 void fatal(boost::format const & fmt) { warn(fmt.str()); }
83 void inform(std::string const & line);
84 void inform(boost::format const & fmt) { inform(fmt.str()); }
85 void set_tick_trailer(std::string const & trailer);
86 void set_tick_writer(tick_writer * t_writer);
87 void ensure_clean_line();
88
89private:
90 std::set<std::string> issued_warnings;
91
92 bool some_tick_is_dirty; // At least one tick needs being printed
93 bool last_write_was_a_tick;
94 std::map<std::string,ticker *> tickers;
95 tick_writer * t_writer;
96 void finish_ticking();
97 void write_ticks();
98 std::string tick_trailer;
99
100 friend struct tick_write_dot;
101 friend struct tick_write_count;
102 friend struct ticker;
103};
104
105extern struct user_interface ui;
106
107// like platform.hh's "terminal_width", but always returns a sensible value
108// (even if there is no terminal)
109unsigned int guess_terminal_width();
110
111// returns the a default user locale value
112const std::locale & get_user_locale();
113
114#endif // __UI_HH__

Archive Download this file

Branches

Tags

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