Skip to content

Commit f42643f

Browse files
committed
now for timestamps, nano for stopwatches
1 parent fcda806 commit f42643f

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

lib/Terminal/Widgets/Scrollable.rakumod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ABSTRACT: Common role for scrollable widgets
22

3+
use nano;
4+
35
use Terminal::Widgets::Events;
46

57

@@ -15,14 +17,14 @@ role Terminal::Widgets::Scrollable {
1517
method refresh-for-scroll(Bool:D :$force = False) {
1618
if $!scrolled || $force {
1719
note "🆕 Starting refresh-for-scroll of: {self.gist-name}" if $.debug;
18-
my $t0 = now;
20+
my $t0 = nano;
1921

2022
.full-refresh for %.scrollbars.keys;
2123
self.full-refresh;
2224
$!scrolled = False;
2325

2426
note sprintf("⏱️ refresh-for-scroll of {self.gist-name}: %.3fms",
25-
1000 * (now - $t0)) if $.debug;
27+
(nano - $t0) / 1_000_000) if $.debug;
2628
}
2729
}
2830

lib/Terminal/Widgets/Terminal.rakumod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ABSTRACT: Pausable event pump for parsed and decoded ANSI terminal events
22

3+
use nano;
4+
35
use Terminal::Print;
46
use Terminal::Capabilities;
57
use Terminal::LineEditor::RawTerminalInput;
@@ -146,7 +148,7 @@ class Terminal::Widgets::Terminal
146148
method resize-toplevel() {
147149
with $.current-toplevel {
148150
note "⚙️ Processing resize-toplevel request" if $!debug;
149-
my $t0 = now;
151+
my $t0 = nano;
150152

151153
my $is-current-grid = .grid === $!terminal-print.current-grid;
152154

@@ -166,7 +168,7 @@ class Terminal::Widgets::Terminal
166168
.relayout(:focus);
167169

168170
note sprintf("⏱️ resize-toplevel request processed: %.3fms\n",
169-
1000 * (now - $t0)) if $!debug;
171+
(nano - $t0) / 1_000_000) if $!debug;
170172
}
171173
}
172174

lib/Terminal/Widgets/TopLevel.rakumod

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ABSTRACT: A top-level (full-screen) widget
22

3+
use nano;
4+
35
use Terminal::Widgets::Events;
46
use Terminal::Widgets::Layout;
57
use Terminal::Widgets::Widget;
@@ -29,12 +31,12 @@ does Terminal::Widgets::Layout::WidgetBuilding {
2931
Terminal::Widgets::Events::EventPhase:D $phase = TrickleDown) {
3032
my $show-time = $.debug && $phase == TrickleDown;
3133
note '⚙️ Processing ' ~ $event.gist if $show-time;
32-
my $t0 = now;
34+
my $t0 = nano;
3335

3436
callsame;
3537

3638
note sprintf("⏱️ Event #%d processed: %.3fms\n",
37-
$event.id, 1000 * (now - $t0)) if $show-time;
39+
$event.id, (nano - $t0) / 1_000_000) if $show-time;
3840
}
3941

4042
#| Add a widget to a named group
@@ -62,7 +64,7 @@ does Terminal::Widgets::Layout::WidgetBuilding {
6264
method focus-on(Terminal::Widgets::Widget:D $target,
6365
Bool:D :$redraw = True) {
6466
note "⚙️ Processing top level focus-on for: {$target.gist-name}" if $.debug;
65-
my $t0 = now;
67+
my $t0 = nano;
6668

6769
# Determine if focus is *really* changing
6870
my $prev = $!focused-widget;
@@ -84,25 +86,25 @@ does Terminal::Widgets::Layout::WidgetBuilding {
8486
$target.full-refresh if $redraw;
8587

8688
note sprintf("⏱️ focus-on processed for {$target.gist-name}: %.3fms\n",
87-
1000 * (now - $t0)) if $.debug;
89+
(nano - $t0) / 1_000_000) if $.debug;
8890
}
8991

9092
#| Redraw entire widget tree
9193
method redraw-all() {
9294
note "🆕 Starting redraw-all of: {self.gist-name}" if $.debug;
93-
my $t0 = now;
95+
my $t0 = nano;
9496

9597
my $frame-info = Terminal::Widgets::FrameInfo.new;
9698
self.do-frame($frame-info);
9799

98100
note sprintf("⏱️ redraw-all of {self.gist-name}: %.3fms",
99-
1000 * (now - $t0)) if $.debug;
101+
(nano - $t0) / 1_000_000) if $.debug;
100102
}
101103

102104
#| Relayout, redraw, and composite entire widget tree
103105
method relayout(Bool:D :$focus = False) {
104106
note '⚙️ Processing top level relayout request' if $.debug;
105-
my $t0 = now;
107+
my $t0 = nano;
106108

107109
# Build the layout and then send a global event that layout has completed
108110
self.build-layout;
@@ -114,7 +116,7 @@ does Terminal::Widgets::Layout::WidgetBuilding {
114116
self.composite;
115117

116118
note sprintf("⏱️ Top level relayout request processed: %.3fms\n",
117-
1000 * (now - $t0)) if $.debug;
119+
(nano - $t0) / 1_000_000) if $.debug;
118120
}
119121

120122
# XXXX: Allow terminal to be disconnected or switched?

lib/Terminal/Widgets/Viewer/Tree.rakumod

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ABSTRACT: A viewer/browser for a Volatile::Tree
22

3+
use nano;
4+
35
use Terminal::Widgets::Layout;
46
use Terminal::Widgets::Events;
57
use Terminal::Widgets::TextContent;
@@ -117,19 +119,19 @@ class Terminal::Widgets::Viewer::Tree
117119
# Auto-cache flattened nodes and displayable lines
118120
method flat-node-cache() {
119121
@!flat-node-cache ||= do {
120-
my $t0 = now;
122+
my $t0 = nano;
121123
self.flattened-nodes($!display-root, my @n);
122124
note sprintf("💲 Refill flattened-nodes: %.3fms (%d elems)",
123-
1000 * (now - $t0), @n.elems) if $.debug;
125+
(nano - $t0) / 1_000_000, @n.elems) if $.debug;
124126
@n
125127
}
126128
}
127129
method flat-line-cache() {
128130
@!flat-line-cache ||= do {
129-
my $t0 = now;
131+
my $t0 = nano;
130132
self.node-lines($!display-root, my @l);
131133
note sprintf("💲 Refill node-lines: %.3fms (%d elems)",
132-
1000 * (now - $t0), @l.elems) if $.debug;
134+
(nano - $t0) / 1_000_000, @l.elems) if $.debug;
133135
@l
134136
}
135137
}
@@ -142,7 +144,7 @@ class Terminal::Widgets::Viewer::Tree
142144
use Text::MiscUtils::Layout;
143145
state %width-cache;
144146

145-
my $t0 = now;
147+
my $t0 = nano;
146148

147149
# XXXX: Sadly at high cardinality this cleaner version still
148150
# leaves too much performance on the table
@@ -155,7 +157,7 @@ class Terminal::Widgets::Viewer::Tree
155157
}).max;
156158

157159
note sprintf("💲 Recalculate max-line-width: %.3fms (%d elems)",
158-
1000 * (now - $t0), @!flat-line-cache.elems) if $.debug;
160+
(nano - $t0) / 1_000_000, @!flat-line-cache.elems) if $.debug;
159161
$max
160162
}
161163
}
@@ -305,14 +307,14 @@ class Terminal::Widgets::Viewer::Tree
305307
#| Perform cache clears and scroll changes needed for changed expanded state
306308
method refresh-for-expand-change() {
307309
note "🆕 Starting refresh-for-expand-change of: {self.gist-name}" if $.debug;
308-
my $t0 = now;
310+
my $t0 = nano;
309311

310312
self.clear-caches;
311313
self.fix-scroll-maxes;
312314
self.refresh-for-scroll(:force);
313315

314316
note sprintf("⏱️ Refresh for expand change of {self.gist-name}: %.3fms",
315-
1000 * (now - $t0)) if $.debug;
317+
(nano - $t0) / 1_000_000) if $.debug;
316318
}
317319

318320
#| Walk up the parents from a given DisplayNode, making sure they are

lib/Terminal/Widgets/Widget.rakumod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ABSTRACT: Wrapper of Terminal::Print::Widget with EventHandling and Animation hooks
22

3+
use nano;
4+
35
use Terminal::Print::Widget;
46
use Terminal::Print::Animated;
57
use Terminal::Print::BoxDrawing;
@@ -273,14 +275,14 @@ class Terminal::Widgets::Widget
273275
#| Fully refresh this widget and optionally force a print
274276
method full-refresh(Bool:D :$print = True) {
275277
note "🆕 Starting full-refresh of: {self.gist-name}" if $!debug;
276-
my $t0 = now;
278+
my $t0 = nano;
277279

278280
self.clear-frame;
279281
self.draw-frame;
280282
self.composite(:$print);
281283

282284
note sprintf("⏱️ full-refresh of {self.gist-name}: %.3fms",
283-
1000 * (now - $t0)) if $!debug;
285+
(nano - $t0) / 1_000_000) if $!debug;
284286
}
285287

286288
#| Clear the frame and set it all-dirty (so it requires composite)

0 commit comments

Comments
 (0)