lotabout / skim

Fuzzy Finder in rust!
MIT License
5.1k stars 183 forks source link

How to differentiate the items in skim option? #538

Closed xixiaofinland closed 8 months ago

xixiaofinland commented 1 year ago

My original need and implementation

I have a list of items for the user to select in Skim. They are either A type or B type, thus I use a Project struct with a bool field true or false to differentiate them. code here

And I followed this sample.

The problem I encounter

Once the items are passed into rx_item, they are no more Project type but SkimItem, i.e. the bool field is gone. Do I need to cast it back? Why does Skim change the type?

Alternatively, is there an easier way to achieve my goal (i.e. differentiate these two types of items in skim UI)? I considered using String with and without color, but can't figure out how.

xixiaofinland commented 8 months ago

I figured out to use display trait

    fn display<'a>(&'a self, _context: DisplayContext<'a>) -> AnsiString<'a> {
        if self.session_exists {
            return AnsiString::from(format!("*{}", self.folder));
        }
        return AnsiString::from(self.folder.clone());
    }