[view] stop scrolling to the right when the end is reached

Fixes #84
pull/254/head
Timothy Stack 9 years ago
parent 1ad3966a95
commit b4cb092ce1

@ -44,6 +44,17 @@ public:
~db_label_source() { };
size_t hist_label_width() {
size_t retval = 0;
for (std::vector<size_t>::iterator iter = this->dls_column_sizes.begin();
iter != this->dls_column_sizes.end();
++iter) {
retval += *iter;
}
return retval;
};
void hist_label_for_group(int group, std::string &label_out)
{
label_out.clear();

@ -77,6 +77,10 @@ public:
public:
virtual ~label_source() { };
virtual size_t hist_label_width() {
return INT_MAX;
};
virtual void hist_label_for_group(int group,
std::string &label_out) { };
@ -132,6 +136,11 @@ public:
return (this->buckets_per_group() + 1) * this->hs_groups.size();
};
size_t text_line_width() {
return this->hs_label_source == NULL ? 0 :
this->hs_label_source->hist_label_width();
};
void set_role_for_type(bucket_type_t bt, view_colors::role_t role)
{
this->hs_type2role[bt] = role;

@ -56,6 +56,10 @@ public:
/** @return The number of rows in the list. */
virtual size_t listview_rows(const listview_curses &lv) = 0;
virtual size_t listview_width(const listview_curses &lv) {
return INT_MAX;
};
/**
* Get the string value for a row in the list.
*
@ -343,7 +347,10 @@ public:
*/
void set_left(unsigned int left)
{
if (this->lv_left != left) {
if (left > this->get_inner_width()) {
alerter::singleton().chime();
}
else if (this->lv_left != left) {
this->lv_left = left;
this->lv_scroll.invoke(this);
this->lv_needs_update = true;
@ -399,6 +406,11 @@ public:
this->lv_source->listview_rows(*this));
};
size_t get_inner_width() const {
return this->lv_source == NULL ? 0 :
this->lv_source->listview_width(*this);
};
void set_needs_update() { this->lv_needs_update = true; };
/**

@ -625,8 +625,14 @@ void rebuild_indexes(bool force)
class time_label_source
: public hist_source::label_source {
public:
static const char *LINE_FORMAT;
time_label_source() { };
size_t hist_label_width() {
return strlen(LINE_FORMAT) + 8 * 3;
};
void hist_label_for_bucket(int bucket_start_value,
const hist_source::bucket_t &bucket,
string &label_out)
@ -665,13 +671,15 @@ public:
len = strlen(buffer);
snprintf(&buffer[len], sizeof(buffer) - len,
" %8d total %8d errors %8d warnings",
LINE_FORMAT,
total, errors, warnings);
label_out = string(buffer);
};
};
const char *time_label_source::LINE_FORMAT = " %8d total %8d errors %8d warnings";
static bool append_default_files(lnav_flags_t flag)
{
bool retval = true;

@ -59,7 +59,8 @@ throw (error)
lf_index_size(0),
lf_is_closed(false),
lf_logline_observer(NULL),
lf_logfile_observer(NULL)
lf_logfile_observer(NULL),
lf_longest_line(0)
{
require(filename.size() > 0);
@ -270,6 +271,7 @@ throw (line_buffer::error, logfile::error)
while (this->lf_line_buffer.read_line(off, sbr, &lv)) {
size_t old_size = this->lf_index.size();
this->lf_longest_line = std::max(this->lf_longest_line, sbr.length());
this->lf_partial_line = lv.lv_partial;
this->process_prefix(last_off, sbr);
last_off = off;

@ -114,6 +114,10 @@ public:
/** @return The inode for this log file. */
const struct stat &get_stat() const { return this->lf_stat; };
size_t get_longest_line_length() const {
return this->lf_longest_line;
}
bool is_compressed() const {
return this->lf_line_buffer.is_compressed();
};
@ -255,15 +259,16 @@ public:
return retval;
}
size_t line_length(iterator ll) {
size_t line_length(iterator ll, bool include_continues = true) {
iterator next_line = ll;
size_t retval;
do {
++next_line;
} while ((next_line != this->end()) &&
((ll->get_offset() == next_line->get_offset()) ||
next_line->is_continued()));
include_continues &&
((ll->get_offset() == next_line->get_offset()) ||
next_line->is_continued()));
if (next_line == this->end()) {
retval = this->lf_index_size - ll->get_offset();
@ -361,6 +366,7 @@ protected:
bool lf_partial_line;
logline_observer *lf_logline_observer;
logfile_observer *lf_logfile_observer;
size_t lf_longest_line;
};
class logline_observer {

@ -44,7 +44,8 @@ bookmark_type_t logfile_sub_source::BM_FILES("");
logfile_sub_source::logfile_sub_source()
: lss_flags(0),
lss_min_log_level(logline::LEVEL_UNKNOWN)
lss_min_log_level(logline::LEVEL_UNKNOWN),
lss_longest_line(0)
{
this->clear_line_size_cache();
}
@ -462,6 +463,7 @@ bool logfile_sub_source::rebuild_index(bool force)
this->lss_index.clear();
this->lss_filtered_index.clear();
this->lss_longest_line = 0;
}
if (retval || force) {
@ -472,13 +474,16 @@ bool logfile_sub_source::rebuild_index(bool force)
for (iter = this->lss_files.begin();
iter != this->lss_files.end();
iter++) {
if ((*iter)->get_file() == NULL)
logfile_data *ld = *iter;
logfile *lf = ld->get_file();
if (lf == NULL)
continue;
merge.add((*iter),
(*iter)->get_file()->begin() + (*iter)->ld_lines_indexed,
(*iter)->get_file()->end());
index_size += (*iter)->get_file()->size();
merge.add(ld,
lf->begin() + ld->ld_lines_indexed,
lf->end());
index_size += lf->size();
this->lss_longest_line = std::max(this->lss_longest_line, lf->get_longest_line_length());
}
this->lss_index.reset();
@ -534,10 +539,11 @@ bool logfile_sub_source::rebuild_index(bool force)
content_line_t cl = (content_line_t) this->lss_index[index_index];
uint64_t line_number;
logfile_data *ld = this->find_data(cl, line_number);
logfile::iterator line_iter = ld->get_file()->begin() + line_number;
if (!ld->ld_filter_state.excluded(filter_in_mask, filter_out_mask,
line_number) &&
(*(ld->get_file()->begin() + line_number)).get_msg_level() >=
line_iter->get_msg_level() >=
this->lss_min_log_level) {
this->lss_filtered_index.push_back(index_index);
if (this->lss_index_delegate != NULL) {

@ -124,6 +124,10 @@ public:
return this->lss_filtered_index.size();
};
size_t text_line_width() {
return this->lss_longest_line;
};
bool empty() const { return this->lss_filtered_index.empty(); };
void text_value_for_line(textview_curses &tc,
@ -536,5 +540,6 @@ private:
std::pair<int, size_t> lss_line_size_cache[LINE_SIZE_CACHE_SIZE];
logline::level_t lss_min_log_level;
index_delegate *lss_index_delegate;
size_t lss_longest_line;
};
#endif

@ -37,11 +37,14 @@ class plain_text_source
: public text_sub_source {
public:
plain_text_source(std::string text)
: tds_longest_line(0)
{
size_t start = 0, end;
while ((end = text.find('\n', start)) != std::string::npos) {
this->tds_lines.push_back(text.substr(start, end - start));
size_t len = (end - start);
this->tds_lines.push_back(text.substr(start, len));
this->tds_longest_line = std::max(this->tds_longest_line, len);
start = end + 1;
}
if (start < text.length()) {
@ -58,6 +61,10 @@ public:
return this->tds_lines.size();
};
size_t text_line_width() {
return this->tds_longest_line;
};
void text_value_for_line(textview_curses &tc,
int row,
std::string &value_out,
@ -72,6 +79,7 @@ public:
private:
std::vector<std::string> tds_lines;
size_t tds_longest_line;
};
#endif //LNAV_PLAIN_TEXT_SOURCE_HH

@ -63,6 +63,10 @@ public:
return retval;
};
size_t text_line_width() {
return this->tss_files.empty() ? 0 : this->current_file()->get_longest_line_length();
};
void text_value_for_line(textview_curses &tc,
int line,
std::string &value_out,

@ -276,6 +276,10 @@ public:
*/
virtual size_t text_line_count() = 0;
virtual size_t text_line_width() {
return INT_MAX;
};
/**
* Get the value for a line.
*
@ -610,6 +614,11 @@ public:
this->tc_sub_source->text_line_count();
};
size_t listview_width(const listview_curses &lv) {
return this->tc_sub_source == NULL ? 0 :
this->tc_sub_source->text_line_width();
};
void listview_value_for_row(const listview_curses &lv,
vis_line_t line,
attr_line_t &value_out);

Loading…
Cancel
Save