Skip to content

Commit

Permalink
use key <kbd>i</kbd> to pop up information screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
laixintao committed Oct 20, 2023
1 parent f168702 commit 56eca3d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
15 changes: 14 additions & 1 deletion flameshow/render/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from textual.widgets import Footer, Static, Tabs, Tab

from flameshow import __version__
from flameshow.render.framedetail import FrameDetail
from flameshow.render.framedetail import FrameDetail, InformaionScreen
from flameshow.render.header import FlameshowHeader
from flameshow.render.tabs import SampleTabs

Expand Down Expand Up @@ -58,6 +58,7 @@ class FlameshowApp(App):
),
Binding("ctrl+c,q", "quit", "Quit", show=True, key_display="Q"),
Binding("o", "debug"),
Binding("i", "information_screen", "Toggle view stack", show=True),
]

DEFAULT_CSS = """
Expand Down Expand Up @@ -125,6 +126,7 @@ def __init__(
frame=self.root_stack,
sample_index=self.sample_index,
)
self.show_information_screen = False

def on_mount(self):
logger.info("mounted")
Expand Down Expand Up @@ -228,3 +230,14 @@ def handle_sample_type_changed(self, event: Tabs.TabActivated):
logger.info("Tab changed: %s", event)
chosen_index = event.tab.id.split("-")[1]
self.sample_index = int(chosen_index)

def action_information_screen(self):
if self.show_information_screen:
self.pop_screen()
else:
self.push_screen(
InformaionScreen(
self.view_frame, self.sample_index, self.sample_unit
)
)
self.show_information_screen = not self.show_information_screen
32 changes: 31 additions & 1 deletion flameshow/render/framedetail.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from textual.containers import Vertical, VerticalScroll
from textual.css.query import NoMatches
from textual.reactive import reactive
from textual.screen import Screen
from textual.widget import Widget
from textual.widgets import Static
from textual.widgets import Footer, Static

from flameshow.models import Frame
from flameshow.render.header import FlameshowHeader
from flameshow.utils import sizeof

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -392,3 +394,31 @@ def watch_frame(self, new_frame):
def watch_sample_index(self, new_sample_index):
logger.info("sample index changed to: %s", new_sample_index)
self._rerender()


class InformaionScreen(Screen):
def __init__(
self, frame, sample_index, sample_unit, *args, **kwargs
) -> None:
super().__init__(*args, **kwargs)
self.frame = frame
self.sample_index = sample_index
self.sample_unit = sample_unit

def compose(self):
center_text = "Stack detail information"
yield FlameshowHeader(center_text)
content, height = self.frame.render_detail(
self.sample_index, self.sample_unit
)
span_detail = Static(
content,
id="span-detail",
)
span_detail.styles.height = height
span_stack_container = VerticalScroll(
span_detail, id="span-stack-container"
)
span_stack_container.border_title = self.frame.render_title()
yield span_stack_container
yield Footer()

0 comments on commit 56eca3d

Please sign in to comment.