refactor(tui): rename instances to profiles
This commit is contained in:
1 parent
ad3243cffe
commit
8685fa9800
7 files changed
+93
-128
No files matched your search
Generated
+58
-90
@@ -62,6 +62,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.18"
|
||||
@@ -337,6 +346,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8acebd8ad879283633b343856142139f2da2317c96b05b4dd6181c61e2480184"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -351,6 +361,18 @@ dependencies = [
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.4"
|
||||
@@ -818,7 +840,7 @@ dependencies = [
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core 0.52.0",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -830,18 +852,30 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icy_sixel"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccc0a9c4770bc47b0a933256a496cfb8b6531f753ea9bccb19c6dff0ff7273fc"
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.24.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder",
|
||||
"color_quant",
|
||||
"exr",
|
||||
"gif",
|
||||
"jpeg-decoder",
|
||||
"num-traits",
|
||||
"png",
|
||||
"qoi",
|
||||
"tiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.25.5"
|
||||
@@ -971,6 +1005,9 @@ name = "jpeg-decoder"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
@@ -1093,11 +1130,11 @@ dependencies = [
|
||||
"crossterm",
|
||||
"dirs-next",
|
||||
"fmt",
|
||||
"image",
|
||||
"image 0.25.5",
|
||||
"lazy_static",
|
||||
"once_cell",
|
||||
"rascii_art",
|
||||
"ratatui",
|
||||
"ratatui-image",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
]
|
||||
@@ -1444,6 +1481,18 @@ dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rascii_art"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e27f573a36aab4d4f2dd4aae8f44e8c5409a3d2cefce01d116cb11de546b1c65"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"clap",
|
||||
"image 0.24.9",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ratatui"
|
||||
version = "0.29.0"
|
||||
@@ -1465,23 +1514,6 @@ dependencies = [
|
||||
"unicode-width 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ratatui-image"
|
||||
version = "5.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9e2b311a4215ae53a10d57d541c80e103347294650b4d5501a6a3b41ecd8dff"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"icy_sixel",
|
||||
"image",
|
||||
"rand",
|
||||
"ratatui",
|
||||
"rustix",
|
||||
"serde",
|
||||
"thiserror 1.0.69",
|
||||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rav1e"
|
||||
version = "0.7.1"
|
||||
@@ -2145,16 +2177,6 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6"
|
||||
dependencies = [
|
||||
"windows-core 0.58.0",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
@@ -2164,60 +2186,6 @@ dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10"
|
||||
dependencies = [
|
||||
"windows-result",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
|
||||
+1
-1
@@ -16,8 +16,8 @@ serde_derive = "1.0.217"
|
||||
lazy_static = "1.5.0"
|
||||
colored = "3.0.0"
|
||||
chrono = "0.4.39"
|
||||
ratatui-image = { version = "5.0.0", features = ["crossterm", "serde"]}
|
||||
image = "0.25.5"
|
||||
fmt = "0.1.0"
|
||||
once_cell = "1.20.3"
|
||||
rascii_art = "0.4.5"
|
||||
|
||||
+3
-3
@@ -9,13 +9,13 @@ use crate::debug;
|
||||
|
||||
pub mod types;
|
||||
|
||||
fn get_config_path() -> PathBuf {
|
||||
pub fn get_config_path() -> PathBuf {
|
||||
let base_dir = config_dir().unwrap();
|
||||
base_dir.join("mcl/config.toml")
|
||||
base_dir.join("mcl/")
|
||||
}
|
||||
|
||||
fn ensure_config_exists(default_path: &str) -> PathBuf {
|
||||
let config_path = get_config_path();
|
||||
let config_path = get_config_path().join("config.toml");
|
||||
|
||||
if !config_path.exists() {
|
||||
if let Some(parent_dir) = config_path.parent() {
|
||||
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
use super::{widgets::{self, instances, WidgetKey}, Tui};
|
||||
use super::{widgets::{self, profiles, WidgetKey}, Tui};
|
||||
use color_eyre::eyre::Context;
|
||||
use crossterm::event::{self, Event};
|
||||
use ratatui::{
|
||||
@@ -11,12 +11,12 @@ use ratatui::{
|
||||
pub struct App {
|
||||
exit: bool,
|
||||
focused: FocusedArea,
|
||||
instances_state: instances::State,
|
||||
profiles_state: profiles::State,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum FocusedArea {
|
||||
Instances,
|
||||
Profiles,
|
||||
Content,
|
||||
Account,
|
||||
Details,
|
||||
@@ -25,7 +25,7 @@ pub enum FocusedArea {
|
||||
|
||||
impl Default for FocusedArea {
|
||||
fn default() -> Self {
|
||||
FocusedArea::Instances
|
||||
FocusedArea::Profiles
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ impl App {
|
||||
|
||||
|
||||
// Render Instances
|
||||
widgets::instances::render(frame, chunks[0], self.focused, &mut self.instances_state);
|
||||
widgets::profiles::render(frame, chunks[0], self.focused, &mut self.profiles_state);
|
||||
|
||||
|
||||
// Divide the main content into vertical chunks
|
||||
@@ -97,7 +97,7 @@ impl App {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) -> color_eyre::Result<()> {
|
||||
match key_event.code {
|
||||
KeyCode::Char('q') => self.exit = true,
|
||||
KeyCode::Char('I') => self.focused = FocusedArea::Instances,
|
||||
KeyCode::Char('P') => self.focused = FocusedArea::Profiles,
|
||||
KeyCode::Char('C') => self.focused = FocusedArea::Content,
|
||||
KeyCode::Char('A') => self.focused = FocusedArea::Account,
|
||||
KeyCode::Char('D') => self.focused = FocusedArea::Details,
|
||||
@@ -106,7 +106,7 @@ impl App {
|
||||
}
|
||||
|
||||
match self.focused {
|
||||
FocusedArea::Instances => self.instances_state.handle_key(&key_event),
|
||||
FocusedArea::Profiles => self.profiles_state.handle_key(&key_event),
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
pub mod layout;
|
||||
pub mod widgets;
|
||||
pub mod picture;
|
||||
|
||||
use std::io::{stdout, Result, Stdout};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use ratatui::{
|
||||
pub mod account;
|
||||
pub mod content;
|
||||
pub mod details;
|
||||
pub mod instances;
|
||||
pub mod profiles;
|
||||
pub mod status;
|
||||
|
||||
pub fn styled_title(title: &str, highlight: bool) -> Line {
|
||||
|
||||
@@ -4,11 +4,10 @@ use ratatui::{
|
||||
style::{Modifier, Style},
|
||||
text::Text,
|
||||
widgets::{
|
||||
Block, BorderType, Borders, Cell, Paragraph, Row, Scrollbar, ScrollbarOrientation, ScrollbarState, Table, TableState
|
||||
Block, BorderType, Borders, Cell, Row, Scrollbar, ScrollbarOrientation, ScrollbarState, Table, TableState
|
||||
},
|
||||
Frame,
|
||||
};
|
||||
use ratatui_image::StatefulImage;
|
||||
|
||||
use crate::{config::SETTINGS, tui::layout::FocusedArea};
|
||||
|
||||
@@ -16,35 +15,34 @@ use super::{styled_title, WidgetKey};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct State {
|
||||
pub instances: Vec<Data>,
|
||||
pub profiles: Vec<Data>,
|
||||
pub table_state: TableState,
|
||||
pub scrollbar_state: ScrollbarState,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Data {
|
||||
pub title: String,
|
||||
pub id: String,
|
||||
pub running: bool,
|
||||
pub img: Option<StatefulImage>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Data {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Data")
|
||||
.field("title", &self.title)
|
||||
.field("id", &self.id)
|
||||
.field("running", &self.running)
|
||||
.field("img", &"<StatefulImage>")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
// impl std::fmt::Debug for Data {
|
||||
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// f.debug_struct("Data")
|
||||
// .field("title", &self.title)
|
||||
// .field("id", &self.id)
|
||||
// .field("running", &self.running)
|
||||
// .field("img", &"<StatefulImage>")
|
||||
// .finish()
|
||||
// }
|
||||
// }
|
||||
|
||||
impl State {
|
||||
fn next(&mut self) {
|
||||
let i = match self.table_state.selected() {
|
||||
Some(i) => {
|
||||
if i >= self.instances.len().saturating_sub(1) {
|
||||
if i >= self.profiles.len().saturating_sub(1) {
|
||||
0
|
||||
} else {
|
||||
i + 1
|
||||
@@ -60,7 +58,7 @@ impl State {
|
||||
let i = match self.table_state.selected() {
|
||||
Some(i) => {
|
||||
if i == 0 {
|
||||
self.instances.len().saturating_sub(1)
|
||||
self.profiles.len().saturating_sub(1)
|
||||
} else {
|
||||
i - 1
|
||||
}
|
||||
@@ -72,10 +70,10 @@ impl State {
|
||||
}
|
||||
|
||||
fn update_scrollbar(&mut self) {
|
||||
let items = self.instances.len().saturating_sub(1);
|
||||
let items = self.profiles.len().saturating_sub(1);
|
||||
let index = self.table_state.selected().unwrap_or(0);
|
||||
|
||||
if self.instances.is_empty() {
|
||||
if self.profiles.is_empty() {
|
||||
self.table_state.select(None);
|
||||
} else if self.table_state.selected().is_none() {
|
||||
self.table_state.select(Some(0));
|
||||
@@ -91,16 +89,15 @@ impl WidgetKey for State {
|
||||
fn handle_key(&mut self, key_event: &crossterm::event::KeyEvent) {
|
||||
match key_event.code {
|
||||
KeyCode::Char('a') => {
|
||||
self.instances.push(Data {
|
||||
self.profiles.push(Data {
|
||||
title: "Test".to_string(),
|
||||
id: "123".to_string(),
|
||||
running: false,
|
||||
img: Some(StatefulImage::default()),
|
||||
});
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Char('d') => {
|
||||
self.instances.clear();
|
||||
self.profiles.clear();
|
||||
self.update_scrollbar();
|
||||
}
|
||||
KeyCode::Char('j') | KeyCode::Down => self.next(),
|
||||
@@ -111,14 +108,14 @@ impl WidgetKey for State {
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut State) {
|
||||
let color = if focused == FocusedArea::Instances {
|
||||
let color = if focused == FocusedArea::Profiles {
|
||||
SETTINGS.colors.border_focused
|
||||
} else {
|
||||
SETTINGS.colors.border_unfocused
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.title(styled_title("Instances", true))
|
||||
.title(styled_title("Profiles", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(color));
|
||||
@@ -134,7 +131,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
|
||||
let table_area = block.inner(area);
|
||||
|
||||
let rows = state.instances.iter().enumerate().map(|(i, data)| {
|
||||
let rows = state.profiles.iter().enumerate().map(|(i, data)| {
|
||||
let status = if data.running { "Running" } else { "Stopped" };
|
||||
|
||||
let background_color = if i % 2 == 0 {
|
||||
@@ -143,6 +140,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
SETTINGS.colors.row_alternate_bg
|
||||
};
|
||||
|
||||
|
||||
Row::new(vec![
|
||||
Cell::from(Text::from(format!("\n{}\n", data.title))),
|
||||
Cell::from(Text::from(format!("\n{}\n", data.id))),
|
||||
Reference in new issue
Block a user