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

Export image with current shell's theme #2

Open
fdncred opened this issue Dec 3, 2023 · 10 comments · Fixed by #6
Open

Export image with current shell's theme #2

fdncred opened this issue Dec 3, 2023 · 10 comments · Fixed by #6
Assignees
Labels
enhancement New feature or request

Comments

@fdncred
Copy link
Contributor

fdncred commented Dec 3, 2023

This is from to png
image
This is from ls in the terminal
image

You'll notice other problems between these images too. to png looks good but it's not quite right. It's really noticeable on the header and footer labels as well as the row indexes.

@FMotalleb
Copy link
Owner

will fix colors after patching the ansi parser

@FMotalleb FMotalleb added the enhancement New feature or request label Dec 4, 2023
@FMotalleb FMotalleb self-assigned this Dec 4, 2023
@FMotalleb
Copy link
Owner

FMotalleb commented Dec 4, 2023

added a new feature and flag --theme (-t) with two options (currently), vscode(default) and xterm
maybe ill add custom configuration

@FMotalleb
Copy link
Owner

samples:

Vscode:
vs

Xterm:
xterm

@FMotalleb
Copy link
Owner

The improved functionality now includes compatibility with a variety of themes such as “vscode,” “xterm,” “ubuntu,” “eclipse,” “mirc,” “putty,” “winxp,” “terminal,” “win10,” and “win_power-shell.” Additionally, there’s flexibility to personalize each color within any chosen theme. This is achieved by using the custom-theme- prefix followed by the color name (for example, fg, bg, white, etc.). The custom-defined colors will take precedence, replacing the default colors of the selected theme.

@FMotalleb FMotalleb linked a pull request Dec 4, 2023 that will close this issue
@fdncred
Copy link
Contributor Author

fdncred commented Dec 4, 2023

I'm not really sure what the point of a theme is. I just want it to look like my screen. I'll try it out in a little while.

@FMotalleb
Copy link
Owner

I get your point; however, since the plugins API doesn’t grant me the capability to get your existing shell theme, this method allows you to customize the output to your preference.

@fdncred
Copy link
Contributor Author

fdncred commented Dec 4, 2023

I understand now. I do think there's a way to query the terminal and get colors. I've seen it somewhere but maybe not all terminals support it.

@fdncred
Copy link
Contributor Author

fdncred commented Dec 5, 2023

I wrote this little thing tonight. It doesn't work perfectly because someone broke the input command but if you run this custom command and hit enter 16 times, and your terminal supports this query, you'll get an output like this below. At least this is how it works on Wezterm on MacOS.

def get-terminal-colors [] {
    let color_00 = (input $"(ansi -o '4;0;?')(ansi st)" --bytes-until-any "\e\\" -s) 
    let color_01 = (input $"(ansi -o '4;1;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_02 = (input $"(ansi -o '4;2;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_03 = (input $"(ansi -o '4;3;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_04 = (input $"(ansi -o '4;4;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_05 = (input $"(ansi -o '4;5;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_06 = (input $"(ansi -o '4;6;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_07 = (input $"(ansi -o '4;7;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_08 = (input $"(ansi -o '4;8;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_09 = (input $"(ansi -o '4;9;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_10 = (input $"(ansi -o '4;10;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_11 = (input $"(ansi -o '4;11;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_12 = (input $"(ansi -o '4;12;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_13 = (input $"(ansi -o '4;13;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_14 = (input $"(ansi -o '4;14;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_15 = (input $"(ansi -o '4;15;?')(ansi st)" --bytes-until-any "\e\\" -s)
    # goes through 4;255;?
    [
        $color_00
        $color_01
        $color_02
        $color_03
        $color_04
        $color_05
        $color_06
        $color_07
        $color_08
        $color_09
        $color_10
        $color_11
        $color_12
        $color_13
        $color_14
        $color_15
    ] | each {|col|
        let rgb = $col | split row : | get 1 | split row /
        let red = ($rgb | get 0 | str substring 0..2)
        let green = ($rgb | get 1 | str substring 0..2)
        let blue = ($rgb | get 2 | str substring 0..2)

        {
            red: $red
            green: $green
            blue: $blue
            hex: $"#($red)($green)($blue)"
            rgb: $"RGB(char lp)($red | into int -r 16), ($green | into int -r 16), ($blue | into int -r 16)(char rp)"
        }
    }
}

image

@FMotalleb
Copy link
Owner

I'll try to make it work but I don't think i can because of how stdin/out are controlled in nu-plugins

@FMotalleb FMotalleb reopened this Dec 5, 2023
@FMotalleb FMotalleb changed the title green bold not rendering correctly Export png with current shell's theme Dec 5, 2023
@FMotalleb FMotalleb changed the title Export png with current shell's theme Export image with current shell's theme Dec 5, 2023
@fdncred
Copy link
Contributor Author

fdncred commented Dec 6, 2023

I tweaked this conversion a little bit so it's a little more accurate with converting 16bits to 8bits.

def get-terminal-colors [] {
    let color_00 = (input $"(ansi -o '4;0;?')(ansi st)" --bytes-until-any "\e\\" -s) 
    let color_01 = (input $"(ansi -o '4;1;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_02 = (input $"(ansi -o '4;2;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_03 = (input $"(ansi -o '4;3;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_04 = (input $"(ansi -o '4;4;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_05 = (input $"(ansi -o '4;5;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_06 = (input $"(ansi -o '4;6;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_07 = (input $"(ansi -o '4;7;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_08 = (input $"(ansi -o '4;8;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_09 = (input $"(ansi -o '4;9;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_10 = (input $"(ansi -o '4;10;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_11 = (input $"(ansi -o '4;11;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_12 = (input $"(ansi -o '4;12;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_13 = (input $"(ansi -o '4;13;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_14 = (input $"(ansi -o '4;14;?')(ansi st)" --bytes-until-any "\e\\" -s)
    let color_15 = (input $"(ansi -o '4;15;?')(ansi st)" --bytes-until-any "\e\\" -s)
    # goes through 4;255;?
    [
        $color_00 $color_01 $color_02 $color_03
        $color_04 $color_05 $color_06 $color_07
        $color_08 $color_09 $color_10 $color_11
        $color_12 $color_13 $color_14 $color_15
    ] | each {|col|
        let rgb = $col | split row : | get 1 | split row /

        # 16bit rgb to 8bit =  0xe7e7 | bits and 0x00ff
        let red = ($"0x($rgb | get 0)" | into int | bits and 0x00ff)
        let green = ($"0x($rgb | get 1)" | into int | bits and 0x00ff)
        let blue = ($"0x($rgb | get 2)" | into int | bits and 0x00ff)
        let red_hx = ($red | fmt).lowerhex | str substring 2..
        let green_hx = ($green | fmt).lowerhex | str substring 2..
        let blue_hx = ($blue | fmt).lowerhex | str substring 2..

        {
            red: $red_hx
            green: $green_hx
            blue: $blue_hx
            hex: $"#($red_hx)($green_hx)($blue_hx)"
            rgb: $"RGB(char lp)($red), ($green), ($blue)(char rp)"
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants