enable disk cache pool allocator by default. fix ansi escape code conversion in client_test on windows
This commit is contained in:
parent
07ecf7c1bd
commit
ac2916c426
|
@ -108,14 +108,21 @@ std::string const& progress_bar(int progress, int width, color_code c
|
||||||
|
|
||||||
caption.resize(size_t(width), ' ');
|
caption.resize(size_t(width), ' ');
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
char const* background = "40";
|
||||||
|
#else
|
||||||
|
char const* background = "48;5;238";
|
||||||
|
#endif
|
||||||
|
|
||||||
char str[256];
|
char str[256];
|
||||||
if (flags & progress_invert)
|
if (flags & progress_invert)
|
||||||
snprintf(str, sizeof(str), "\x1b[48;5;238m\x1b[37m%s\x1b[4%d;3%dm%s\x1b[49;39m"
|
snprintf(str, sizeof(str), "\x1b[%sm\x1b[37m%s\x1b[4%d;3%dm%s\x1b[49;39m"
|
||||||
, caption.substr(0, progress_chars).c_str(), c, tc
|
, background, caption.substr(0, progress_chars).c_str(), c, tc
|
||||||
, caption.substr(progress_chars).c_str());
|
, caption.substr(progress_chars).c_str());
|
||||||
else
|
else
|
||||||
snprintf(str, sizeof(str), "\x1b[4%d;3%dm%s\x1b[48;5;238m\x1b[37m%s\x1b[49;39m"
|
snprintf(str, sizeof(str), "\x1b[4%d;3%dm%s\x1b[%sm\x1b[37m%s\x1b[49;39m"
|
||||||
, c, tc, caption.substr(0, progress_chars).c_str(), caption.substr(progress_chars).c_str());
|
, c, tc, caption.substr(0, progress_chars).c_str(), background
|
||||||
|
, caption.substr(progress_chars).c_str());
|
||||||
bar = str;
|
bar = str;
|
||||||
}
|
}
|
||||||
return bar;
|
return bar;
|
||||||
|
@ -208,7 +215,7 @@ void terminal_size(int* terminal_width, int* terminal_height)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
void apply_ansi_code(int* attributes, bool* reverse, int code)
|
void apply_ansi_code(int* attributes, bool* reverse, bool* support_chaining, int code)
|
||||||
{
|
{
|
||||||
static const int color_table[8] =
|
static const int color_table[8] =
|
||||||
{
|
{
|
||||||
|
@ -224,8 +231,8 @@ void apply_ansi_code(int* attributes, bool* reverse, int code)
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
foreground_mask = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
|
foreground_mask = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
|
||||||
background_mask = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
|
background_mask = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int fg_mask[2] = {foreground_mask, background_mask};
|
static const int fg_mask[2] = {foreground_mask, background_mask};
|
||||||
|
@ -233,14 +240,29 @@ void apply_ansi_code(int* attributes, bool* reverse, int code)
|
||||||
static const int fg_shift[2] = { 0, 4};
|
static const int fg_shift[2] = { 0, 4};
|
||||||
static const int bg_shift[2] = { 4, 0};
|
static const int bg_shift[2] = { 4, 0};
|
||||||
|
|
||||||
|
// default foreground
|
||||||
|
if (code == 39) code = 37;
|
||||||
|
|
||||||
|
// default background
|
||||||
|
if (code == 49) code = 40;
|
||||||
|
|
||||||
if (code == 0)
|
if (code == 0)
|
||||||
{
|
{
|
||||||
// reset
|
// reset
|
||||||
*attributes = color_table[7];
|
*attributes = color_table[7];
|
||||||
*reverse = false;
|
*reverse = false;
|
||||||
|
*support_chaining = true;
|
||||||
|
}
|
||||||
|
else if (code == 1)
|
||||||
|
{
|
||||||
|
// intensity
|
||||||
|
*attributes |= *reverse ? BACKGROUND_INTENSITY : FOREGROUND_INTENSITY;
|
||||||
|
*support_chaining = true;
|
||||||
}
|
}
|
||||||
else if (code == 7)
|
else if (code == 7)
|
||||||
{
|
{
|
||||||
|
// reverse video
|
||||||
|
*support_chaining = true;
|
||||||
if (*reverse) return;
|
if (*reverse) return;
|
||||||
*reverse = true;
|
*reverse = true;
|
||||||
int fg_col = *attributes & foreground_mask;
|
int fg_col = *attributes & foreground_mask;
|
||||||
|
@ -254,12 +276,14 @@ void apply_ansi_code(int* attributes, bool* reverse, int code)
|
||||||
// foreground color
|
// foreground color
|
||||||
*attributes &= ~fg_mask[*reverse];
|
*attributes &= ~fg_mask[*reverse];
|
||||||
*attributes |= color_table[code - 30] << fg_shift[*reverse];
|
*attributes |= color_table[code - 30] << fg_shift[*reverse];
|
||||||
|
*support_chaining = true;
|
||||||
}
|
}
|
||||||
else if (code >= 40 && code <= 47)
|
else if (code >= 40 && code <= 47)
|
||||||
{
|
{
|
||||||
// foreground color
|
// background color
|
||||||
*attributes &= ~bg_mask[*reverse];
|
*attributes &= ~bg_mask[*reverse];
|
||||||
*attributes |= color_table[code - 40] << bg_shift[*reverse];
|
*attributes |= color_table[code - 40] << bg_shift[*reverse];
|
||||||
|
*support_chaining = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -288,14 +312,15 @@ void print(char const* buf)
|
||||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||||
if (GetConsoleScreenBufferInfo(out, &sbi))
|
if (GetConsoleScreenBufferInfo(out, &sbi))
|
||||||
{
|
{
|
||||||
COORD pos = sbi.dwCursorPosition;
|
COORD const pos = sbi.dwCursorPosition;
|
||||||
int width = sbi.dwSize.X;
|
int const width = sbi.dwSize.X;
|
||||||
int run = width - pos.X;
|
int const run = width - pos.X;
|
||||||
DWORD n;
|
DWORD n;
|
||||||
FillConsoleOutputAttribute(out, 0x7, run, pos, &n);
|
FillConsoleOutputAttribute(out, 0x7, run, pos, &n);
|
||||||
FillConsoleOutputCharacter(out, ' ', run, pos, &n);
|
FillConsoleOutputCharacter(out, ' ', run, pos, &n);
|
||||||
}
|
}
|
||||||
++buf;
|
++buf;
|
||||||
|
start = buf;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (*start == 'J')
|
else if (*start == 'J')
|
||||||
|
@ -312,19 +337,31 @@ void print(char const* buf)
|
||||||
FillConsoleOutputCharacter(out, ' ', run, pos, &n);
|
FillConsoleOutputCharacter(out, ' ', run, pos, &n);
|
||||||
}
|
}
|
||||||
++buf;
|
++buf;
|
||||||
|
start = buf;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
one_more:
|
one_more:
|
||||||
while (*buf != 'm' && *buf != ';' && *buf != 0) ++buf;
|
while (*buf != 'm' && *buf != ';' && *buf != 0) ++buf;
|
||||||
|
|
||||||
|
// this is where we handle reset, color and reverse codes
|
||||||
if (*buf == 0) break;
|
if (*buf == 0) break;
|
||||||
int code = atoi(start);
|
int code = atoi(start);
|
||||||
apply_ansi_code(¤t_attributes, &reverse, code);
|
bool support_chaining = false;
|
||||||
|
apply_ansi_code(¤t_attributes, &reverse, &support_chaining, code);
|
||||||
|
if (support_chaining)
|
||||||
|
{
|
||||||
if (*buf == ';')
|
if (*buf == ';')
|
||||||
{
|
{
|
||||||
++buf;
|
++buf;
|
||||||
start = buf;
|
start = buf;
|
||||||
goto one_more;
|
goto one_more;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ignore codes with multiple fields for now
|
||||||
|
while (*buf != 'm' && *buf != 0) ++buf;
|
||||||
|
}
|
||||||
SetConsoleTextAttribute(out, current_attributes);
|
SetConsoleTextAttribute(out, current_attributes);
|
||||||
++buf; // skip 'm'
|
++buf; // skip 'm'
|
||||||
start = buf;
|
start = buf;
|
||||||
|
|
|
@ -96,7 +96,11 @@ void session_view::render()
|
||||||
snprintf(str, sizeof(str), "%s%swaste: %s up: %s (%s) "
|
snprintf(str, sizeof(str), "%s%swaste: %s up: %s (%s) "
|
||||||
"disk queue: %s | %s cache w: %3d%% r: %3d%% "
|
"disk queue: %s | %s cache w: %3d%% r: %3d%% "
|
||||||
"size: w: %s r: %s total: %s %s\x1b[K"
|
"size: w: %s r: %s total: %s %s\x1b[K"
|
||||||
|
#ifdef _WIN32
|
||||||
|
, esc("40")
|
||||||
|
#else
|
||||||
, esc("48;5;238")
|
, esc("48;5;238")
|
||||||
|
#endif
|
||||||
, esc("1")
|
, esc("1")
|
||||||
, add_suffix(m_cnt[0][m_wasted_bytes_idx]).c_str()
|
, add_suffix(m_cnt[0][m_wasted_bytes_idx]).c_str()
|
||||||
, color(add_suffix(upload_rate, "/s"), col_red).c_str()
|
, color(add_suffix(upload_rate, "/s"), col_red).c_str()
|
||||||
|
|
|
@ -200,7 +200,7 @@ namespace libtorrent
|
||||||
SET(support_merkle_torrents, true, 0),
|
SET(support_merkle_torrents, true, 0),
|
||||||
SET(report_redundant_bytes, true, 0),
|
SET(report_redundant_bytes, true, 0),
|
||||||
SET_NOPREV(listen_system_port_fallback, true, 0),
|
SET_NOPREV(listen_system_port_fallback, true, 0),
|
||||||
SET(use_disk_cache_pool, false, 0),
|
SET(use_disk_cache_pool, true, 0),
|
||||||
SET_NOPREV(announce_crypto_support, true, 0),
|
SET_NOPREV(announce_crypto_support, true, 0),
|
||||||
SET_NOPREV(enable_upnp, true, &session_impl::update_upnp),
|
SET_NOPREV(enable_upnp, true, &session_impl::update_upnp),
|
||||||
SET_NOPREV(enable_natpmp, true, &session_impl::update_natpmp),
|
SET_NOPREV(enable_natpmp, true, &session_impl::update_natpmp),
|
||||||
|
|
Loading…
Reference in New Issue