mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-15 22:52:31 +00:00
* Renamed pex_{enabled,active} to is_pex_*.
* Changed the download info screen to only use commands. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@972 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -52,6 +52,15 @@
|
||||
|
||||
namespace display { namespace helpers {
|
||||
|
||||
// All we're ever going to need:
|
||||
|
||||
inline TextElementCommand*
|
||||
te_command(const char* command, int flags = TextElementCommand::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return new TextElementCommand(command, flags, attributes, TextElementCommand::extent_full);
|
||||
}
|
||||
|
||||
// End All we're ever going to need.
|
||||
|
||||
typedef TextElementStringBase string_base;
|
||||
typedef TextElementValueBase value_base;
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include <rak/string_manip.h>
|
||||
|
||||
#include "rpc/parse_commands.h"
|
||||
#include "text_element_string.h"
|
||||
|
||||
namespace display {
|
||||
@@ -89,33 +90,47 @@ TextElementCString::copy_string(char* first, char* last, rpc::target_type target
|
||||
return first + length;
|
||||
}
|
||||
|
||||
// char*
|
||||
// TextElementCommand::print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
// Attributes baseAttribute = attributes->back();
|
||||
// push_attribute(attributes, Attributes(first, m_attributes, Attributes::color_invalid));
|
||||
char*
|
||||
TextElementCommand::print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
Attributes baseAttribute = attributes->back();
|
||||
push_attribute(attributes, Attributes(first, m_attributes, Attributes::color_invalid));
|
||||
|
||||
// if (first == last)
|
||||
// return first;
|
||||
torrent::Object result = rpc::parse_command(target, m_command, m_commandEnd).first;
|
||||
|
||||
// if (m_flags & flag_escape_hex) {
|
||||
// char buffer[last - first];
|
||||
// char* bufferLast = copy_string(buffer, buffer + (last - first), target);
|
||||
if (first == last)
|
||||
return first;
|
||||
|
||||
// first = rak::transform_hex(buffer, bufferLast, first, last);
|
||||
switch (result.type()) {
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
const std::string& str = result.as_string();
|
||||
|
||||
// } else if (m_flags & flag_escape_html) {
|
||||
// char buffer[last - first];
|
||||
// char* bufferLast = copy_string(buffer, buffer + (last - first), target);
|
||||
if (m_flags & flag_escape_hex) {
|
||||
first = rak::transform_hex(str.c_str(), str.c_str() + str.size(), first, last);
|
||||
|
||||
// first = rak::copy_escape_html(buffer, bufferLast, first, last);
|
||||
} else if (m_flags & flag_escape_html) {
|
||||
first = rak::copy_escape_html(str.c_str(), str.c_str() + str.size(), first, last);
|
||||
|
||||
// } else {
|
||||
// first = copy_string(first, last, target);
|
||||
// }
|
||||
} else {
|
||||
size_t length = std::min<size_t>(str.size(), std::distance(first, last));
|
||||
|
||||
// push_attribute(attributes, Attributes(first, baseAttribute));
|
||||
std::memcpy(first, str.c_str(), length);
|
||||
first += std::min<size_t>(str.size(), length);
|
||||
}
|
||||
|
||||
// return first;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
{
|
||||
first += std::max(snprintf(first, last - first + 1, "%lld", result.as_value()), 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return first;
|
||||
}
|
||||
|
||||
push_attribute(attributes, Attributes(first, baseAttribute));
|
||||
return first;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -167,7 +167,12 @@ public:
|
||||
|
||||
static const int flag_fixed_width = (1 << 8);
|
||||
|
||||
TextElementCommand(const char* command) : m_command(command) {}
|
||||
TextElementCommand(const char* command, int flags, int attributes, extent_type length) :
|
||||
m_flags(flags),
|
||||
m_attributes(attributes),
|
||||
m_length(length),
|
||||
m_command(command),
|
||||
m_commandEnd(command + std::strlen(command)) {}
|
||||
|
||||
int flags() const { return m_flags; }
|
||||
void set_flags(int flags) { m_flags = flags; }
|
||||
@@ -177,15 +182,17 @@ public:
|
||||
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target);
|
||||
|
||||
virtual extent_type max_length() { return m_length; }
|
||||
|
||||
protected:
|
||||
int m_flags;
|
||||
int m_attributes;
|
||||
extent_type m_length;
|
||||
|
||||
const char* m_command;
|
||||
const char* m_commandEnd;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user