Skip to content

Commit

Permalink
Changing active_at type to Instant
Browse files Browse the repository at this point in the history
  • Loading branch information
dantepippi committed Apr 21, 2021
1 parent a8dae62 commit bab5279
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/client/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{common::SenderWithContext, pty_bus::VteBytes, tab::Pane, wasm_vm::PluginInstruction};

use std::{sync::mpsc::channel, unimplemented};

use crate::panes::{PaneId, PositionAndSize};
use crate::utils::shared::secs_from_epoch;

use std::time::Instant;
use std::{sync::mpsc::channel, unimplemented};

pub struct PluginPane {
pub pid: u32,
Expand All @@ -14,7 +14,7 @@ pub struct PluginPane {
pub position_and_size_override: Option<PositionAndSize>,
pub send_plugin_instructions: SenderWithContext<PluginInstruction>,
pub max_height: Option<usize>,
pub active_at: u64,
pub active_at: Instant,
}

impl PluginPane {
Expand All @@ -32,7 +32,7 @@ impl PluginPane {
position_and_size_override: None,
send_plugin_instructions,
max_height: None,
active_at: secs_from_epoch(),
active_at: Instant::now(),
}
}
}
Expand Down Expand Up @@ -202,11 +202,11 @@ impl Pane for PluginPane {
self.invisible_borders
}

fn active_at(&self) -> u64 {
fn active_at(&self) -> Instant {
self.active_at
}

fn set_active_at(&mut self, time: u64) {
fn set_active_at(&mut self, time: Instant) {
self.active_at = time;
}
}
10 changes: 5 additions & 5 deletions src/client/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::common::utils::shared::secs_from_epoch;
use crate::tab::Pane;
use ::nix::pty::Winsize;
use ::std::os::unix::io::RawFd;
use std::fmt::Debug;
use std::time::Instant;

use crate::panes::grid::Grid;
use crate::panes::terminal_character::{
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct TerminalPane {
pub position_and_size: PositionAndSize,
pub position_and_size_override: Option<PositionAndSize>,
pub max_height: Option<usize>,
pub active_at: u64,
pub active_at: Instant,
vte_parser: vte::Parser,
}

Expand Down Expand Up @@ -275,11 +275,11 @@ impl Pane for TerminalPane {
self.grid.should_render = true;
}

fn active_at(&self) -> u64 {
fn active_at(&self) -> Instant {
self.active_at
}

fn set_active_at(&mut self, time: u64) {
fn set_active_at(&mut self, time: Instant) {
self.active_at = time;
}
}
Expand All @@ -295,7 +295,7 @@ impl TerminalPane {
position_and_size_override: None,
max_height: None,
vte_parser: vte::Parser::new(),
active_at: secs_from_epoch(),
active_at: Instant::now(),
}
}
pub fn get_x(&self) -> usize {
Expand Down
9 changes: 5 additions & 4 deletions src/client/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use crate::layout::Layout;
use crate::os_input_output::OsApi;
use crate::panes::{PaneId, PositionAndSize, TerminalPane};
use crate::pty_bus::{PtyInstruction, VteBytes};
use crate::utils::shared::{adjust_to_size, secs_from_epoch};
use crate::utils::shared::adjust_to_size;
use crate::wasm_vm::PluginInstruction;
use crate::{boundaries::Boundaries, panes::PluginPane};
use serde::{Deserialize, Serialize};
use std::os::unix::io::RawFd;
use std::time::Instant;
use std::{
cmp::Reverse,
collections::{BTreeMap, HashSet},
Expand Down Expand Up @@ -118,8 +119,8 @@ pub trait Pane {
fn scroll_up(&mut self, count: usize);
fn scroll_down(&mut self, count: usize);
fn clear_scroll(&mut self);
fn active_at(&self) -> u64;
fn set_active_at(&mut self, time: u64);
fn active_at(&self) -> Instant;
fn set_active_at(&mut self, instant: Instant);

fn right_boundary_x_coords(&self) -> usize {
self.x() + self.columns()
Expand Down Expand Up @@ -681,7 +682,7 @@ impl Tab {
if !self.panes_to_hide.contains(&pane.pid()) {
match self.active_terminal.unwrap() == pane.pid() {
true => {
pane.set_active_at(secs_from_epoch());
pane.set_active_at(Instant::now());
boundaries.add_rect(pane.as_ref(), self.mode_info.mode, Some(colors::GREEN))
}
false => boundaries.add_rect(pane.as_ref(), self.mode_info.mode, None),
Expand Down
8 changes: 0 additions & 8 deletions src/common/utils/shared.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
//! Some general utility functions.
use std::time::{SystemTime, UNIX_EPOCH};
use std::{iter, str::from_utf8};

use strip_ansi_escapes::strip;

pub fn secs_from_epoch() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs()
}

fn ansi_len(s: &str) -> usize {
from_utf8(&strip(s.as_bytes()).unwrap())
.unwrap()
Expand Down

0 comments on commit bab5279

Please sign in to comment.