mirror of
https://github.com/apognu/tuigreet.git
synced 2024-09-11 07:25:29 +03:00
Removed a few useless clone().
This commit is contained in:
parent
59c4fa4cfe
commit
dd56f3fb7a
@ -204,18 +204,18 @@ impl Greeter {
|
|||||||
// If we should remember the last logged-in user.
|
// If we should remember the last logged-in user.
|
||||||
if greeter.remember {
|
if greeter.remember {
|
||||||
if let Some(username) = get_last_user_username() {
|
if let Some(username) = get_last_user_username() {
|
||||||
greeter.username = MaskedString::from(username.clone(), get_last_user_name());
|
greeter.username = MaskedString::from(username, get_last_user_name());
|
||||||
|
|
||||||
// If, on top of that, we should remember their last session.
|
// If, on top of that, we should remember their last session.
|
||||||
if greeter.remember_user_session {
|
if greeter.remember_user_session {
|
||||||
if let Ok(ref session_path) = get_last_user_session_path(&username) {
|
if let Ok(ref session_path) = get_last_user_session_path(greeter.username.get()) {
|
||||||
// Set the selected menu option and the session source.
|
// Set the selected menu option and the session source.
|
||||||
greeter.sessions.selected = greeter.sessions.options.iter().position(|Session { path, .. }| path.as_deref() == Some(session_path)).unwrap_or(0);
|
greeter.sessions.selected = greeter.sessions.options.iter().position(|Session { path, .. }| path.as_deref() == Some(session_path)).unwrap_or(0);
|
||||||
greeter.session_source = SessionSource::Session(greeter.sessions.selected);
|
greeter.session_source = SessionSource::Session(greeter.sessions.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if we have the last free-form command from the user.
|
// See if we have the last free-form command from the user.
|
||||||
if let Ok(command) = get_last_user_session(&username) {
|
if let Ok(command) = get_last_user_session(greeter.username.get()) {
|
||||||
greeter.session_source = SessionSource::Command(command);
|
greeter.session_source = SessionSource::Command(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ pub fn get_last_user_name() -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_last_username(username: &MaskedString) {
|
pub fn write_last_username(username: &MaskedString) {
|
||||||
let _ = fs::write(LAST_USER_USERNAME, username.value.clone());
|
let _ = fs::write(LAST_USER_USERNAME, &username.value);
|
||||||
|
|
||||||
if let Some(ref name) = username.mask {
|
if let Some(ref name) = username.mask {
|
||||||
let _ = fs::write(LAST_USER_NAME, name);
|
let _ = fs::write(LAST_USER_NAME, name);
|
||||||
|
@ -44,7 +44,7 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box<dyn
|
|||||||
|
|
||||||
let command_label_text = prompt_value(theme, Some(fl!("new_command")));
|
let command_label_text = prompt_value(theme, Some(fl!("new_command")));
|
||||||
let command_label = Paragraph::new(command_label_text).style(theme.of(&[Themed::Prompt]));
|
let command_label = Paragraph::new(command_label_text).style(theme.of(&[Themed::Prompt]));
|
||||||
let command_value_text = Span::from(greeter.buffer.clone());
|
let command_value_text = Span::from(&greeter.buffer);
|
||||||
let command_value = Paragraph::new(command_value_text).style(theme.of(&[Themed::Input]));
|
let command_value = Paragraph::new(command_value_text).style(theme.of(&[Themed::Input]));
|
||||||
|
|
||||||
f.render_widget(command_label, chunks[0]);
|
f.render_widget(command_label, chunks[0]);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::error::Error;
|
use std::{borrow::Cow, error::Error};
|
||||||
|
|
||||||
use tui::{
|
use tui::{
|
||||||
prelude::Rect,
|
prelude::Rect,
|
||||||
@ -18,7 +18,7 @@ use crate::{
|
|||||||
use super::style::Themed;
|
use super::style::Themed;
|
||||||
|
|
||||||
pub trait MenuItem {
|
pub trait MenuItem {
|
||||||
fn format(&self) -> String;
|
fn format(&self) -> Cow<'_, str>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crate::{power::PowerOption, ui::common::menu::MenuItem};
|
use crate::{power::PowerOption, ui::common::menu::MenuItem};
|
||||||
|
|
||||||
#[derive(SmartDefault, Clone)]
|
#[derive(SmartDefault, Clone)]
|
||||||
@ -8,7 +10,7 @@ pub struct Power {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MenuItem for Power {
|
impl MenuItem for Power {
|
||||||
fn format(&self) -> String {
|
fn format(&self) -> Cow<'_, str> {
|
||||||
self.label.clone()
|
Cow::Borrowed(&self.label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::Greeter;
|
use crate::Greeter;
|
||||||
|
|
||||||
@ -86,8 +89,8 @@ pub struct Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MenuItem for Session {
|
impl MenuItem for Session {
|
||||||
fn format(&self) -> String {
|
fn format(&self) -> Cow<'_, str> {
|
||||||
self.name.clone()
|
Cow::Borrowed(&self.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use super::common::menu::MenuItem;
|
use super::common::menu::MenuItem;
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
@ -7,10 +9,10 @@ pub struct User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MenuItem for User {
|
impl MenuItem for User {
|
||||||
fn format(&self) -> String {
|
fn format(&self) -> Cow<'_, str> {
|
||||||
match &self.name {
|
match &self.name {
|
||||||
Some(name) => format!("{name} ({})", self.username),
|
Some(name) => Cow::Owned(format!("{name} ({})", self.username)),
|
||||||
None => self.username.clone(),
|
None => Cow::Borrowed(&self.username),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user