improve formatting removal

This commit is contained in:
Andrzej Rybczak
2009-04-19 22:19:52 +02:00
parent 88fa887776
commit c7251ebb98
5 changed files with 54 additions and 20 deletions

View File

@@ -1631,8 +1631,7 @@ int main(int argc, char *argv[])
ShowMessage("Searching...");
Screen<Scrollpad> *s = static_cast<Screen<Scrollpad> *>(myScreen);
s->Main()->RemoveFormatting(fmtReverse);
s->Main()->RemoveFormatting(fmtReverseEnd);
s->Main()->RemoveFormatting();
ShowMessage("%s", s->Main()->SetFormatting(fmtReverse, findme, fmtReverseEnd) || findme.empty() ? "Done!" : "No matching patterns found");
s->Main()->Flush();
}

View File

@@ -32,6 +32,9 @@ Scrollpad::Scrollpad(size_t startx,
Border border)
: Window(startx, starty, width, height, title, color, border),
itsBeginning(0),
itsFoundForEach(0),
itsFoundValueBegin(0),
itsFoundValueEnd(0),
itsRealHeight(1)
{
}
@@ -102,7 +105,27 @@ void Scrollpad::Flush()
bool Scrollpad::SetFormatting(short vb, const std::basic_string<my_char_t> &s, short ve, bool for_each)
{
return itsBuffer.SetFormatting(vb, s, ve, for_each);
bool result = itsBuffer.SetFormatting(vb, s, ve, for_each);
if (result)
{
itsFoundForEach = for_each;
itsFoundValueBegin = vb;
itsFoundValueEnd = ve;
itsFoundPattern = s;
}
else
{
itsFoundForEach = 0;
itsFoundValueBegin = 0;
itsFoundValueEnd = 0;
itsFoundPattern.clear();
}
return result;
}
void Scrollpad::RemoveFormatting()
{
itsBuffer.RemoveFormatting(itsFoundValueBegin, itsFoundPattern, itsFoundValueEnd, itsFoundForEach);
}
void Scrollpad::Recreate()

View File

@@ -35,7 +35,7 @@ namespace NCurses
void Flush();
bool SetFormatting(short, const std::basic_string<my_char_t> &, short, bool for_each = 1);
void RemoveFormatting(short value) { itsBuffer.RemoveFormatting(value); }
void RemoveFormatting();
std::basic_string<my_char_t> Content() { return itsBuffer.Str(); }
virtual void Refresh();
@@ -67,6 +67,11 @@ namespace NCurses
int itsBeginning;
bool itsFoundForEach;
short itsFoundValueBegin;
short itsFoundValueEnd;
std::basic_string<my_char_t> itsFoundPattern;
size_t itsRealHeight;
};
}

View File

@@ -472,9 +472,8 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
}
if (changed.StatusFlags && Config.header_visibility)
{
static string switch_state;
string switch_state;
switch_state.clear();
if (mpd_repeat)
switch_state += mpd_repeat;
if (mpd_random)

View File

@@ -40,18 +40,10 @@ namespace NCurses
return Position < f.Position;
}
struct hasValue
bool operator==(const FormatPos &f)
{
hasValue(short value) : itsValue(value) { }
bool operator()(const FormatPos &fp)
{
return fp.Value == itsValue;
}
private:
short itsValue;
};
return Position == f.Position && Value == f.Value;
}
};
std::basic_ostringstream<C> itsString;
@@ -64,7 +56,7 @@ namespace NCurses
std::basic_string<C> Str() const;
bool SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each = 1);
void RemoveFormatting(short value);
void RemoveFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each = 1);
void SetTemp(std::basic_string<C> *);
void Clear();
@@ -122,9 +114,25 @@ template <typename C> bool NCurses::basic_buffer<C>::SetFormatting(short vb, con
return result;
}
template <typename C> void NCurses::basic_buffer<C>::RemoveFormatting(short value)
template <typename C> void NCurses::basic_buffer<C>::RemoveFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each)
{
itsFormat.remove_if(typename FormatPos::hasValue(value));
if (s.empty())
return;
std::basic_string<C> base = itsString.str();
FormatPos fp;
for (size_t i = base.find(s); i != std::basic_string<C>::npos; i = base.find(s, i))
{
fp.Value = vb;
fp.Position = i;
itsFormat.remove(fp);
i += s.length();
fp.Value = ve;
fp.Position = i;
itsFormat.remove(fp);
if (!for_each)
break;
}
}
template <typename C> void NCurses::basic_buffer<C>::SetTemp(std::basic_string<C> *tmp)