sgtpep / pmenu

A dynamic terminal-based menu inspired by dmenu written in Python without dependencies with an optional MRU ordering which could also be used as an application launcher and CtrlP alternative.
GNU General Public License v3.0
122 stars 6 forks source link

colorize pmenu #3

Open dalanicolai opened 5 years ago

dalanicolai commented 5 years ago

Would it be possible to implement an option to colorize the menu? So that for example ls --color | pmenu would be rendered in color. Or alternatively maybe an option to colorize the menu with grc and grcat could be implemented?

The colorcodes from ls --color are passed to the input_items: print(input_items) after the input_items assignment returns colored output. However the function: result = redirect_stdio(lambda: curses_wrapper(main)) somehow results in colorless output

sgtpep commented 5 years ago

Hi @dalanicolai! I've looked into whether it's possible to bypass some pre-existing escape sequences (like colors) to curses in python, but looks like there's no easy way to output test with them in curses. For instance: https://stackoverflow.com/questions/27464023/how-to-use-ansi-escape-codes-inside-mvwprintw-in-ncurses/27475218#27475218. If I understand it right, for that we need to parse escape sequences out and then emulate their effects using primitives and attributes from curses. It makes this solution not portable and error-prone.

sgtpep commented 5 years ago

Maybe there're some alternatives but I'm not sure. Judging by this issue fzf supports it with --ansi option. PathPicker maybe, too.