1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 23:21:08 +03:00

debug overlay: remember last log line globally

It can be confusing to see the same log lines when re-opening
the debug overlay, so this commit remembers the last line
in a global to make that feel more natural.

Because that causes the initial `OpenGL Initialized!` log to
show only in the first instance of the overlay, that log line
is now changed to debug level and the overlay will now
explicitly log the version information, along with some
brief usage text:

```
Debug Overlay
wezterm version: 20220714-001416-810512c2
OpenGL version: AMD BEIGE_GOBY (LLVM 14.0.0, DRM 3.46, 5.18.10-200.fc36.x86_64) 4.6 (Compatibility Profile) Mesa 22.1.3
Enter lua statements or expressions and hit Enter.
Press ESC or CTRL-D to exit
```
This commit is contained in:
Wez Furlong 2022-07-14 06:53:41 -07:00
parent 810512c2c5
commit 49ab340a92
2 changed files with 36 additions and 13 deletions

View File

@ -7,6 +7,7 @@ use mlua::Value;
use mux::termwiztermtab::TermWizTerminal;
use std::io::Write;
use std::path::PathBuf;
use std::sync::Mutex;
use termwiz::cell::{AttributeChange, CellAttributes, Intensity};
use termwiz::color::AnsiColor;
use termwiz::input::{InputEvent, KeyCode, KeyEvent};
@ -14,6 +15,10 @@ use termwiz::lineedit::*;
use termwiz::surface::Change;
use termwiz::terminal::Terminal;
lazy_static::lazy_static! {
static ref LATEST_LOG_ENTRY: Mutex<Option<DateTime<Local>>> = Mutex::new(None);
}
struct LuaReplHost {
history: BasicHistory,
lua: mlua::Lua,
@ -127,7 +132,11 @@ impl LineEditorHost for LuaReplHost {
}
}
pub fn show_debug_overlay(mut term: TermWizTerminal, gui_win: GuiWin) -> anyhow::Result<()> {
pub fn show_debug_overlay(
mut term: TermWizTerminal,
gui_win: GuiWin,
opengl_info: String,
) -> anyhow::Result<()> {
term.no_grab_mouse_in_raw_mode();
let config::LoadedConfig { lua, .. } = config::Config::load();
@ -144,25 +153,21 @@ pub fn show_debug_overlay(mut term: TermWizTerminal, gui_win: GuiWin) -> anyhow:
lua.load("wezterm = require 'wezterm'").exec()?;
lua.globals().set("window", gui_win)?;
let mut latest_log_entry = None;
let mut host = Some(LuaReplHost::new(lua));
term.render(&[Change::Title("Debug".to_string())])?;
fn print_new_log_entries(
term: &mut TermWizTerminal,
latest: &mut Option<DateTime<Local>>,
) -> termwiz::Result<()> {
fn print_new_log_entries(term: &mut TermWizTerminal) -> termwiz::Result<()> {
let entries = env_bootstrap::ringlog::get_entries();
let mut changes = vec![];
for entry in entries {
if let Some(latest) = latest {
if let Some(latest) = LATEST_LOG_ENTRY.lock().unwrap().as_ref() {
if entry.then <= *latest {
// already seen this one
continue;
}
}
latest.replace(entry.then);
LATEST_LOG_ENTRY.lock().unwrap().replace(entry.then);
changes.push(Change::AllAttributes(CellAttributes::default()));
changes.push(Change::Text(entry.then.format("%H:%M:%S%.3f ").to_string()));
@ -190,8 +195,17 @@ pub fn show_debug_overlay(mut term: TermWizTerminal, gui_win: GuiWin) -> anyhow:
term.render(&changes)
}
term.render(&[Change::Text(format!(
"Debug Overlay\r\n\
wezterm version: {}\r\n\
OpenGL version: {opengl_info}\r\n\
Enter lua statements or expressions and hit Enter.\r\n\
Press ESC or CTRL-D to exit\r\n",
config::wezterm_version()
))])?;
loop {
print_new_log_entries(&mut term, &mut latest_log_entry)?;
print_new_log_entries(&mut term)?;
let mut editor = LineEditor::new(&mut term);
editor.set_prompt("> ");
if let Some(line) = editor.read_line(host.as_mut().unwrap())? {

View File

@ -384,6 +384,8 @@ pub struct TermWindow {
current_mouse_buttons: Vec<MousePress>,
current_mouse_capture: Option<MouseCapture>,
opengl_info: Option<String>,
/// Keeps track of double and triple clicks
last_mouse_click: Option<LastMouseClick>,
@ -509,11 +511,15 @@ impl TermWindow {
match RenderState::new(ctx, &self.fonts, &self.render_metrics, ATLAS_SIZE) {
Ok(gl) => {
log::info!(
"OpenGL initialized! {} {} is_context_loss_possible={} wezterm version: {}",
self.opengl_info.replace(format!(
"{} {}",
gl.context.get_opengl_renderer_string(),
gl.context.get_opengl_version_string()
));
log::debug!(
"OpenGL initialized! {} {} wezterm version: {}",
gl.context.get_opengl_renderer_string(),
gl.context.get_opengl_version_string(),
gl.context.is_context_loss_possible(),
config::wezterm_version(),
);
self.render_state.replace(gl);
@ -699,6 +705,7 @@ impl TermWindow {
is_click_to_focus_window: false,
key_table_state: KeyTableState::default(),
modal: RefCell::new(None),
opengl_info: None,
};
let tw = Rc::new(RefCell::new(myself));
@ -1809,8 +1816,10 @@ impl TermWindow {
let gui_win = GuiWin::new(self);
let opengl_info = self.opengl_info.as_deref().unwrap_or("Unknown").to_string();
let (overlay, future) = start_overlay(self, &tab, move |_tab_id, term| {
crate::overlay::show_debug_overlay(term, gui_win)
crate::overlay::show_debug_overlay(term, gui_win, opengl_info)
});
self.assign_overlay(tab.tab_id(), overlay);
promise::spawn::spawn(future).detach();