Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Jul 4, 2024
1 parent 86522ab commit cc659a9
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 410 deletions.
6 changes: 3 additions & 3 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use termwiz::escape::{
parser::Parser,
Action, ControlCode,
};
use tui::style::{Color, Modifier, Style};
use tui::text::{Span,Text};
use tui::prelude::Line;
use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Text};

/// Converts ANSI-escaped strings to tui-rs compatible text
pub fn bytes_to_text<'a, B: AsRef<[u8]>>(bytes: B) -> Text<'a> {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn bytes_to_text<'a, B: AsRef<[u8]>>(bytes: B) -> Text<'a> {
let rgb_tuple = rgb.to_srgb_u8();
span_style =
span_style.bg(Color::Rgb(rgb_tuple.0, rgb_tuple.1, rgb_tuple.2));
},
}
},
_ => {}
}
Expand Down
288 changes: 151 additions & 137 deletions src/app.rs

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// that can be found in the LICENSE file.

use crossbeam_channel::{Receiver, Sender};
use std::{io, collections::HashMap};
use std::thread;
use std::{collections::HashMap, io};

use crate::common::{DiffMode, OutputMode, logging_result};
use crate::common::{logging_result, DiffMode, OutputMode};
use crate::event::AppEvent;
use crate::exec::{exec_after_command, CommandResult};
use crate::output;
Expand Down Expand Up @@ -93,10 +93,10 @@ impl Batch {
if _exec_return && self.is_beep {
println!("\x07")
}
},
}

// Other event
Ok(_) => {},
Ok(_) => {}

// Error
Err(_) => {}
Expand Down Expand Up @@ -172,7 +172,10 @@ impl Batch {

// print split line
if self.is_color {
println!("\x1b[38;5;240m=====[{:}]=========================\x1b[0m", timestamp_dst);
println!(
"\x1b[38;5;240m=====[{:}]=========================\x1b[0m",
timestamp_dst
);
} else {
println!("=====[{:}]=========================", timestamp_dst);
}
Expand Down Expand Up @@ -228,6 +231,4 @@ impl Batch {
self.logfile = logfile;
self
}


}
54 changes: 37 additions & 17 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

// module
use crossbeam_channel::Sender;
use flate2::{read::GzDecoder, write::GzEncoder};
use std::io::prelude::*;
use std::io::BufReader;
use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex};
use std::thread;
use flate2::{write::GzEncoder, read::GzDecoder};

// local module
use crate::common;
Expand Down Expand Up @@ -93,15 +93,15 @@ impl CommandResult {
}

pub fn set_output(&self, data: Vec<u8>) -> Self {
return self.set_data(data, OutputMode::Output)
return self.set_data(data, OutputMode::Output);
}

pub fn set_stdout(&self, data: Vec<u8>) -> Self {
return self.set_data(data, OutputMode::Stdout)
return self.set_data(data, OutputMode::Stdout);
}

pub fn set_stderr(&self, data: Vec<u8>) -> Self {
return self.set_data(data, OutputMode::Stderr)
return self.set_data(data, OutputMode::Stderr);
}

fn get_data(&self, data_type: OutputMode) -> String {
Expand Down Expand Up @@ -173,7 +173,11 @@ impl ExecuteCommand {
let command_str = self.command.clone().join(" ");

// create exec_commands...
let exec_commands = create_exec_cmd_args(self.is_exec,self.shell_command.clone(),command_str.clone());
let exec_commands = create_exec_cmd_args(
self.is_exec,
self.shell_command.clone(),
command_str.clone(),
);

// exec command...
let length = exec_commands.len();
Expand Down Expand Up @@ -214,7 +218,10 @@ impl ExecuteCommand {
// write to vector
stdout.read_to_end(&mut buf).expect("Failed to read stdout");
arc_vec_stdout_clone.lock().unwrap().extend_from_slice(&buf);
arc_vec_output_stdout_clone.lock().unwrap().extend_from_slice(&buf);
arc_vec_output_stdout_clone
.lock()
.unwrap()
.extend_from_slice(&buf);
});

// start stderr thread
Expand All @@ -226,17 +233,29 @@ impl ExecuteCommand {
// write to vector
stderr.read_to_end(&mut buf).expect("Failed to read stderr");
arc_vec_stderr_clone.lock().unwrap().extend_from_slice(&buf);
arc_vec_output_stderr_clone.lock().unwrap().extend_from_slice(&buf);
arc_vec_output_stderr_clone
.lock()
.unwrap()
.extend_from_slice(&buf);
});

// with thread stdout/stderr
stdout_thread.join().expect("Failed to join stdout thread");
stderr_thread.join().expect("Failed to join stderr thread");

// Unwrap Arc, get MutexGuard and extract vector
vec_output = Arc::try_unwrap(arc_vec_output).unwrap().into_inner().unwrap();
vec_stdout = Arc::try_unwrap(arc_vec_stdout).unwrap().into_inner().unwrap();
vec_stderr = Arc::try_unwrap(arc_vec_stderr).unwrap().into_inner().unwrap();
vec_output = Arc::try_unwrap(arc_vec_output)
.unwrap()
.into_inner()
.unwrap();
vec_stdout = Arc::try_unwrap(arc_vec_stdout)
.unwrap()
.into_inner()
.unwrap();
vec_stderr = Arc::try_unwrap(arc_vec_stderr)
.unwrap()
.into_inner()
.unwrap();

// get command status
let exit_status = child.wait().expect("");
Expand Down Expand Up @@ -281,7 +300,12 @@ pub struct ExecuteAfterResultData {
pub after_result: CommandResultData,
}

pub fn exec_after_command(shell_command: String, after_command: String, before: CommandResult, after: CommandResult) {
pub fn exec_after_command(
shell_command: String,
after_command: String,
before: CommandResult,
after: CommandResult,
) {
let before_result: CommandResultData = before.export_data();
let after_result = after.export_data();

Expand Down Expand Up @@ -330,11 +354,8 @@ fn create_exec_cmd_args(is_exec: bool, shell_command: String, command: String) -
for shell_command_arg in shell_command_args {
let exec_cmd_arg: String;
if shell_command_arg.contains("{COMMAND}") {
exec_cmd_arg = str::replace(
&shell_command_arg,
crate::SHELL_COMMAND_EXECCMD,
&command,
);
exec_cmd_arg =
str::replace(&shell_command_arg, crate::SHELL_COMMAND_EXECCMD, &command);
is_shellcmd_template = true;
} else {
exec_cmd_arg = shell_command_arg;
Expand All @@ -352,7 +373,6 @@ fn create_exec_cmd_args(is_exec: bool, shell_command: String, command: String) -
}

exec_commands

}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use ratatui::style::Stylize;
use tui::{
layout::Rect,
style::{Color, Style},
prelude::Line,
widgets::{Block, Borders, BorderType, Clear, Paragraph, Wrap},
style::{Color, Style},
widgets::{Block, BorderType, Borders, Clear, Paragraph, Wrap},
Frame,
};

Expand Down
3 changes: 1 addition & 2 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
// TODO: 幅調整系の数字をconstにする(生数字で雑計算だとわけわからん)

use tui::{
prelude::Line,
style::{Color, Modifier, Style},
text::Span,

widgets::Paragraph,
Frame,
prelude::Line,
};

// local module
Expand Down
48 changes: 17 additions & 31 deletions src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use ratatui::text::Span;
use tui::{
layout::Rect,
style::{Color, Style},
prelude::Line,
style::{Color, Style},
widgets::{Block, Borders, Clear, Paragraph, Wrap},
Frame,
};

use crate::keymap::{get_input_action_description, InputAction, Keymap};
use crate::common::centered_rect;
use crate::keymap::{get_input_action_description, InputAction, Keymap};

pub struct KeyData {
pub key: String,
Expand Down Expand Up @@ -97,7 +97,8 @@ impl<'a> HelpWindow<'a> {
pub fn page_down(&mut self) {
let height: u16 = self.area.height - 2; // top/bottom border = 2
if self.lines > height as i16 {
self.position = std::cmp::min(self.position + height as i16, self.lines - height as i16);
self.position =
std::cmp::min(self.position + height as i16, self.lines - height as i16);
}
}

Expand All @@ -111,41 +112,22 @@ impl<'a> HelpWindow<'a> {
self.position = self.lines - height as i16;
}
}


}

fn gen_help_text_from_key_data<'a>(data: Vec<KeyData>) -> Vec<Line<'a>> {
let mut text = vec![];

for key_data in data {
let line1 = Line::from(vec![
Span::styled(
" - [",
Style::default().fg(Color::LightGreen),
),
Span::styled(
key_data.key,
Style::default().fg(Color::Yellow),
),
Span::styled(
"] key :",
Style::default().fg(Color::LightGreen),
)
]
);
Span::styled(" - [", Style::default().fg(Color::LightGreen)),
Span::styled(key_data.key, Style::default().fg(Color::Yellow)),
Span::styled("] key :", Style::default().fg(Color::LightGreen)),
]);

let line2 = Line::from(vec![
Span::styled(
" ",
Style::default(),
),
Span::styled(
key_data.description,
Style::default().fg(Color::White),
),
]
);
Span::styled(" ", Style::default()),
Span::styled(key_data.description, Style::default().fg(Color::White)),
]);

text.push(line1);
text.push(line2);
Expand All @@ -162,8 +144,12 @@ fn gen_help_text<'a>(keymap: Keymap) -> Vec<Line<'a>> {
let key = input_event_content.input.to_str();
let description = get_input_action_description(input_event_content.action);

keydata_list.push(KeyData { key: key, description: description, action: input_event_content.action});
};
keydata_list.push(KeyData {
key: key,
description: description,
action: input_event_content.action,
});
}

// sort
keydata_list.sort_by(|a, b| a.action.cmp(&b.action));
Expand Down
Loading

0 comments on commit cc659a9

Please sign in to comment.