Clippy fixes
This commit is contained in:
parent
9a36dc2401
commit
05ee3dca4a
4 changed files with 57 additions and 70 deletions
66
src/main.rs
66
src/main.rs
|
|
@ -118,8 +118,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let startup_options = if let Some(shell_program) = shell_program_opt {
|
let startup_options = if let Some(shell_program) = shell_program_opt {
|
||||||
let mut options = tty::Options::default();
|
let options = tty::Options {
|
||||||
options.shell = Some(tty::Shell::new(shell_program, shell_args));
|
shell: Some(tty::Shell::new(shell_program, shell_args)),
|
||||||
|
..tty::Options::default()
|
||||||
|
};
|
||||||
Some(options)
|
Some(options)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -354,14 +356,13 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_config(&mut self) -> Command<Message> {
|
fn save_config(&mut self) -> Command<Message> {
|
||||||
match self.config_handler {
|
if let Some(ref config_handler) = self.config_handler {
|
||||||
Some(ref config_handler) => match self.config.write_entry(&config_handler) {
|
match self.config.write_entry(config_handler) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("failed to save config: {}", err);
|
log::error!("failed to save config: {}", err);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
self.update_config()
|
self.update_config()
|
||||||
}
|
}
|
||||||
|
|
@ -565,7 +566,7 @@ impl App {
|
||||||
widget::settings::item::builder(fl!("default-font")).control(widget::dropdown(
|
widget::settings::item::builder(fl!("default-font")).control(widget::dropdown(
|
||||||
&self.font_names,
|
&self.font_names,
|
||||||
font_selected,
|
font_selected,
|
||||||
|index| Message::DefaultFont(index),
|
Message::DefaultFont,
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
.add(
|
.add(
|
||||||
|
|
@ -589,7 +590,7 @@ impl App {
|
||||||
widget::dropdown(
|
widget::dropdown(
|
||||||
&self.curr_font_stretch_names,
|
&self.curr_font_stretch_names,
|
||||||
font_stretch_selected,
|
font_stretch_selected,
|
||||||
|index| Message::DefaultFontStretch(index),
|
Message::DefaultFontStretch,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -598,7 +599,7 @@ impl App {
|
||||||
widget::dropdown(
|
widget::dropdown(
|
||||||
&self.curr_font_weight_names,
|
&self.curr_font_weight_names,
|
||||||
font_weight_selected,
|
font_weight_selected,
|
||||||
|index| Message::DefaultFontWeight(index),
|
Message::DefaultFontWeight,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -607,7 +608,7 @@ impl App {
|
||||||
widget::dropdown(
|
widget::dropdown(
|
||||||
&self.curr_font_weight_names,
|
&self.curr_font_weight_names,
|
||||||
dim_font_weight_selected,
|
dim_font_weight_selected,
|
||||||
|index| Message::DefaultDimFontWeight(index),
|
Message::DefaultDimFontWeight,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -616,7 +617,7 @@ impl App {
|
||||||
widget::dropdown(
|
widget::dropdown(
|
||||||
&self.curr_font_weight_names,
|
&self.curr_font_weight_names,
|
||||||
bold_font_weight_selected,
|
bold_font_weight_selected,
|
||||||
|index| Message::DefaultBoldFontWeight(index),
|
Message::DefaultBoldFontWeight,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -751,7 +752,7 @@ impl Application for App {
|
||||||
//TODO: get localized name if possible
|
//TODO: get localized name if possible
|
||||||
let font_name = face
|
let font_name = face
|
||||||
.families
|
.families
|
||||||
.get(0)
|
.first()
|
||||||
.map_or_else(|| face.post_script_name.to_string(), |x| x.0.to_string());
|
.map_or_else(|| face.post_script_name.to_string(), |x| x.0.to_string());
|
||||||
font_name_faces_map
|
font_name_faces_map
|
||||||
.entry(font_name)
|
.entry(font_name)
|
||||||
|
|
@ -827,7 +828,7 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
let themes = terminal_theme::terminal_themes();
|
let themes = terminal_theme::terminal_themes();
|
||||||
let mut theme_names: Vec<_> = themes.keys().map(|x| x.clone()).collect();
|
let mut theme_names: Vec<_> = themes.keys().cloned().collect();
|
||||||
theme_names.sort();
|
theme_names.sort();
|
||||||
let pane_model = TerminalPaneGrid::new(segmented_button::ModelBuilder::default().build());
|
let pane_model = TerminalPaneGrid::new(segmented_button::ModelBuilder::default().build());
|
||||||
let mut terminal_ids = HashMap::new();
|
let mut terminal_ids = HashMap::new();
|
||||||
|
|
@ -1239,17 +1240,14 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
Message::TabContextAction(entity, action) => {
|
Message::TabContextAction(entity, action) => {
|
||||||
if let Some(tab_model) = self.pane_model.active() {
|
if let Some(tab_model) = self.pane_model.active() {
|
||||||
match tab_model.data::<Mutex<Terminal>>(entity) {
|
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||||
Some(terminal) => {
|
// Close context menu
|
||||||
// Close context menu
|
{
|
||||||
{
|
let mut terminal = terminal.lock().unwrap();
|
||||||
let mut terminal = terminal.lock().unwrap();
|
terminal.context_menu = None;
|
||||||
terminal.context_menu = None;
|
|
||||||
}
|
|
||||||
// Run action's message
|
|
||||||
return self.update(action.message(Some(entity)));
|
|
||||||
}
|
}
|
||||||
_ => {}
|
// Run action's message
|
||||||
|
return self.update(action.message(Some(entity)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1258,25 +1256,19 @@ impl Application for App {
|
||||||
let panes: Vec<_> = self.pane_model.panes.iter().collect();
|
let panes: Vec<_> = self.pane_model.panes.iter().collect();
|
||||||
for (_pane, tab_model) in panes {
|
for (_pane, tab_model) in panes {
|
||||||
let entity = tab_model.active();
|
let entity = tab_model.active();
|
||||||
match tab_model.data::<Mutex<Terminal>>(entity) {
|
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||||
Some(terminal) => {
|
let mut terminal = terminal.lock().unwrap();
|
||||||
let mut terminal = terminal.lock().unwrap();
|
terminal.context_menu = None;
|
||||||
terminal.context_menu = None;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the context menu on the correct pane / terminal
|
// Show the context menu on the correct pane / terminal
|
||||||
if let Some(tab_model) = self.pane_model.panes.get(pane) {
|
if let Some(tab_model) = self.pane_model.panes.get(pane) {
|
||||||
let entity = tab_model.active();
|
let entity = tab_model.active();
|
||||||
match tab_model.data::<Mutex<Terminal>>(entity) {
|
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||||
Some(terminal) => {
|
// Update context menu position
|
||||||
// Update context menu position
|
let mut terminal = terminal.lock().unwrap();
|
||||||
let mut terminal = terminal.lock().unwrap();
|
terminal.context_menu = position_opt;
|
||||||
terminal.context_menu = position_opt;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1459,7 +1451,7 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header_start(&self) -> Vec<Element<Self::Message>> {
|
fn header_start(&self) -> Vec<Element<Self::Message>> {
|
||||||
vec![menu_bar(&self.key_binds).into()]
|
vec![menu_bar(&self.key_binds)]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header_end(&self) -> Vec<Element<Self::Message>> {
|
fn header_end(&self) -> Vec<Element<Self::Message>> {
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,7 @@ impl MouseReporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn report_sgr_mouse_wheel_scroll(
|
pub fn report_sgr_mouse_wheel_scroll(
|
||||||
&self,
|
&self,
|
||||||
terminal: &Terminal,
|
terminal: &Terminal,
|
||||||
|
|
|
||||||
|
|
@ -242,12 +242,12 @@ impl Terminal {
|
||||||
|
|
||||||
let (cell_width, cell_height) = {
|
let (cell_width, cell_height) = {
|
||||||
let mut font_system = font_system().write().unwrap();
|
let mut font_system = font_system().write().unwrap();
|
||||||
let mut font_system = font_system.raw();
|
let font_system = font_system.raw();
|
||||||
buffer.set_wrap(&mut font_system, Wrap::None);
|
buffer.set_wrap(font_system, Wrap::None);
|
||||||
|
|
||||||
// Use size of space to determine cell size
|
// Use size of space to determine cell size
|
||||||
buffer.set_text(&mut font_system, " ", default_attrs, Shaping::Advanced);
|
buffer.set_text(font_system, " ", default_attrs, Shaping::Advanced);
|
||||||
let layout = buffer.line_layout(&mut font_system, 0).unwrap();
|
let layout = buffer.line_layout(font_system, 0).unwrap();
|
||||||
let w = layout[0].w;
|
let w = layout[0].w;
|
||||||
buffer.set_monospace_width(font_system, Some(w));
|
buffer.set_monospace_width(font_system, Some(w));
|
||||||
(w, metrics.line_height)
|
(w, metrics.line_height)
|
||||||
|
|
@ -459,7 +459,7 @@ impl Terminal {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find next search match
|
// Find next search match
|
||||||
match term.search_next(
|
if let Some(search_match) = term.search_next(
|
||||||
search_regex,
|
search_regex,
|
||||||
search_origin,
|
search_origin,
|
||||||
if forwards {
|
if forwards {
|
||||||
|
|
@ -471,21 +471,18 @@ impl Terminal {
|
||||||
if forwards { Side::Left } else { Side::Right },
|
if forwards { Side::Left } else { Side::Right },
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
Some(search_match) => {
|
// Scroll to match
|
||||||
// Scroll to match
|
if forwards {
|
||||||
if forwards {
|
term.scroll_to_point(*search_match.end());
|
||||||
term.scroll_to_point(*search_match.end());
|
} else {
|
||||||
} else {
|
term.scroll_to_point(*search_match.start());
|
||||||
term.scroll_to_point(*search_match.start());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set selection to match
|
|
||||||
let mut selection =
|
|
||||||
Selection::new(SelectionType::Simple, *search_match.start(), Side::Left);
|
|
||||||
selection.update(*search_match.end(), Side::Right);
|
|
||||||
term.selection = Some(selection);
|
|
||||||
}
|
}
|
||||||
None => {}
|
|
||||||
|
// Set selection to match
|
||||||
|
let mut selection =
|
||||||
|
Selection::new(SelectionType::Simple, *search_match.start(), Side::Left);
|
||||||
|
selection.update(*search_match.end(), Side::Right);
|
||||||
|
term.selection = Some(selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -561,8 +558,8 @@ impl Terminal {
|
||||||
}
|
}
|
||||||
if changed {
|
if changed {
|
||||||
self.metadata_set.clear();
|
self.metadata_set.clear();
|
||||||
let default_bg = convert_color(&colors, Color::Named(NamedColor::Background));
|
let default_bg = convert_color(colors, Color::Named(NamedColor::Background));
|
||||||
let default_fg = convert_color(&colors, Color::Named(NamedColor::Foreground));
|
let default_fg = convert_color(colors, Color::Named(NamedColor::Foreground));
|
||||||
|
|
||||||
let default_metadata = Metadata::new(default_bg, default_fg);
|
let default_metadata = Metadata::new(default_bg, default_fg);
|
||||||
let (default_metadata_idx, _) = self.metadata_set.insert_full(default_metadata);
|
let (default_metadata_idx, _) = self.metadata_set.insert_full(default_metadata);
|
||||||
|
|
@ -800,6 +797,7 @@ impl Terminal {
|
||||||
) {
|
) {
|
||||||
let term_lock = self.term.lock();
|
let term_lock = self.term.lock();
|
||||||
let mode = term_lock.mode();
|
let mode = term_lock.mode();
|
||||||
|
#[allow(clippy::collapsible_else_if)]
|
||||||
if mode.contains(TermMode::SGR_MOUSE) {
|
if mode.contains(TermMode::SGR_MOUSE) {
|
||||||
if let Some(code) = self.mouse_reporter.sgr_mouse_code(event, modifiers, x, y) {
|
if let Some(code) = self.mouse_reporter.sgr_mouse_code(event, modifiers, x, y) {
|
||||||
self.input_no_scroll(code)
|
self.input_no_scroll(code)
|
||||||
|
|
@ -849,6 +847,6 @@ impl Terminal {
|
||||||
impl Drop for Terminal {
|
impl Drop for Terminal {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Ensure shutdown on terminal drop
|
// Ensure shutdown on terminal drop
|
||||||
let _ = self.notifier.0.send(Msg::Shutdown);
|
self.notifier.0.send(Msg::Shutdown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn terminal_box<'a, Message>(terminal: &'a Mutex<Terminal>) -> TerminalBox<'a, Message>
|
pub fn terminal_box<Message>(terminal: &Mutex<Terminal>) -> TerminalBox<'_, Message>
|
||||||
where
|
where
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
{
|
{
|
||||||
|
|
@ -192,9 +192,8 @@ where
|
||||||
) -> mouse::Interaction {
|
) -> mouse::Interaction {
|
||||||
let state = tree.state.downcast_ref::<State>();
|
let state = tree.state.downcast_ref::<State>();
|
||||||
|
|
||||||
match &state.dragging {
|
if let Some(Dragging::Scrollbar { .. }) = &state.dragging {
|
||||||
Some(Dragging::Scrollbar { .. }) => return mouse::Interaction::Idle,
|
return mouse::Interaction::Idle;
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
||||||
|
|
@ -228,8 +227,7 @@ where
|
||||||
let cosmic_theme = theme.cosmic();
|
let cosmic_theme = theme.cosmic();
|
||||||
let scrollbar_w = cosmic_theme.spacing.space_xxs as f32;
|
let scrollbar_w = cosmic_theme.spacing.space_xxs as f32;
|
||||||
|
|
||||||
let view_position =
|
let view_position = layout.position() + [self.padding.left, self.padding.top].into();
|
||||||
layout.position() + [self.padding.left as f32, self.padding.top as f32].into();
|
|
||||||
let view_w = cmp::min(viewport.width as i32, layout.bounds().width as i32)
|
let view_w = cmp::min(viewport.width as i32, layout.bounds().width as i32)
|
||||||
- self.padding.horizontal() as i32
|
- self.padding.horizontal() as i32
|
||||||
- scrollbar_w as i32;
|
- scrollbar_w as i32;
|
||||||
|
|
@ -455,7 +453,7 @@ where
|
||||||
dot_width = dot_width.min(full_width - accu_width);
|
dot_width = dot_width.min(full_width - accu_width);
|
||||||
|
|
||||||
let dot_bottom_offset = match accu_width as u32 % 8 {
|
let dot_bottom_offset = match accu_width as u32 % 8 {
|
||||||
3 | 4 | 5 => bottom_offset + style_line_height,
|
3..=5 => bottom_offset + style_line_height,
|
||||||
2 | 6 => bottom_offset + 2.0 * style_line_height / 3.0,
|
2 | 6 => bottom_offset + 2.0 * style_line_height / 3.0,
|
||||||
1 | 7 => bottom_offset + 1.0 * style_line_height / 3.0,
|
1 | 7 => bottom_offset + 1.0 * style_line_height / 3.0,
|
||||||
_ => bottom_offset,
|
_ => bottom_offset,
|
||||||
|
|
@ -508,10 +506,7 @@ where
|
||||||
Size::new(scrollbar_w, scrollbar_h),
|
Size::new(scrollbar_w, scrollbar_h),
|
||||||
);
|
);
|
||||||
|
|
||||||
let pressed = match &state.dragging {
|
let pressed = matches!(&state.dragging, Some(Dragging::Scrollbar { .. }));
|
||||||
Some(Dragging::Scrollbar { .. }) => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut hover = false;
|
let mut hover = false;
|
||||||
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
if let Some(p) = cursor_position.position_in(layout.bounds()) {
|
||||||
|
|
@ -1022,6 +1017,7 @@ where
|
||||||
state.is_focused = true;
|
state.is_focused = true;
|
||||||
|
|
||||||
// Handle left click drag
|
// Handle left click drag
|
||||||
|
#[allow(clippy::collapsible_if)]
|
||||||
if let Button::Left = button {
|
if let Button::Left = button {
|
||||||
let x = p.x - self.padding.left;
|
let x = p.x - self.padding.left;
|
||||||
let y = p.y - self.padding.top;
|
let y = p.y - self.padding.top;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue