Skip to content

Commit

Permalink
new app layout
Browse files Browse the repository at this point in the history
  • Loading branch information
adgaultier committed Jan 9, 2025
1 parent f35b45b commit babe1c7
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 354 deletions.
25 changes: 3 additions & 22 deletions tamanoir-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use std::{
};

use anyhow::Result;
use ratatui::{
layout::{Constraint, Direction, Layout},
Frame,
};
use ratatui::Frame;

use crate::{
grpc::{RemoteShellServiceClient, SessionServiceClient, StreamReceiver},
Expand All @@ -31,11 +28,6 @@ pub struct App {
pub session_client: SessionServiceClient,
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum ActivePopup {
Help,
}

impl App {
pub async fn new(ip: Ipv4Addr, port: u16) -> AppResult<Self> {
let sessions: SessionsMap = SessionsMap::default();
Expand All @@ -49,7 +41,7 @@ impl App {
let mut session_receiver = session_client.clone();

let mut sections = Sections::new(shell_std.clone(), sessions.clone());
sections.sessions_section.init(&mut session_client).await?;
sections.session_section.init(&mut session_client).await?;

tokio::spawn(async move {
tokio::try_join!(
Expand All @@ -69,18 +61,7 @@ impl App {
}

pub fn render(&mut self, frame: &mut Frame) {
let (_settings_block, section_block) = {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(6),
Constraint::Length(1),
Constraint::Fill(1),
])
.split(frame.area());
(chunks[0], chunks[2])
};
self.sections.render(frame, section_block, None);
self.sections.render(frame, frame.area());
}

pub fn quit(&mut self) {
Expand Down
11 changes: 7 additions & 4 deletions tamanoir-tui/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tonic::{transport::Channel, Request};
use crate::{
app::{AppResult, SessionsMap},
section::{
session::utils::init_keymaps,
keylogger::utils::init_keymaps,
shell::{ShellCmd, ShellCmdHistory, ShellStdType},
},
tamanoir_grpc::{
Expand Down Expand Up @@ -90,9 +90,12 @@ impl RceServiceClient {
.await?;
Ok(())
}
pub async fn list_available_rce() -> AppResult<Vec<SessionRcePayload>> {
let res = vec![];
Ok(res)
pub async fn list_available_rce(&mut self) -> anyhow::Result<Vec<SessionRcePayload>> {
let res = self
.client
.list_available_rce(Request::new(Empty {}))
.await?;
Ok(res.into_inner().rce_list)
}
}
pub trait StreamReceiver<T> {
Expand Down
62 changes: 62 additions & 0 deletions tamanoir-tui/src/section/keylogger/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
pub mod utils;

use ratatui::{
layout::{Margin, Rect},
style::{Color, Style, Stylize},
text::{Span, Text},
widgets::{Block, BorderType, Paragraph, Wrap},
Frame,
};
use utils::Layout;

use crate::tamanoir_grpc::SessionResponse;

#[derive(Debug)]
pub struct KeyLoggerSection {
layout: Layout,
}
impl KeyLoggerSection {
pub fn new() -> Self {
Self {
layout: Layout::Azerty,
}
}
pub fn render(
&mut self,
frame: &mut Frame,
block: Rect,
selected_session: &mut Option<SessionResponse>,
is_focused: bool,
) {
let txt = match selected_session {
Some(session) => match session.parse_keycodes(self.layout.clone()) {
Ok(kc) => Text::from(SessionResponse::format_keys(kc)),

Err(_) => Text::from("Error decoding keycodes".to_string()).centered(),
},
_ => Text::from("No Session selected".to_string()).centered(),
};
let highlight_color = if is_focused {
Color::Yellow
} else {
Color::Blue
};
let p = Paragraph::new(txt).wrap(Wrap { trim: true }).block(
Block::bordered()
.border_type(BorderType::Rounded)
.border_style(Style::new().fg(highlight_color))
.title(Span::styled(
"Keylogger",
Style::default().fg(highlight_color).bold(),
)),
);

frame.render_widget(
p,
block.inner(Margin {
horizontal: 1,
vertical: 0,
}),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{collections::HashMap, sync::OnceLock};

use ratatui::style::{palette::tailwind, Color};
pub static KEYMAPS: OnceLock<HashMap<u8, KeyMap>> = OnceLock::new();
const AZERTY: &str = include_str!("../../../../assets/layouts/azerty.yml");
const QWERTY: &str = include_str!("../../../../assets/layouts/qwerty.yml");
Expand All @@ -26,33 +25,6 @@ use serde::Deserialize;

use crate::{app::AppResult, tamanoir_grpc::SessionResponse};
const COMMON_REPEATED_KEYS: [&str; 4] = [" 󱊷 ", " 󰌑 ", " 󰁮 ", "  "];
pub const PALETTES: [tailwind::Palette; 4] = [
tailwind::BLUE,
tailwind::EMERALD,
tailwind::INDIGO,
tailwind::RED,
];
#[derive(Debug)]
pub struct TableColors {
pub buffer_bg: Color,
pub row_fg: Color,
pub selected_row_style_fg: Color,
pub normal_row_color: Color,
pub alt_row_color: Color,
pub footer_border_color: Color,
}
impl TableColors {
pub const fn new(color: &tailwind::Palette) -> Self {
Self {
buffer_bg: tailwind::SLATE.c950,
row_fg: tailwind::SLATE.c200,
selected_row_style_fg: color.c400,
normal_row_color: tailwind::SLATE.c950,
alt_row_color: tailwind::SLATE.c900,
footer_border_color: color.c400,
}
}
}

#[derive(Debug, Clone, PartialEq, Deserialize)]
pub enum TargetArch {
Expand Down Expand Up @@ -103,6 +75,10 @@ impl FromStr for TargetArch {
}
}
}
impl TargetArch {
pub const ALL: [Self; 2] = [Self::X86_64, Self::Aarch64];
}
#[derive(Debug, Clone)]
pub enum Layout {
Qwerty = 0,
Azerty = 1,
Expand All @@ -117,9 +93,6 @@ impl From<u8> for Layout {
}
}
}
impl TargetArch {
pub const ALL: [Self; 2] = [Self::X86_64, Self::Aarch64];
}

#[derive(Deserialize, Debug)]
pub struct KeyMap {
Expand Down
Loading

0 comments on commit babe1c7

Please sign in to comment.