Skip to content

Instantly share code, notes, and snippets.

@worr
Created January 2, 2011 05:56
Show Gist options
  • Select an option

  • Save worr/762331 to your computer and use it in GitHub Desktop.

Select an option

Save worr/762331 to your computer and use it in GitHub Desktop.
Highlights comments in bold in an ncurses interface
#!/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