refactor: reuse shortcut sanitizer and scrollbar styling
This commit is contained in:
1 parent
7e7e5c0c31
commit
22a3eebe78
8 files changed
+25
-87
No files matched your search
@@ -225,7 +225,7 @@ fn quote_windows_arg(value: &str) -> String {
|
||||
quoted
|
||||
}
|
||||
|
||||
fn sanitize(name: &str) -> String {
|
||||
pub(crate) fn sanitize(name: &str) -> String {
|
||||
name.chars()
|
||||
.map(|c| {
|
||||
if c.is_alphanumeric() || c == '-' || c == '_' {
|
||||
|
||||
+2
-15
@@ -126,7 +126,7 @@ fn rewrite_linux_desktop_entries(_data_dir: &Path, _instances_dir: &Path) {
|
||||
};
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name();
|
||||
let sanitized = sanitize(&name.to_string_lossy());
|
||||
let sanitized = crate::instance::desktop::sanitize(&name.to_string_lossy());
|
||||
let old = apps_dir.join(format!("mcl-{sanitized}.desktop"));
|
||||
let new = apps_dir.join(format!("rmcl-{sanitized}.desktop"));
|
||||
if old.exists()
|
||||
@@ -159,7 +159,7 @@ fn rewrite_native_desktop_shortcuts(_desktop_dir: &Path, _instances_dir: &Path)
|
||||
let display = entry.file_name().to_string_lossy().into_owned();
|
||||
// mcl named shortcut files with the sanitized form of the
|
||||
// instance name ("My Pack" -> "My_Pack"), so look those up.
|
||||
let sanitized = sanitize(&display);
|
||||
let sanitized = crate::instance::desktop::sanitize(&display);
|
||||
let path = _desktop_dir.join(format!("Minecraft - {sanitized}.{ext}"));
|
||||
if !path.exists() {
|
||||
continue;
|
||||
@@ -174,19 +174,6 @@ fn rewrite_native_desktop_shortcuts(_desktop_dir: &Path, _instances_dir: &Path)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn sanitize(name: &str) -> String {
|
||||
name.chars()
|
||||
.map(|c| {
|
||||
if c.is_alphanumeric() || c == '-' || c == '_' {
|
||||
c
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/migrate.rs"]
|
||||
mod tests;
|
||||
+2
-12
@@ -221,7 +221,7 @@ impl App {
|
||||
layout::{Alignment, Margin},
|
||||
style::{Modifier, Style},
|
||||
text::Line,
|
||||
widgets::{Block, Clear, Paragraph, Scrollbar, ScrollbarOrientation},
|
||||
widgets::{Block, Clear, Paragraph},
|
||||
};
|
||||
|
||||
let theme = THEME.as_ref();
|
||||
@@ -298,17 +298,7 @@ impl App {
|
||||
height: overlay.height.saturating_sub(2),
|
||||
};
|
||||
frame.render_stateful_widget(
|
||||
Scrollbar::default()
|
||||
.orientation(ScrollbarOrientation::VerticalRight)
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
.track_symbol(Some(""))
|
||||
.end_symbol(Some("\u{25bc}")),
|
||||
widgets::scrollbar(theme.text_dim()),
|
||||
scrollbar_area,
|
||||
&mut self.log_overlay_scrollbar,
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span, Text},
|
||||
widgets::{Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
|
||||
widgets::{Paragraph, ScrollbarState},
|
||||
};
|
||||
use ratatui_image::{CropOptions, Resize, StatefulImage, protocol::StatefulProtocol};
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
@@ -2439,17 +2439,7 @@ pub fn render(
|
||||
height: list_area.height.saturating_sub(2),
|
||||
};
|
||||
frame.render_stateful_widget(
|
||||
Scrollbar::default()
|
||||
.orientation(ScrollbarOrientation::VerticalRight)
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
.track_symbol(Some(""))
|
||||
.end_symbol(Some("\u{25bc}")),
|
||||
crate::tui::widgets::scrollbar(theme.text_dim()),
|
||||
scrollbar_area,
|
||||
&mut state.scrollbar_state,
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span, Text},
|
||||
widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState},
|
||||
widgets::{Block, Borders, ScrollbarState},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, LazyLock, Mutex};
|
||||
@@ -384,17 +384,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
frame.render_stateful_widget(list, area, &mut state.list_state);
|
||||
|
||||
frame.render_stateful_widget(
|
||||
Scrollbar::default()
|
||||
.orientation(ScrollbarOrientation::VerticalRight)
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
.track_symbol(Some(""))
|
||||
.end_symbol(Some("\u{25bc}")),
|
||||
super::scrollbar(theme.text_dim()),
|
||||
scrollbar_area,
|
||||
&mut state.scrollbar_state,
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@ use ratatui::{
|
||||
layout::{Constraint, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
|
||||
widgets::{Block, Borders, Paragraph, ScrollbarState},
|
||||
};
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
@@ -550,17 +550,7 @@ fn render_list(frame: &mut Frame, area: Rect, state: &mut LogsState, is_focused:
|
||||
height: inner.height.saturating_sub(2),
|
||||
};
|
||||
frame.render_stateful_widget(
|
||||
Scrollbar::default()
|
||||
.orientation(ScrollbarOrientation::VerticalRight)
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
.track_symbol(Some(""))
|
||||
.end_symbol(Some("\u{25bc}")),
|
||||
super::scrollbar(theme.accent()),
|
||||
scrollbar_area,
|
||||
&mut state.scrollbar_state,
|
||||
);
|
||||
@@ -639,17 +629,7 @@ fn render_viewer(
|
||||
height: area.height.saturating_sub(2),
|
||||
};
|
||||
frame.render_stateful_widget(
|
||||
Scrollbar::default()
|
||||
.orientation(ScrollbarOrientation::VerticalRight)
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
.track_symbol(Some(""))
|
||||
.end_symbol(Some("\u{25bc}")),
|
||||
super::scrollbar(theme.accent()),
|
||||
scrollbar_area,
|
||||
&mut state.viewer_scrollbar_state,
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ use crossterm::event::KeyEvent;
|
||||
use ratatui::{
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Scrollbar, ScrollbarOrientation},
|
||||
};
|
||||
|
||||
pub mod account;
|
||||
@@ -47,6 +48,16 @@ pub(crate) fn status_badge(label: impl Into<String>, color: Color) -> Span<'stat
|
||||
Span::styled(format!(" {} ", label.into()), status_badge_style(color))
|
||||
}
|
||||
|
||||
pub(crate) fn scrollbar(color: Color) -> Scrollbar<'static> {
|
||||
Scrollbar::default()
|
||||
.orientation(ScrollbarOrientation::VerticalRight)
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(Style::default().fg(color).add_modifier(Modifier::BOLD))
|
||||
.thumb_symbol("\u{2551}")
|
||||
.track_symbol(Some(""))
|
||||
.end_symbol(Some("\u{25bc}"))
|
||||
}
|
||||
|
||||
pub trait WidgetKey {
|
||||
fn handle_key(&mut self, key_event: &KeyEvent);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ use ratatui::{
|
||||
layout::{Constraint, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::Span,
|
||||
widgets::{Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
|
||||
widgets::{Paragraph, ScrollbarState},
|
||||
};
|
||||
use ratatui_image::{Resize, StatefulImage, protocol::StatefulProtocol};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
@@ -445,17 +445,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
|
||||
height: area.height.saturating_sub(2),
|
||||
};
|
||||
frame.render_stateful_widget(
|
||||
Scrollbar::default()
|
||||
.orientation(ScrollbarOrientation::VerticalRight)
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
.track_symbol(Some(""))
|
||||
.end_symbol(Some("\u{25bc}")),
|
||||
super::scrollbar(theme.text_dim()),
|
||||
scrollbar_area,
|
||||
&mut state.scrollbar_state,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user