Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansi option being ignored on the library #311

Closed
mpasa opened this issue Apr 29, 2020 · 1 comment
Closed

Ansi option being ignored on the library #311

mpasa opened this issue Apr 29, 2020 · 1 comment

Comments

@mpasa
Copy link

mpasa commented Apr 29, 2020

It seems the ansi option using Skim as a library is being ignored.

How to reproduce

Create a new cargo project

cargo new skim_ansi

Add skim and ansi_term as libraries. The last one will be used to produce a colored string.

Cargo.toml

[package]
name = "skim_ansi"
version = "0.1.0"
edition = "2018"

[dependencies]
skim = "0.8.1"
ansi_term = "0.12"

Run skim as stated in the documentation, with a colored string generated by ansi_term.

src/main.rs

use skim::prelude::*;
use std::io::Cursor;
use ansi_term::Colour::Red;

fn main() {
    // Skim options, ansi is being activated
    let options = SkimOptionsBuilder::default()
        .height(Some("90%"))
        .ansi(true)
        .build()
        .unwrap();

    // Input line. We use ansi_term to produce a red string
    let input = Red.paint("A red string").to_string();

    let item_reader = SkimItemReader::default();
    let items = item_reader.of_bufread(Cursor::new(input));

    let selected_items = Skim::run_with(&options, Some(items))
        .map(|out| out.selected_items)
        .unwrap_or_else(|| Vec::new());

    for item in selected_items.iter() {
        print!("{}{}", item.output(), "\n");
    }
}

Expected behaviour

  • The string should be colored while in the skim window
  • The result should also be colored

Actual behaviour

  • The string is not colored in the skim window. It appears as ?[31mA red string?[0m.
  • The result is colored correctly.

image

@lotabout
Copy link
Collaborator

lotabout commented Oct 5, 2020

Same issue as #300 , should be addressed in master branch.

ansi option now belongs to SkimItemReader and is removed from SkimOptions.

@lotabout lotabout closed this as completed Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants