Created
January 2, 2011 05:56
-
-
Save worr/762331 to your computer and use it in GitHub Desktop.
Highlights comments in bold in an ncurses interface
This file contains hidden or 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
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use 5.010; | |
| use Curses; | |
| # Use the name of this program if no file is passed in | |
| my $filename = $ARGV[0] // "comment_hili.pl"; | |
| open (my $fh, "<", $filename); # we use lexical filehandles since they have scope | |
| my $win = Curses->new; # Make a new ncurses window and call initscr on it | |
| foreach (<$fh>) { | |
| # when uses the smart match operator against the topic var to decide when to enter clauses | |
| when (/#.*/) { | |
| $win->addstr(substr($_, 0, $-[0])); | |
| $win->attron(A_BOLD); | |
| $win->addstr(substr($_, $-[0], $+[0] - $-[0] + 1)); | |
| $win->attroff(A_BOLD); | |
| } | |
| default { | |
| $win->addstr($_); | |
| } | |
| } | |
| $win->refresh; | |
| $win->getch; # wait for user input | |
| endwin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment