Skip to content

Commit dbbfe01

Browse files
committed
[file_collection] erase error for directory
1 parent d28d9a7 commit dbbfe01

35 files changed

Lines changed: 542 additions & 339 deletions

docs/schemas/config-v1.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@
962962
"title": "/ui/theme-defs/<theme_name>/status-styles/title",
963963
"$ref": "#/definitions/style"
964964
},
965+
"alert-title": {
966+
"description": "Styling for title sections of status bars with alerts",
967+
"title": "/ui/theme-defs/<theme_name>/status-styles/alert-title",
968+
"$ref": "#/definitions/style"
969+
},
965970
"disabled-title": {
966971
"description": "Styling for title sections of status bars",
967972
"title": "/ui/theme-defs/<theme_name>/status-styles/disabled-title",

src/base/string_attr_type.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ enum class role_t : int32_t {
119119
VCR_STATUS_TITLE_HOTKEY,
120120
VCR_STATUS_DISABLED_TITLE,
121121
VCR_STATUS_HOTKEY,
122+
VCR_ALERT_STATUS_TITLE,
123+
VCR_STATUS_STITCH_ALERT_TITLE_TO_NORMAL,
124+
VCR_STATUS_STITCH_NORMAL_TO_ALERT_TITLE,
122125
VCR_INACTIVE_STATUS,
123126
VCR_INACTIVE_WARN_STATUS,
124127
VCR_INACTIVE_ALERT_STATUS,

src/file_collection.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,17 @@ file_collection::merge(file_collection& other)
226226

227227
this->fc_synced_files.insert(other.fc_synced_files.begin(),
228228
other.fc_synced_files.end());
229-
230229
std::map<std::string, file_stub_info> new_stubs;
231230
{
232231
safe::ReadAccess<safe_name_to_stubs> errs(*other.fc_name_to_stubs);
233232

234233
new_stubs.insert(errs->cbegin(), errs->cend());
235234
}
236-
{
235+
if (!new_stubs.empty()) {
237236
safe::WriteAccess<safe_name_to_stubs> errs(*this->fc_name_to_stubs);
238237

239238
errs->insert(new_stubs.begin(), new_stubs.end());
239+
this->fc_files_generation += 1;
240240
}
241241
if (!other.fc_file_names.empty()) {
242242
this->fc_files_generation += 1;
@@ -331,7 +331,8 @@ struct same_file {
331331
* @param required Specifies whether or not the file must exist and be valid.
332332
*/
333333
std::optional<std::future<file_collection>>
334-
file_collection::watch_logfile(const std::string& filename,
334+
file_collection::watch_logfile(const std::string& user_req,
335+
const std::string& filename,
335336
logfile_open_options& loo,
336337
bool required)
337338
{
@@ -379,11 +380,11 @@ file_collection::watch_logfile(const std::string& filename,
379380
{
380381
safe::WriteAccess<safe_name_to_stubs> errs(*this->fc_name_to_stubs);
381382

382-
auto err_iter = errs->find(filename_key);
383+
auto err_iter = errs->find(user_req);
383384
if (err_iter != errs->end()) {
384385
if (err_iter->second.fsi_mtime != st.st_mtime) {
385386
log_debug("clearing error info for file: %s",
386-
filename_key.c_str());
387+
user_req.c_str());
387388
errs->erase(err_iter);
388389
}
389390
}
@@ -849,7 +850,8 @@ file_collection::expand_filename(
849850
}
850851

851852
if (required || access(iter->second.c_str(), R_OK) == 0) {
852-
auto future_opt = watch_logfile(iter->second, loo, required);
853+
auto future_opt
854+
= watch_logfile(filename_key, iter->second, loo, required);
853855
if (future_opt) {
854856
auto fut = std::move(future_opt.value());
855857
if (fq.push_back(std::move(fut))
@@ -1003,6 +1005,7 @@ file_collection::copy()
10031005
file_collection retval;
10041006

10051007
retval.merge(*this);
1008+
retval.fc_name_to_stubs = this->fc_name_to_stubs;
10061009
retval.fc_progress = this->fc_progress;
10071010
return retval;
10081011
}

src/file_collection.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ struct file_collection {
223223
bool required);
224224

225225
std::optional<std::future<file_collection>> watch_logfile(
226-
const std::string& filename, logfile_open_options& loo, bool required);
226+
const std::string& user_req,
227+
const std::string& filename,
228+
logfile_open_options& loo,
229+
bool required);
227230

228231
void merge(file_collection& other);
229232

src/filter_status_source.cc

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,54 @@ filter_status_source::statusview_fields()
119119
break;
120120
}
121121

122+
size_t error_count = 0;
123+
124+
auto& fc = lnav_data.ld_active_files;
125+
{
126+
auto stub_map = fc.fc_name_to_stubs->readAccess();
127+
128+
for (const auto& stub : *stub_map) {
129+
switch (stub.second.fsi_description.um_level) {
130+
case lnav::console::user_message::level::raw:
131+
case lnav::console::user_message::level::ok:
132+
case lnav::console::user_message::level::info:
133+
case lnav::console::user_message::level::warning:
134+
break;
135+
case lnav::console::user_message::level::error:
136+
error_count += 1;
137+
break;
138+
}
139+
}
140+
}
141+
142+
if (error_count == 0) {
143+
this->tss_error.clear();
144+
} else if (error_count == 1) {
145+
this->tss_error.set_value(" error: a file cannot be opened "_frag);
146+
} else if (error_count > 1) {
147+
this->tss_error.set_value(" error: %zu files cannot be opened ",
148+
error_count);
149+
}
150+
122151
if (lnav_data.ld_mode == ln_mode_t::FILES
123152
|| lnav_data.ld_mode == ln_mode_t::FILE_DETAILS
124153
|| lnav_data.ld_mode == ln_mode_t::SEARCH_FILES)
125154
{
126155
this->tss_fields[TSF_FILES_TITLE].set_value(
127156
" " ANSI_ROLE("F") "iles ", role_t::VCR_STATUS_TITLE_HOTKEY);
128-
this->tss_fields[TSF_FILES_TITLE].set_role(role_t::VCR_STATUS_TITLE);
129-
this->tss_fields[TSF_FILES_RIGHT_STITCH].set_stitch_value(
130-
role_t::VCR_STATUS_STITCH_TITLE_TO_NORMAL,
131-
role_t::VCR_STATUS_STITCH_NORMAL_TO_TITLE);
157+
if (error_count > 0) {
158+
this->tss_fields[TSF_FILES_TITLE].set_role(
159+
role_t::VCR_ALERT_STATUS_TITLE);
160+
this->tss_fields[TSF_FILES_RIGHT_STITCH].set_stitch_value(
161+
role_t::VCR_STATUS_STITCH_ALERT_TITLE_TO_NORMAL,
162+
role_t::VCR_STATUS_STITCH_NORMAL_TO_ALERT_TITLE);
163+
} else {
164+
this->tss_fields[TSF_FILES_TITLE].set_role(
165+
role_t::VCR_STATUS_TITLE);
166+
this->tss_fields[TSF_FILES_RIGHT_STITCH].set_stitch_value(
167+
role_t::VCR_STATUS_STITCH_TITLE_TO_NORMAL,
168+
role_t::VCR_STATUS_STITCH_NORMAL_TO_TITLE);
169+
}
132170
this->tss_fields[TSF_TITLE].set_value(" " ANSI_ROLE("T") "ext Filters ",
133171
role_t::VCR_STATUS_HOTKEY);
134172
this->tss_fields[TSF_TITLE].set_role(role_t::VCR_STATUS_DISABLED_TITLE);
@@ -137,43 +175,12 @@ filter_status_source::statusview_fields()
137175
} else {
138176
this->tss_fields[TSF_FILES_TITLE].set_value(" " ANSI_ROLE("F") "iles ",
139177
role_t::VCR_STATUS_HOTKEY);
140-
if (lnav_data.ld_active_files.fc_name_to_stubs->readAccess()->empty()) {
178+
if (error_count > 0) {
141179
this->tss_fields[TSF_FILES_TITLE].set_role(
142-
role_t::VCR_STATUS_DISABLED_TITLE);
180+
role_t::VCR_ALERT_STATUS);
143181
} else {
144-
size_t error_count = 0;
145-
size_t other_count = 0;
146-
147-
auto& fc = lnav_data.ld_active_files;
148-
{
149-
auto stub_map = fc.fc_name_to_stubs->readAccess();
150-
151-
for (const auto& stub : *stub_map) {
152-
switch (stub.second.fsi_description.um_level) {
153-
case lnav::console::user_message::level::raw:
154-
case lnav::console::user_message::level::ok:
155-
case lnav::console::user_message::level::info:
156-
case lnav::console::user_message::level::warning:
157-
other_count += 1;
158-
break;
159-
case lnav::console::user_message::level::error:
160-
error_count += 1;
161-
break;
162-
}
163-
}
164-
}
165-
166-
if (error_count > 0) {
167-
this->tss_fields[TSF_FILES_TITLE].set_role(
168-
role_t::VCR_ALERT_STATUS);
169-
}
170-
if (error_count == 1) {
171-
this->tss_error.set_value(
172-
" error: a file cannot be opened "_frag);
173-
} else if (error_count > 1) {
174-
this->tss_error.set_value(" error: %zu files cannot be opened ",
175-
error_count);
176-
}
182+
this->tss_fields[TSF_FILES_TITLE].set_role(
183+
role_t::VCR_STATUS_DISABLED_TITLE);
177184
}
178185
this->tss_fields[TSF_FILES_RIGHT_STITCH].set_stitch_value(
179186
role_t::VCR_STATUS_STITCH_NORMAL_TO_TITLE,

src/lnav.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,7 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
19031903
static auto& mlooper = injector::get<main_looper&, services::main_t>();
19041904
mlooper.s_wakeup_fd = wakeup_pair.write_end().get();
19051905

1906+
int last_files_generation = lnav_data.ld_active_files.fc_files_generation;
19061907
exec_phase.completed(lnav::phase_t::init);
19071908
while (lnav_data.ld_looping) {
19081909
auto loop_deadline
@@ -1974,11 +1975,7 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
19741975
lnav_data.ld_active_files.fc_files.size());
19751976
exec_phase.completed(lnav::phase_t::scan);
19761977
}
1977-
auto old_gen = lnav_data.ld_active_files.fc_files_generation;
19781978
update_active_files(new_files);
1979-
if (old_gen != lnav_data.ld_active_files.fc_files_generation) {
1980-
next_rebuild_time = ui_now;
1981-
}
19821979
if (!exec_phase.scan_completed()) {
19831980
auto& fview = lnav_data.ld_files_view;
19841981
auto height = fview.get_inner_height();
@@ -2015,8 +2012,19 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
20152012
}
20162013

20172014
mlooper.get_port().process_for(0s);
2018-
20192015
ui_now = ui_clock::now();
2016+
2017+
if (last_files_generation
2018+
!= lnav_data.ld_active_files.fc_files_generation)
2019+
{
2020+
next_rebuild_time = ui_now;
2021+
lnav_data.ld_files_view.reload_data();
2022+
lnav_data.ld_status[LNS_FILTER].set_needs_update();
2023+
lnav_data.ld_status[LNS_FILTER_HELP].set_needs_update();
2024+
last_files_generation
2025+
= lnav_data.ld_active_files.fc_files_generation;
2026+
}
2027+
20202028
if (exec_phase.scan_completed()) {
20212029
auto* tc = lnav_data.ld_view_stack.top().value_or(nullptr);
20222030
if (tc != nullptr
@@ -2065,9 +2073,9 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
20652073
lnav_data.ld_filter_view.set_needs_update();
20662074
}
20672075
if ((lnav_data.ld_files_view.is_visible()
2068-
&& lnav_data.ld_files_view.get_needs_update())
2069-
|| (lnav_data.ld_filter_view.is_visible()
2070-
&& lnav_data.ld_filter_view.get_needs_update()))
2076+
|| lnav_data.ld_filter_view.is_visible())
2077+
&& (lnav_data.ld_files_view.get_needs_update()
2078+
|| lnav_data.ld_filter_view.get_needs_update()))
20712079
{
20722080
// log_trace("config panels updated, update prompt");
20732081
prompt.p_editor.set_needs_update();

src/lnav_config.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,10 @@ static const struct json_path_container theme_status_styles_handlers = {
11211121
.with_description("Styling for title sections of status bars")
11221122
.for_child(&lnav_theme::lt_style_status_title)
11231123
.with_children(style_config_handlers),
1124+
yajlpp::property_handler("alert-title")
1125+
.with_description("Styling for title sections of status bars with alerts")
1126+
.for_child(&lnav_theme::lt_style_status_alert_title)
1127+
.with_children(style_config_handlers),
11241128
yajlpp::property_handler("disabled-title")
11251129
.with_description("Styling for title sections of status bars")
11261130
.for_child(&lnav_theme::lt_style_status_disabled_title)

src/styling.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct lnav_theme {
141141
positioned_property<style_config> lt_style_invalid_msg;
142142
positioned_property<style_config> lt_style_status_title;
143143
positioned_property<style_config> lt_style_status_title_hotkey;
144+
positioned_property<style_config> lt_style_status_alert_title;
144145
positioned_property<style_config> lt_style_status_disabled_title;
145146
positioned_property<style_config> lt_style_status_subtitle;
146147
positioned_property<style_config> lt_style_status_info;

src/themes/default-theme.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@
309309
"background-color": "Navy",
310310
"bold": true
311311
},
312+
"alert-title": {
313+
"color": "Maroon",
314+
"background-color": "Navy",
315+
"bold": true
316+
},
312317
"disabled-title": {
313318
"color": "Black",
314319
"background-color": "Silver",

src/themes/dracula.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@
275275
"background-color": "#5394ec",
276276
"bold": true
277277
},
278+
"alert-title": {
279+
"color": "$red",
280+
"background-color": "#5394ec",
281+
"bold": true
282+
},
278283
"subtitle": {
279284
"color": "#555",
280285
"background-color": "#66d9ee",

0 commit comments

Comments
 (0)