allow dump_screen() to only dump the viewport (#1794)

* allow dump_screen() to only dump the viewport

* add additional implementations

* set full default as false
This commit is contained in:
Dan Näsman 2022-10-19 16:49:13 +03:00 committed by GitHub
parent 5878e9f6f8
commit 2e70a4c672
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 40 additions and 19 deletions

View file

@ -985,9 +985,12 @@ impl Grid {
} }
} }
pub fn dump_screen(&mut self) -> String { pub fn dump_screen(&mut self, full: bool) -> String {
let mut scrollback: String = dump_screen!(self.lines_above);
let viewport: String = dump_screen!(self.viewport); let viewport: String = dump_screen!(self.viewport);
if !full {
return viewport;
}
let mut scrollback: String = dump_screen!(self.lines_above);
if !scrollback.is_empty() { if !scrollback.is_empty() {
scrollback.push('\n'); scrollback.push('\n');
} }

View file

@ -512,8 +512,8 @@ impl Pane for TerminalPane {
self.geom.y -= count; self.geom.y -= count;
self.reflow_lines(); self.reflow_lines();
} }
fn dump_screen(&mut self, _client_id: ClientId) -> String { fn dump_screen(&mut self, _client_id: ClientId, full: bool) -> String {
self.grid.dump_screen() self.grid.dump_screen(full)
} }
fn scroll_up(&mut self, count: usize, _client_id: ClientId) { fn scroll_up(&mut self, count: usize, _client_id: ClientId) {
self.grid.move_viewport_up(count); self.grid.move_viewport_up(count);

View file

@ -157,10 +157,10 @@ pub(crate) fn route_action(
}; };
session.senders.send_to_screen(screen_instr).unwrap(); session.senders.send_to_screen(screen_instr).unwrap();
}, },
Action::DumpScreen(val) => { Action::DumpScreen(val, full) => {
session session
.senders .senders
.send_to_screen(ScreenInstruction::DumpScreen(val, client_id)) .send_to_screen(ScreenInstruction::DumpScreen(val, client_id, full))
.unwrap(); .unwrap();
}, },
Action::EditScrollback => { Action::EditScrollback => {

View file

@ -147,7 +147,7 @@ pub enum ScreenInstruction {
MovePaneRight(ClientId), MovePaneRight(ClientId),
MovePaneLeft(ClientId), MovePaneLeft(ClientId),
Exit, Exit,
DumpScreen(String, ClientId), DumpScreen(String, ClientId, bool),
EditScrollback(ClientId), EditScrollback(ClientId),
ScrollUp(ClientId), ScrollUp(ClientId),
ScrollUpAt(Position, ClientId), ScrollUpAt(Position, ClientId),
@ -1437,12 +1437,15 @@ pub(crate) fn screen_thread_main(
screen.render()?; screen.render()?;
screen.unblock_input()?; screen.unblock_input()?;
}, },
ScreenInstruction::DumpScreen(file, client_id) => { ScreenInstruction::DumpScreen(file, client_id, full) => {
active_tab_and_connected_client_id!( active_tab_and_connected_client_id!(
screen, screen,
client_id, client_id,
|tab: &mut Tab, client_id: ClientId| tab |tab: &mut Tab, client_id: ClientId| tab.dump_active_terminal_screen(
.dump_active_terminal_screen(Some(file.to_string()), client_id) Some(file.to_string()),
client_id,
full
)
); );
screen.render()?; screen.render()?;
screen.unblock_input()?; screen.unblock_input()?;

View file

@ -165,7 +165,7 @@ pub trait Pane {
fn push_right(&mut self, count: usize); fn push_right(&mut self, count: usize);
fn pull_left(&mut self, count: usize); fn pull_left(&mut self, count: usize);
fn pull_up(&mut self, count: usize); fn pull_up(&mut self, count: usize);
fn dump_screen(&mut self, _client_id: ClientId) -> String { fn dump_screen(&mut self, _client_id: ClientId, _full: bool) -> String {
"".to_owned() "".to_owned()
} }
fn scroll_up(&mut self, count: usize, client_id: ClientId); fn scroll_up(&mut self, count: usize, client_id: ClientId);
@ -1800,16 +1800,25 @@ impl Tab {
} }
Ok(()) Ok(())
} }
pub fn dump_active_terminal_screen(&mut self, file: Option<String>, client_id: ClientId) { pub fn dump_active_terminal_screen(
&mut self,
file: Option<String>,
client_id: ClientId,
full: bool,
) {
if let Some(active_pane) = self.get_active_pane_or_floating_pane_mut(client_id) { if let Some(active_pane) = self.get_active_pane_or_floating_pane_mut(client_id) {
let dump = active_pane.dump_screen(client_id); let dump = active_pane.dump_screen(client_id, full);
self.os_api.write_to_file(dump, file); self.os_api.write_to_file(dump, file);
} }
} }
pub fn edit_scrollback(&mut self, client_id: ClientId) -> Result<()> { pub fn edit_scrollback(&mut self, client_id: ClientId) -> Result<()> {
let mut file = temp_dir(); let mut file = temp_dir();
file.push(format!("{}.dump", Uuid::new_v4())); file.push(format!("{}.dump", Uuid::new_v4()));
self.dump_active_terminal_screen(Some(String::from(file.to_string_lossy())), client_id); self.dump_active_terminal_screen(
Some(String::from(file.to_string_lossy())),
client_id,
true,
);
let line_number = self let line_number = self
.get_active_pane(client_id) .get_active_pane(client_id)
.and_then(|a_t| a_t.get_line_number()); .and_then(|a_t| a_t.get_line_number());

View file

@ -507,7 +507,7 @@ fn dump_screen() {
tab.handle_pty_bytes(2, Vec::from("scratch".as_bytes())) tab.handle_pty_bytes(2, Vec::from("scratch".as_bytes()))
.unwrap(); .unwrap();
let file = "/tmp/log.sh"; let file = "/tmp/log.sh";
tab.dump_active_terminal_screen(Some(file.to_string()), client_id); tab.dump_active_terminal_screen(Some(file.to_string()), client_id, false);
assert_eq!( assert_eq!(
map.lock().unwrap().get(file).unwrap(), map.lock().unwrap().get(file).unwrap(),
"scratch", "scratch",

View file

@ -1190,6 +1190,7 @@ pub fn send_cli_dump_screen_action() {
); );
let cli_action = CliAction::DumpScreen { let cli_action = CliAction::DumpScreen {
path: PathBuf::from("/tmp/foo"), path: PathBuf::from("/tmp/foo"),
full: true,
}; };
let _ = mock_screen.to_screen.send(ScreenInstruction::PtyBytes( let _ = mock_screen.to_screen.send(ScreenInstruction::PtyBytes(
0, 0,

View file

@ -181,7 +181,11 @@ pub enum CliAction {
/// [right|left|up|down] /// [right|left|up|down]
MovePane { direction: Direction }, MovePane { direction: Direction },
/// Dumps the pane scrollback to a file /// Dumps the pane scrollback to a file
DumpScreen { path: PathBuf }, DumpScreen {
path: PathBuf,
#[clap(short, long, value_parser, default_value("false"), takes_value(false))]
full: bool,
},
/// Open the pane scrollback in your default editor /// Open the pane scrollback in your default editor
EditScrollback, EditScrollback,
/// Scroll up in the focused pane /// Scroll up in the focused pane

View file

@ -139,7 +139,7 @@ pub enum Action {
MoveFocusOrTab(Direction), MoveFocusOrTab(Direction),
MovePane(Option<Direction>), MovePane(Option<Direction>),
/// Dumps the screen to a file /// Dumps the screen to a file
DumpScreen(String), DumpScreen(String, bool),
/// Scroll up in focus pane. /// Scroll up in focus pane.
EditScrollback, EditScrollback,
ScrollUp, ScrollUp,
@ -237,8 +237,9 @@ impl Action {
CliAction::MoveFocus { direction } => Ok(vec![Action::MoveFocus(direction)]), CliAction::MoveFocus { direction } => Ok(vec![Action::MoveFocus(direction)]),
CliAction::MoveFocusOrTab { direction } => Ok(vec![Action::MoveFocusOrTab(direction)]), CliAction::MoveFocusOrTab { direction } => Ok(vec![Action::MoveFocusOrTab(direction)]),
CliAction::MovePane { direction } => Ok(vec![Action::MovePane(Some(direction))]), CliAction::MovePane { direction } => Ok(vec![Action::MovePane(Some(direction))]),
CliAction::DumpScreen { path } => Ok(vec![Action::DumpScreen( CliAction::DumpScreen { path, full } => Ok(vec![Action::DumpScreen(
path.as_os_str().to_string_lossy().into(), path.as_os_str().to_string_lossy().into(),
full,
)]), )]),
CliAction::EditScrollback => Ok(vec![Action::EditScrollback]), CliAction::EditScrollback => Ok(vec![Action::EditScrollback]),
CliAction::ScrollUp => Ok(vec![Action::ScrollUp]), CliAction::ScrollUp => Ok(vec![Action::ScrollUp]),

View file

@ -427,7 +427,7 @@ impl Action {
Ok(Action::MovePane(Some(direction))) Ok(Action::MovePane(Some(direction)))
} }
}, },
"DumpScreen" => Ok(Action::DumpScreen(string)), "DumpScreen" => Ok(Action::DumpScreen(string, false)),
"NewPane" => { "NewPane" => {
if string.is_empty() { if string.is_empty() {
return Ok(Action::NewPane(None, None)); return Ok(Action::NewPane(None, None));