39
41
" -a, --all display all sections\n".
40
42
" -e, --edit edit your todo file\n".
41
43
" -h, --headers show setion headers\n".
42
" -s, --section=SECTION display this named section\n".
44
" --section=SECTION display this named section\n".
43
45
" --help display this help and exit\n".
44
46
" --version output version information and exit\n";
132
# function to display a line
135
my ( $line, $section ) = @_;
136
state $old_section = '';
138
# detect section change
139
if( $section ne $old_section ) {
140
$old_section = $section;
142
# display section heading
143
if( $display_headers || $display_all ) {
145
( "=" x length( $section ) )."\n";
149
# replace tabs with 4 spaces
130
157
# scan through file
131
my $next_section = '';
158
my $candidate_section = '';
132
159
my $section = '';
133
my $old_section = '';
134
161
open FILE, "<$todo_dir/todo" or die "can't open todo file";
138
164
# detect the line after section headings, and thus sections
139
if( /^[-=]{2,}/ && $next_section ne '' ) {
140
$section = $next_section;
165
if( /^[-=]{2,}/ && $candidate_section ne '' ) {
166
$section = $candidate_section;
167
$candidate_section = '';
143
172
# detect section headings
144
elsif( /^[-_\.A-Za-z0-9 ]+$/ ) {
146
chomp( $next_section );
148
# we have neither a section heading nor the line after
173
if( /^[-_\.A-Za-z0-9 ]+$/ ) {
174
$candidate_section = $_;
175
chomp $candidate_section;
153
if( ( $section eq $display_section ) ||
154
( $section && $display_all ) )
156
# detect section change
157
if( $section ne $old_section ) {
158
$old_section = $section;
160
# display section heading
161
if( $display_headers ||
165
( "=" x length( $section ) )."\n";
169
# replace tabs with 4 spaces
178
$candidate_section = '';
182
display_line( $last_line, $section ) if( $last_line ne '' );
185
if( ( $section eq $display_section ) ||
186
( $section && $display_all ) )
194
display_line( $last_line, $section ) if( $last_line ne '' );