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 "sanity.hh"
22
23struct user_interface;
24
25struct ticker
26{
27 size_t ticks;
28 size_t mod;
29 size_t total;
30 size_t previous_total;
31 bool kilocount;
32 bool use_total;
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);
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
47{
48public:
49 tick_writer() {}
50 virtual ~tick_writer() {}
51 virtual void write_ticks() = 0;
52 virtual void clear_line() = 0;
53};
54
55struct tick_write_count : virtual public tick_writer
56{
57public:
58 tick_write_count();
59 ~tick_write_count();
60 void write_ticks();
61 void clear_line();
62private:
63 std::vector<size_t> last_tick_widths;
64 size_t last_tick_len;
65};
66
67struct tick_write_dot : virtual public tick_writer
68{
69public:
70 tick_write_dot();
71 ~tick_write_dot();
72 void write_ticks();
73 void clear_line();
74private:
75 std::map<std::string,size_t> last_ticks;
76 unsigned int chars_on_line;
77};
78
79struct tick_write_nothing : virtual public tick_writer
80{
81public:
82 void write_ticks() {}
83 void clear_line() {}
84};
85
86struct user_interface
87{
88public:
89 user_interface();
90 ~user_interface();
91 void warn(std::string const & warning);
92 void warn(format_base const & fmt) { warn(fmt.str()); }
93 void fatal(std::string const & warning);
94 void fatal(format_base const & fmt) { warn(fmt.str()); }
95 void inform(std::string const & line);
96 void inform(format_base const & fmt) { inform(fmt.str()); }
97 void set_tick_trailer(std::string const & trailer);
98 void set_tick_writer(tick_writer * t_writer);
99 void ensure_clean_line();
100 void redirect_log_to(system_path const & filename);
101
102 void set_prog_name(std::string const & name);
103 std::string output_prefix();
104
105private:
106 std::set<std::string> issued_warnings;
107
108 bool some_tick_is_dirty; // At least one tick needs being printed
109 bool last_write_was_a_tick;
110 std::map<std::string,ticker *> tickers;
111 tick_writer * t_writer;
112 void finish_ticking();
113 void write_ticks();
114 std::string tick_trailer;
115
116 std::string prog_name;
117
118 friend struct tick_write_dot;
119 friend struct tick_write_count;
120 friend struct ticker;
121};
122
123extern struct user_interface ui;
124
125// like platform.hh's "terminal_width", but always returns a sensible value
126// (even if there is no terminal)
127unsigned int guess_terminal_width();
128
129// returns the a default user locale value
130const std::locale & get_user_locale();
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