-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: item display * refactor: <🍔> move config to bin pkg feat: <🍋> support multiple list picker 1. inquire is supported for now. 2. fzf to be implemented. * feat: added item formatter * feat: add fzf picker --------- Co-authored-by: Towry Wang <towry@users.noreply.github.com>
- Loading branch information
Showing
18 changed files
with
346 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mod cli; | ||
mod prompts; | ||
mod config; | ||
|
||
use cli::*; | ||
use npmpink_tui::shell::shell; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// |package_name|source_dir_tail|source_id| | ||
#[derive(Clone)] | ||
pub struct PackageItemDisplay { | ||
pub title: String, | ||
pub source_label: String, | ||
pub source_id: String, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct SourceItemDisplay { | ||
pub title: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::item_display::PackageItemDisplay; | ||
use crate::package::Package; | ||
use crate::source::Source; | ||
use std::rc::Rc; | ||
|
||
struct SourceItemFormatter {} | ||
|
||
#[derive(Clone)] | ||
pub struct PackageItemFormatter<'a> { | ||
pub inner: Rc<Package>, | ||
pub source: &'a Source, | ||
} | ||
|
||
impl<'a> PackageItemFormatter<'a> { | ||
pub fn new(package: Rc<Package>, source: &'a Source) -> PackageItemFormatter<'a> { | ||
PackageItemFormatter { | ||
inner: package, | ||
source, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> From<PackageItemFormatter<'a>> for PackageItemDisplay { | ||
fn from(val: PackageItemFormatter<'a>) -> Self { | ||
PackageItemDisplay { | ||
title: val.inner.name.clone(), | ||
source_label: source_label(val.source).unwrap_or("<unkown source>".to_owned()), | ||
source_id: source_id(val.source).unwrap_or("<unkown source id>".to_owned()), | ||
} | ||
} | ||
} | ||
|
||
fn source_label(source: &Source) -> Option<String> { | ||
source | ||
.path | ||
.to_owned() | ||
.file_stem() | ||
.and_then(|p| p.to_os_string().into_string().ok()) | ||
} | ||
|
||
fn source_id(source: &Source) -> Option<String> { | ||
Some(source.id.clone()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod config; | ||
pub mod item_display; | ||
pub mod item_formatter; | ||
pub mod lockfile; | ||
pub mod ops; | ||
pub mod package; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![allow(dead_code)] | ||
|
||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::BTreeMap; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use anstyle::{AnsiColor, Style}; | ||
use std::fmt; | ||
|
||
use npmpink_core::{ | ||
item_display::PackageItemDisplay as PackageItemDisplayInner, | ||
item_formatter::PackageItemFormatter, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct PackageItemDisplay<'a> { | ||
pub inner: PackageItemDisplayInner, | ||
pub raw: PackageItemFormatter<'a>, | ||
} | ||
|
||
impl<'a> PackageItemDisplay<'a> { | ||
pub fn new(formatter: PackageItemFormatter<'a>) -> PackageItemDisplay { | ||
PackageItemDisplay { | ||
inner: formatter.clone().into(), | ||
raw: formatter, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> fmt::Display for PackageItemDisplay<'a> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let source_label_style = Style::new().fg_color(Some(AnsiColor::Blue.into())).bold(); | ||
|
||
// TODO: apply style here | ||
write!( | ||
f, | ||
"{} {source_label_style}{}{source_label_style:#}", | ||
self.inner.title, self.inner.source_label | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod color; | ||
pub mod item; | ||
mod run; | ||
pub mod select; | ||
pub mod shell; |
Oops, something went wrong.