Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI Checks and Reports Update
name: CI Checks

on:
pull_request:
Expand All @@ -12,7 +12,7 @@ on:

jobs:
run-tests:
name: Run Tests and Generate Reports
name: Run Tests
runs-on: ubuntu-latest

steps:
Expand Down
8 changes: 6 additions & 2 deletions src/term_desktop/aceofbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ class ProcessType(enum.Enum):

class ProcessContext(TypedDict, total=True):
"""
'Children' that are spawned by a process will always have the
follow attributes passed in to them as part of their context.
'Children' that are spawned by a process should always have the
following attributes passed in to them as part of their context.

This allows things like main content widgets, content screens, or shell
sessions to 1) have access to all services directly through
self properties, and 2) access their own unique process identifiers
that is used to track them in the system, if they need to do so.

Remember that that process "children" here refers to things spawned
by the process, but not the process itself (ie an app process
needs to spawn its own Textual widget).
"""

process_type: ProcessType
Expand Down
91 changes: 91 additions & 0 deletions src/term_desktop/apps/syslogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
syslogs.py
"""

# Python imports
from __future__ import annotations

# from typing import Any, Type
# import os
# import sys
# import platform

# Textual imports
from textual.app import ComposeResult
from textual.widgets import RichLog # , Static

# Unused Textual imports (for reference):
# from textual import events, on
# from textual.message import Message
# from textual.binding import Binding

# Textual library imports
from textual_window.window import WindowStylesDict

# Local imports
from term_desktop.app_sdk import (
TDEAppBase,
TDEMainWidget,
LaunchMode,
CustomWindowSettings,
)


class SysLogsMeta(TDEAppBase):

APP_NAME = "System Logs"
APP_ID = "syslogs"
ICON = "📝"
DESCRIPTION = "View system logs."
APP_AUTHOR = "TDE Team"

def launch_mode(self) -> LaunchMode:
"""Returns the launch mode for the app. \n

Must return one of the `LaunchMode` enum values.
"""
return LaunchMode.WINDOW # or FULLSCREEN, or DAEMON

def get_main_content(self) -> type[TDEMainWidget] | None:
"""Returns the class definiton for the main content widget for the app. \n
Must return a definition of a Widget subclass, not an instance of it.

If the TDEapp is a normal app (runs in a window or full screen), this must return
the main content Widget for your app. If the TDEapp is a daemon, this method must
return None.
"""
return SysLogsWidget

def custom_window_settings(self) -> CustomWindowSettings:
"""Returns the settings for the window to be created. \n

This is not part of the contract and not necessary to implement.
This method can be optionally implemented to provide custom window settings.
"""
return {
# This returns an empty dictionary when not overridden.
# see CustomWindowSettings for more options
}

def window_styles(self) -> WindowStylesDict:

return {
"width": 60, #
"height": 30, #
# "max_width": None, # default is 'size of the parent container'
# "max_height": None, # default is 'size of the parent container'
# "min_width": 12, #
# "min_height": 6, #
}


class SysLogsWidget(TDEMainWidget):

# DEFAULT_CSS = """
# #title { border: solid $primary; }
# #content { width: auto; height: auto; }
# """

def compose(self) -> ComposeResult:

yield RichLog(id="log_viewer")
93 changes: 91 additions & 2 deletions src/term_desktop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

# python standard library imports
from __future__ import annotations
from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING, Literal, Any
import sys
import inspect

# from time import time
import logging

if TYPE_CHECKING:
from textual.app import ComposeResult
Expand All @@ -12,7 +16,7 @@
# from textual.await_complete import AwaitComplete

# Textual imports
from textual import on
from textual import LogGroup, LogVerbosity, on # type: ignore
from textual.app import App
from textual.css.query import NoMatches

Expand All @@ -32,6 +36,39 @@
# from term_desktop.app_sdk.appbase import TDEApp


#################
# Logging Setup #
#################


logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

file_handler = logging.FileHandler("app.log")
file_handler.setLevel(logging.INFO)

# Create console handler (optional - for both file and console output)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)

# Create formatter
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")

# Add formatter to handlers
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)

# Add handlers to logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)

logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")


class TermDesktop(App[None]):

TITLE = "Term-Desktop"
Expand All @@ -48,6 +85,7 @@ def compose(self) -> ComposeResult:
def on_mount(self) -> None:

self.services.start_all_services()
self.log()

@on(ServicesManager.ServicesStarted)
def all_services_started(self) -> None:
Expand Down Expand Up @@ -117,6 +155,57 @@ def install_screen(self, screen: Screen, name: str) -> None: # type: ignore
"Use the screen service to push screens instead."
)

#! Override
def _log(
self,
group: LogGroup,
verbosity: LogVerbosity,
_textual_calling_frame: inspect.Traceback,
*objects: Any,
**kwargs: Any,
) -> None:

devtools = self.devtools
if devtools is None or not devtools.is_connected:
return

if verbosity.value > LogVerbosity.NORMAL.value and not devtools.verbose:
return

try:
from textual_dev.client import DevtoolsLog

if len(objects) == 1 and not kwargs:
#! modified next 3 lines
log_msg_obj = DevtoolsLog(objects, caller=_textual_calling_frame)
devtools.log(
log_msg_obj,
group,
verbosity,
)
else:
output = " ".join(str(arg) for arg in objects)
if kwargs:
key_values = " ".join(f"{key}={value!r}" for key, value in kwargs.items())
output = f"{output} {key_values}" if output else key_values
#! modified next 3 lines
log_msg_obj = DevtoolsLog(objects, caller=_textual_calling_frame)
devtools.log(
log_msg_obj,
group,
verbosity,
)
except Exception as error:
self._handle_exception(error)
# else:
# log_payload = {
# "group": group.value,
# "verbosity": verbosity.value,
# "timestamp": int(time()),
# "path": getattr(log_msg_obj.caller, "filename", ""),
# "line_number": getattr(log_msg_obj.caller, "lineno", 0),
# }

def action_log_debug_readout(self) -> None:

self.log.debug(Rule("Debug Readout"))
Expand Down
Loading