chore: Rust 2024 edition

This commit is contained in:
Vukašin Vojinović 2025-09-10 14:33:46 +02:00 • committed by Jeremy Soller
parent 3c654040b2
commit 58b8da4310
9 changed files with 53 additions and 49 deletions

View file

@ -2,9 +2,9 @@
name = "cosmic-term" name = "cosmic-term"
version = "0.1.0" version = "0.1.0"
authors = ["Jeremy Soller <jeremy@system76.com>"] authors = ["Jeremy Soller <jeremy@system76.com>"]
edition = "2021" edition = "2024"
license = "GPL-3.0-only" license = "GPL-3.0-only"
rust-version = "1.80" rust-version = "1.85"
[build-dependencies] [build-dependencies]
vergen = { version = "8", features = ["git", "gitcl"] } vergen = { version = "8", features = ["git", "gitcl"] }

View file

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use cosmic::{ use cosmic::{
cosmic_config::{self, cosmic_config_derive::CosmicConfigEntry, CosmicConfigEntry}, cosmic_config::{self, CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry},
theme, theme,
}; };
use cosmic_text::{Metrics, Stretch, Weight}; use cosmic_text::{Metrics, Stretch, Weight};

View file

@ -3,8 +3,8 @@
use std::{str::FromStr, sync::LazyLock}; use std::{str::FromStr, sync::LazyLock};
use i18n_embed::{ use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader},
DefaultLocalizer, LanguageLoader, Localizer, DefaultLocalizer, LanguageLoader, Localizer,
fluent::{FluentLanguageLoader, fluent_language_loader},
}; };
use icu_collator::{Collator, CollatorOptions, Numeric}; use icu_collator::{Collator, CollatorOptions, Numeric};
use icu_provider::DataLocale; use icu_provider::DataLocale;

View file

@ -4,30 +4,29 @@
use alacritty_terminal::tty::Options; use alacritty_terminal::tty::Options;
use alacritty_terminal::{event::Event as TermEvent, term, term::color::Colors as TermColors, tty}; use alacritty_terminal::{event::Event as TermEvent, term, term::color::Colors as TermColors, tty};
use cosmic::iced::clipboard::dnd::DndAction; use cosmic::iced::clipboard::dnd::DndAction;
use cosmic::widget::DndDestination;
use cosmic::widget::menu::action::MenuAction; use cosmic::widget::menu::action::MenuAction;
use cosmic::widget::menu::key_bind::KeyBind; use cosmic::widget::menu::key_bind::KeyBind;
use cosmic::widget::DndDestination;
use cosmic::{ use cosmic::{
action, Application, ApplicationExt, Element, action,
app::{context_drawer, Core, Settings, Task}, app::{Core, Settings, Task, context_drawer},
cosmic_config::{self, ConfigSet, CosmicConfigEntry}, cosmic_config::{self, ConfigSet, CosmicConfigEntry},
cosmic_theme, executor, cosmic_theme, executor,
iced::{ iced::{
self, self, Alignment, Color, Event, Length, Limits, Padding, Point, Subscription,
advanced::graphics::text::font_system, advanced::graphics::text::font_system,
clipboard, event, clipboard, event,
futures::SinkExt, futures::SinkExt,
keyboard::{Event as KeyEvent, Key, Modifiers}, keyboard::{Event as KeyEvent, Key, Modifiers},
mouse::{Button as MouseButton, Event as MouseEvent}, mouse::{Button as MouseButton, Event as MouseEvent},
stream, window, Alignment, Color, Event, Length, Limits, Padding, Point, Subscription, stream, window,
}, },
style, style,
widget::{self, button, pane_grid, segmented_button, PaneGrid}, widget::{self, PaneGrid, button, pane_grid, segmented_button},
Application, ApplicationExt, Element,
}; };
use cosmic::{surface, Apply}; use cosmic::{Apply, surface};
use cosmic_files::dialog::{Dialog, DialogKind, DialogMessage, DialogResult, DialogSettings}; use cosmic_files::dialog::{Dialog, DialogKind, DialogMessage, DialogResult, DialogSettings};
use cosmic_text::{fontdb::FaceInfo, Family, Stretch, Weight}; use cosmic_text::{Family, Stretch, Weight, fontdb::FaceInfo};
use localize::LANGUAGE_SORTER; use localize::LANGUAGE_SORTER;
use std::{ use std::{
any::TypeId, any::TypeId,
@ -37,13 +36,13 @@ use std::{
error::Error, error::Error,
fs, process, fs, process,
rc::Rc, rc::Rc,
sync::{atomic::Ordering, LazyLock, Mutex}, sync::{LazyLock, Mutex, atomic::Ordering},
}; };
use tokio::sync::mpsc; use tokio::sync::mpsc;
use config::{ use config::{
AppTheme, ColorScheme, ColorSchemeId, ColorSchemeKind, Config, Profile, ProfileId, AppTheme, CONFIG_VERSION, ColorScheme, ColorSchemeId, ColorSchemeKind, Config, Profile,
CONFIG_VERSION, ProfileId,
}; };
mod config; mod config;
mod mouse_reporter; mod mouse_reporter;
@ -174,7 +173,9 @@ fn main() -> Result<(), Box<dyn Error>> {
// Set up environmental variables for terminal // Set up environmental variables for terminal
tty::setup_env(); tty::setup_env();
// Override TERM for better compatibility // Override TERM for better compatibility
env::set_var("TERM", "xterm-256color"); unsafe {
env::set_var("TERM", "xterm-256color");
}
// Set settings // Set settings
let mut settings = Settings::default(); let mut settings = Settings::default();
@ -736,7 +737,7 @@ impl App {
} }
} }
fn about(&self) -> Element<Message> { fn about(&self) -> Element<'_, Message> {
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing; let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
let repository = "https://github.com/pop-os/cosmic-term"; let repository = "https://github.com/pop-os/cosmic-term";
let hash = env!("VERGEN_GIT_SHA"); let hash = env!("VERGEN_GIT_SHA");
@ -768,7 +769,7 @@ impl App {
.into() .into()
} }
fn color_schemes(&self, color_scheme_kind: ColorSchemeKind) -> Element<Message> { fn color_schemes(&self, color_scheme_kind: ColorSchemeKind) -> Element<'_, Message> {
let cosmic_theme::Spacing { space_xxxs, .. } = self.core().system_theme().cosmic().spacing; let cosmic_theme::Spacing { space_xxxs, .. } = self.core().system_theme().cosmic().spacing;
let mut sections = Vec::with_capacity(3 + self.color_scheme_errors.len()); let mut sections = Vec::with_capacity(3 + self.color_scheme_errors.len());
@ -880,7 +881,7 @@ impl App {
widget::settings::view_column(sections).into() widget::settings::view_column(sections).into()
} }
fn profiles(&self) -> Element<Message> { fn profiles(&self) -> Element<'_, Message> {
let cosmic_theme::Spacing { let cosmic_theme::Spacing {
space_s, space_s,
space_xs, space_xs,
@ -1076,7 +1077,7 @@ impl App {
widget::settings::view_column(sections).into() widget::settings::view_column(sections).into()
} }
fn settings(&self) -> Element<Message> { fn settings(&self) -> Element<'_, Message> {
let app_theme_selected = match self.config.app_theme { let app_theme_selected = match self.config.app_theme {
AppTheme::Dark => 1, AppTheme::Dark => 1,
AppTheme::Light => 2, AppTheme::Light => 2,
@ -1482,7 +1483,9 @@ impl Application for App {
}; };
if font_name_faces_map.is_empty() { if font_name_faces_map.is_empty() {
log::error!("at least one monospace font with normal/bold weights and default stretch is required"); log::error!(
"at least one monospace font with normal/bold weights and default stretch is required"
);
log::error!("no monospace fonts to select from, exiting"); log::error!("no monospace fonts to select from, exiting");
process::exit(1); process::exit(1);
} }
@ -2422,10 +2425,10 @@ impl Application for App {
return self.create_and_focus_new_terminal( return self.create_and_focus_new_terminal(
self.pane_model.focused(), self.pane_model.focused(),
self.get_default_profile(), self.get_default_profile(),
) );
} }
Message::TabNewNoProfile => { Message::TabNewNoProfile => {
return self.create_and_focus_new_terminal(self.pane_model.focused(), None) return self.create_and_focus_new_terminal(self.pane_model.focused(), None);
} }
Message::TabNext => { Message::TabNext => {
if let Some(tab_model) = self.pane_model.active() { if let Some(tab_model) = self.pane_model.active() {
@ -2672,7 +2675,7 @@ impl Application for App {
Task::none() Task::none()
} }
fn context_drawer(&self) -> Option<context_drawer::ContextDrawer<Message>> { fn context_drawer(&self) -> Option<context_drawer::ContextDrawer<'_, Message>> {
if !self.core.window.show_context { if !self.core.window.show_context {
return None; return None;
} }
@ -2700,11 +2703,11 @@ impl Application for App {
}) })
} }
fn header_start(&self) -> Vec<Element<Self::Message>> { fn header_start(&self) -> Vec<Element<'_, Self::Message>> {
vec![menu_bar(&self.core, &self.config, &self.key_binds)] vec![menu_bar(&self.core, &self.config, &self.key_binds)]
} }
fn header_end(&self) -> Vec<Element<Self::Message>> { fn header_end(&self) -> Vec<Element<'_, Self::Message>> {
vec![ vec![
widget::button::custom(icon_cache_get("list-add-symbolic", 16)) widget::button::custom(icon_cache_get("list-add-symbolic", 16))
.on_press(Message::TabNew) .on_press(Message::TabNew)
@ -2714,7 +2717,7 @@ impl Application for App {
] ]
} }
fn view_window(&self, window_id: window::Id) -> Element<Message> { fn view_window(&self, window_id: window::Id) -> Element<'_, Message> {
match &self.dialog_opt { match &self.dialog_opt {
Some(dialog) => dialog.view(window_id), Some(dialog) => dialog.view(window_id),
None => widget::text("Unknown window ID").into(), None => widget::text("Unknown window ID").into(),
@ -2722,7 +2725,7 @@ impl Application for App {
} }
/// Creates a view after each update. /// Creates a view after each update.
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<'_, Self::Message> {
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing; let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
let pane_grid = PaneGrid::new(&self.pane_model.panes, |pane, tab_model, _is_maximized| { let pane_grid = PaneGrid::new(&self.pane_model.panes, |pane, tab_model, _is_maximized| {
@ -2870,7 +2873,7 @@ impl Application for App {
fn system_theme_update( fn system_theme_update(
&mut self, &mut self,
_keys: &[&'static str], _keys: &[&'static str],
new_theme: &cosmic::cosmic_theme::Theme, _new_theme: &cosmic::cosmic_theme::Theme,
) -> Task<Self::Message> { ) -> Task<Self::Message> {
self.update(Message::SystemThemeChange) self.update(Message::SystemThemeChange)
} }

View file

@ -1,13 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use cosmic::widget::menu::key_bind::KeyBind; use cosmic::widget::menu::key_bind::KeyBind;
use cosmic::widget::menu::{menu_button, Item as MenuItem}; use cosmic::widget::menu::{Item as MenuItem, menu_button};
use cosmic::{ use cosmic::{
Element,
app::Core, app::Core,
iced::{ iced::{
Background, Length,
advanced::widget::text::Style as TextStyle, advanced::widget::text::Style as TextStyle,
widget::{column, horizontal_space}, widget::{column, horizontal_space},
Background, Length,
}, },
iced_core::Border, iced_core::Border,
theme, theme,
@ -16,11 +17,10 @@ use cosmic::{
menu::{ItemHeight, ItemWidth}, menu::{ItemHeight, ItemWidth},
responsive_menu_bar, segmented_button, responsive_menu_bar, segmented_button,
}, },
Element,
}; };
use std::{collections::HashMap, sync::LazyLock}; use std::{collections::HashMap, sync::LazyLock};
use crate::{fl, Action, ColorSchemeId, ColorSchemeKind, Config, Message}; use crate::{Action, ColorSchemeId, ColorSchemeKind, Config, Message, fl};
static MENU_ID: LazyLock<cosmic::widget::Id> = static MENU_ID: LazyLock<cosmic::widget::Id> =
LazyLock::new(|| cosmic::widget::Id::new("responsive-menu")); LazyLock::new(|| cosmic::widget::Id::new("responsive-menu"));

View file

@ -1,6 +1,6 @@
use cosmic::{ use cosmic::{
iced::mouse::{Event as MouseEvent, ScrollDelta}, iced::mouse::{Event as MouseEvent, ScrollDelta},
iced::{keyboard::Modifiers, mouse::Button, Event}, iced::{Event, keyboard::Modifiers, mouse::Button},
}; };
use crate::terminal::Terminal; use crate::terminal::Terminal;

View file

@ -1,4 +1,5 @@
use alacritty_terminal::{ use alacritty_terminal::{
Term,
event::{Event, EventListener, Notify, OnResize, WindowSize}, event::{Event, EventListener, Notify, OnResize, WindowSize},
event_loop::{EventLoop, Msg, Notifier}, event_loop::{EventLoop, Msg, Notifier},
grid::Dimensions, grid::Dimensions,
@ -6,14 +7,14 @@ use alacritty_terminal::{
selection::{Selection, SelectionType}, selection::{Selection, SelectionType},
sync::FairMutex, sync::FairMutex,
term::{ term::{
Config, TermDamage, TermMode,
cell::Flags, cell::Flags,
color::{self, Colors}, color::{self, Colors},
search::RegexSearch, search::RegexSearch,
viewport_to_point, Config, TermDamage, TermMode, viewport_to_point,
}, },
tty::{self, Options}, tty::{self, Options},
vte::ansi::{Color, CursorShape, NamedColor, Rgb}, vte::ansi::{Color, CursorShape, NamedColor, Rgb},
Term,
}; };
use cosmic::{ use cosmic::{
iced::{advanced::graphics::text::font_system, mouse::ScrollDelta}, iced::{advanced::graphics::text::font_system, mouse::ScrollDelta},
@ -29,8 +30,8 @@ use std::{
collections::HashMap, collections::HashMap,
io, mem, io, mem,
sync::{ sync::{
atomic::{AtomicU32, Ordering},
Arc, Mutex, Weak, Arc, Mutex, Weak,
atomic::{AtomicU32, Ordering},
}, },
time::Instant, time::Instant,
}; };

View file

@ -3,34 +3,34 @@
use alacritty_terminal::{ use alacritty_terminal::{
index::{Column as TermColumn, Point as TermPoint, Side as TermSide}, index::{Column as TermColumn, Point as TermPoint, Side as TermSide},
selection::{Selection, SelectionType}, selection::{Selection, SelectionType},
term::{cell::Flags, TermMode}, term::{TermMode, cell::Flags},
vte::ansi::{CursorShape, NamedColor}, vte::ansi::{CursorShape, NamedColor},
}; };
use cosmic::widget::menu::key_bind::KeyBind; use cosmic::widget::menu::key_bind::KeyBind;
use cosmic::{ use cosmic::{
cosmic_theme::palette::{blend::Compose, WithAlpha}, Renderer,
cosmic_theme::palette::{WithAlpha, blend::Compose},
iced::{ iced::{
Color, Element, Length, Padding, Point, Rectangle, Size, Vector,
advanced::graphics::text::Raw, advanced::graphics::text::Raw,
event::{Event, Status}, event::{Event, Status},
keyboard::{Event as KeyEvent, Key, Modifiers}, keyboard::{Event as KeyEvent, Key, Modifiers},
mouse::{self, Button, Event as MouseEvent, ScrollDelta}, mouse::{self, Button, Event as MouseEvent, ScrollDelta},
Color, Element, Length, Padding, Point, Rectangle, Size, Vector,
}, },
iced_core::{ iced_core::{
Border, Shell,
clipboard::Clipboard, clipboard::Clipboard,
keyboard::key::Named, keyboard::key::Named,
layout::{self, Layout}, layout::{self, Layout},
renderer::{self, Quad, Renderer as _}, renderer::{self, Quad, Renderer as _},
text::Renderer as _, text::Renderer as _,
widget::{ widget::{
self, self, Id, Widget,
operation::{self, Operation}, operation::{self, Operation},
tree, Id, Widget, tree,
}, },
Border, Shell,
}, },
theme::Theme, theme::Theme,
Renderer,
}; };
use cosmic_text::LayoutGlyph; use cosmic_text::LayoutGlyph;
use indexmap::IndexSet; use indexmap::IndexSet;
@ -44,8 +44,8 @@ use std::{
}; };
use crate::{ use crate::{
key_bind::key_binds, mouse_reporter::MouseReporter, terminal::Metadata, Action, Terminal, Action, Terminal, TerminalScroll, key_bind::key_binds, mouse_reporter::MouseReporter,
TerminalScroll, terminal::Metadata,
}; };
pub struct TerminalBox<'a, Message> { pub struct TerminalBox<'a, Message> {

View file

@ -3,11 +3,11 @@ use alacritty_terminal::{
vte::ansi::{NamedColor, Rgb}, vte::ansi::{NamedColor, Rgb},
}; };
use hex_color::HexColor; use hex_color::HexColor;
use palette::{encoding::Srgb, rgb::Rgb as PRgb, FromColor, Okhsl}; use palette::{FromColor, Okhsl, encoding::Srgb, rgb::Rgb as PRgb};
use std::{collections::HashMap, fs}; use std::{collections::HashMap, fs};
use crate::config::{ use crate::config::{
ColorScheme, ColorSchemeAnsi, ColorSchemeKind, COSMIC_THEME_DARK, COSMIC_THEME_LIGHT, COSMIC_THEME_DARK, COSMIC_THEME_LIGHT, ColorScheme, ColorSchemeAnsi, ColorSchemeKind,
}; };
// Fill missing dim/bright colors with derived values from normal ones. // Fill missing dim/bright colors with derived values from normal ones.