pager: don't scroll down for non-log

+ some code moved around in TextEditor
This commit is contained in:
Juerd Waalboer 2022-11-01 04:48:49 +01:00
parent a18ef9939a
commit 4613a14a9f
2 changed files with 45 additions and 37 deletions

View file

@ -114,48 +114,51 @@ sub _editor($title, $origdata, $readonly = 0) {
-wrapping => 0, -wrapping => 0,
-hscrollbar => 0, -hscrollbar => 0,
-vscrollbar => 0, -vscrollbar => 0,
-pos => ($readonly ? length($origdata) : 0), -pos => ($readonly == 2 ? length($origdata) : 0),
#-readonly => !!$readonly # does not support -pos #-readonly => !!$readonly # does not support -pos
); );
my $return; my $return;
my @keys = ( if ($readonly) {
[ Curses::KEY_HOME() => 'cursor-scrlinestart' ], $editor->readonly(1); # must be before bindings
[ Curses::KEY_END() => 'cursor-scrlineend' ], $editor->set_binding(sub { $cui->mainloopExit }, "q") if $readonly;
[ "\cK" => 'delete-line' ], # nano (can't do meta/alt for M-m) } else {
[ "\cU" => 'paste' ], # nano my @keys = (
[ "\c[" => sub { } ], [ Curses::KEY_HOME() => 'cursor-scrlinestart' ],
[ "\cL" => sub { $cui->draw } ], [ Curses::KEY_END() => 'cursor-scrlineend' ],
[ "\c^" => sub { $editor->pos(0) } ], [ "\cK" => 'delete-line' ], # nano (can't do meta/alt for M-m)
[ "\c_" => sub { $editor->pos(length($editor->get)) } ], [ "\cU" => 'paste' ], # nano
[ "\cI" => sub { $editor->add_string(" " x ($tab - ($editor->{-xpos} % $tab))) } ], [ "\c[" => sub { } ],
[ "\cS" => sub { $cui->dialog("Enable flow control :)") } ], [ "\cL" => sub { $cui->draw } ],
[ "\cQ" => sub {} ], [ "\c^" => sub { $editor->pos(0) } ],
[ "\cC" => sub { $editor->{-pastebuffer} = $editor->getline_at_ypos($editor->{-ypos}) } ], [ "\c_" => sub { $editor->pos(length($editor->get)) } ],
[ "\cF" => sub { _find($win) } ], [ "\cI" => sub { $editor->add_string(" " x ($tab - ($editor->{-xpos} % $tab))) } ],
[ "\cX" => sub { [ "\cS" => sub { $cui->dialog("Enable flow control :)") } ],
if ($editor->get ne $origdata) { [ "\cQ" => sub {} ],
my $answer = $cui->dialog( [ "\cC" => sub { $editor->{-pastebuffer} = $editor->getline_at_ypos($editor->{-ypos}) } ],
-message => "Save changes?", [ "\cF" => sub { _find($win) } ],
-buttons => [ [ "\cX" => sub {
{ -label => "[Save]", -value => 1 }, if ($editor->get ne $origdata) {
{ -label => "[Discard]", -value => 0 }, my $answer = $cui->dialog(
{ -label => "[Cancel]", -value => -1 }, -message => "Save changes?",
], -buttons => [
-values => [ 1, 0 ], { -label => "[Save]", -value => 1 },
); { -label => "[Discard]", -value => 0 },
$return = $editor->get if $answer == 1; { -label => "[Cancel]", -value => -1 },
$cui->mainloopExit if $answer >= 0; ],
} else { -values => [ 1, 0 ],
$cui->mainloopExit; );
} $return = $editor->get if $answer == 1;
} ], $cui->mainloopExit if $answer >= 0;
); } else {
$cui->mainloopExit;
}
} ],
);
$editor->readonly(1) if $readonly; # must be before bindings $editor->set_binding(reverse @$_) for @keys;
$editor->set_binding(reverse @$_) for @keys; }
$editor->set_binding(sub { $cui->mainloopExit }, "q") if $readonly;
$editor->focus(); $editor->focus();
$cui->mainloop; $cui->mainloop;
@ -187,4 +190,9 @@ sub pager($title, $data) {
_editor($title, $data, 1); _editor($title, $data, 1);
} }
sub logpager($title, $data) {
_require();
_editor($title, $data, 2);
}
1; 1;

View file

@ -66,7 +66,7 @@ sub log_for($self, $cart, $input, @) {
my @lines = _grep($user); my @lines = _grep($user);
require RevBank::TextEditor; require RevBank::TextEditor;
RevBank::TextEditor::pager("RevBank log for $user", join("", @lines, "(end)")); RevBank::TextEditor::logpager("RevBank log for $user", join("", @lines, "(end)"));
return ACCEPT; return ACCEPT;
} }