[Aptitude-svn-commit] r3372 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Tue, 07 Jun 2005 17:56:36 +0000
Author: dburrows
Date: Tue Jun 7 17:56:34 2005
New Revision: 3372
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
branches/aptitude-0.3/aptitude/src/vscreen/fragment.h
Log:
Change how text fragments are created so that they behave more intuitively:
don't store chstrings, and handle styles by wrapping a style_fragment around the text.
This way, text fragments obey the 'closest style takes precedence' rule.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Tue Jun 7 17:56:34 2005
@@ -1,5 +1,18 @@
2005-06-07 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/fragment.cc, src/vscreen/fragment.h:
+
+ When generating a text fragment from a string and a style,
+ actually wrap it in a style fragment. (maybe I should just
+ include a style in every text fragment, to increase locality?
+ Probably doesn't really matter, though, and a lot of text
+ fragments don't need styles) This makes it easy to generate styled
+ text that does the right thing (i.e., where the style overrides
+ any outer styles rather than vice versa).
+
+ Also stopped using chstrings for text_fragments: they are almost
+ guaranteed to do the wrong thing anyway.
+
* src/pkg_view.cc:
Adjust the remaining bits of pkg_view to handle styles properly:
Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc Tue Jun 7 17:56:34 2005
@@ -22,7 +22,7 @@
class _text_fragment:public fragment
{
public:
- _text_fragment(const chstring &_s):s(_s) {}
+ _text_fragment(const string &_s):s(_s) {}
fragment_contents layout(size_t firstw, size_t restw,
const style &st)
@@ -49,14 +49,15 @@
return false;
}
private:
- chstring s;
+ string s;
};
-fragment *text_fragment(const chstring &s) { return new _text_fragment(s); }
+fragment *text_fragment(const string &s) { return new _text_fragment(s); }
fragment *text_fragment(const string &s,
const style &style)
{
- return new _text_fragment(chstring(s, style));
+ return style_fragment(text_fragment(s),
+ style);
}
/** This fragment just expands to a newline. */
@@ -1033,14 +1034,14 @@
// Optimization: don't create lots of unnecessary text fragments
// when one will do.
- chstring curstr("");
+ string curstr("");
// Loop 3: execute the program
while(nextpercent!=NULL)
{
// First, make a fragment for everything until the percent:
- curstr+=chstring(string(start, nextpercent-start), st);
+ curstr+=string(start, nextpercent-start);
// This is almost always what we want; in the cases when it's not,
// I override it explicitly.
@@ -1050,30 +1051,39 @@
switch(*(nextpercent+1))
{
case '%':
- curstr+=chstring(string("%"), st);
+ curstr+="%";
break;
case 'B':
- st.attrs_flip(A_BOLD);
- break;
case 'b':
- st.attrs_flip(A_BOLD);
- break;
case 'R':
- st.attrs_flip(A_REVERSE);
- break;
case 'r':
- st.attrs_flip(A_REVERSE);
- break;
case 'D':
- st.attrs_flip(A_DIM);
- break;
case 'd':
- st.attrs_flip(A_DIM);
+ if(!curstr.empty())
+ {
+ rval.push_back(text_fragment(curstr, st));
+ curstr="";
+ }
+ switch(*(nextpercent+1))
+ {
+ case 'B':
+ case 'b':
+ st.attrs_flip(A_BOLD);
+ break;
+ case 'R':
+ case 'r':
+ st.attrs_flip(A_REVERSE);
+ break;
+ case 'D':
+ case 'd':
+ st.attrs_flip(A_DIM);
+ break;
+ }
break;
case 'n':
if(!curstr.empty())
{
- rval.push_back(text_fragment(curstr));
+ rval.push_back(text_fragment(curstr, st));
curstr="";
}
@@ -1085,7 +1095,7 @@
if(!curstr.empty())
{
- rval.push_back(text_fragment(curstr));
+ rval.push_back(text_fragment(curstr, st));
curstr="";
}
rval.push_back(arguments[argcount].F);
@@ -1095,12 +1105,18 @@
// should have been verified above.
assert(arguments[argcount].format=='s');
- curstr+=chstring(arguments[argcount].s, st);
+ curstr+=arguments[argcount].s;
++argcount;
break;
case 'S':
assert(arguments[argcount].format=='S');
+ if(!curstr.empty())
+ {
+ rval.push_back(text_fragment(curstr, st));
+ curstr="";
+ }
+
st+=get_style(arguments[argcount].s);
++argcount;
break;
@@ -1126,16 +1142,22 @@
case 'F':
if(!curstr.empty())
{
- rval.push_back(text_fragment(curstr));
+ rval.push_back(text_fragment(curstr, st));
curstr="";
}
rval.push_back(arguments[pos].F);
break;
case 's':
- curstr+=chstring(arguments[pos].s, st);
+ curstr+=arguments[pos].s;
break;
case 'S':
+ if(!curstr.empty())
+ {
+ rval.push_back(text_fragment(curstr, st));
+ curstr="";
+ }
+
st+=get_style(arguments[pos].s);
break;
}
@@ -1150,10 +1172,10 @@
// Get any trailing bit o' string:
if(*start!=0)
- curstr+=chstring(start, st);
+ curstr+=start;
if(!curstr.empty())
- rval.push_back(text_fragment(curstr));
+ rval.push_back(text_fragment(curstr, st));
return sequence_fragment(rval);
}
Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.h Tue Jun 7 17:56:34 2005
@@ -81,18 +81,19 @@
*
* \return the new fragment
*/
-fragment *text_fragment(const chstring &s);
+fragment *text_fragment(const std::string &s);
/** Create a fragment from a string of text. The text will simply be
* formatted as a single line without clipping.
*
* \param s the text to use
- * \param style the new fragment's style
+ * \param style the base style for the new fragment; an implicit
+ * style_fragment for this style is wrapped around the new text_fragment.
*
* \return the new fragment
*/
fragment *text_fragment(const std::string &s,
- const style &st=style());
+ const style &st);
/** Create a fragment from a string of text. The text will simply be
* formatted as a single line without clipping.