mirror of
https://github.com/onyx-and-iris/q3rcon-tui.git
synced 2026-02-26 11:09:11 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cac241a910 | |||
| 4606990edb | |||
| 15fd6a1914 | |||
| f59076f0a6 | |||
| 6bf16f5d50 | |||
| ee45bfd03f | |||
| e10bec03ed | |||
| 02ded9fb46 | |||
| fee3678f40 | |||
| ba91b2d8be | |||
| 437b76ab13 | |||
| 004f1d0880 | |||
| 71401c32f9 | |||
| 1cee478197 | |||
| fcc91b7e34 | |||
| 9b3ae629f3 |
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
@ -30,7 +30,7 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install hatch
|
pip install "virtualenv<21" hatch
|
||||||
|
|
||||||
- name: Build package
|
- name: Build package
|
||||||
run: hatch build
|
run: hatch build
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# q3rcon tui
|
# q3rcon tui
|
||||||
|
|
||||||
[](https://github.com/pypa/hatch)
|
[](https://github.com/pypa/hatch)
|
||||||
[](https://github.com/astral-sh/ruff)
|
[](https://github.com/astral-sh/ruff)
|
||||||
[](https://pypi.org/project/q3rcon-tui)
|
[](https://pypi.org/project/q3rcon-tui)
|
||||||
[](https://pypi.org/project/q3rcon-tui)
|
[](https://pypi.org/project/q3rcon-tui)
|
||||||
@ -43,6 +43,8 @@ q3rcon-tui --host=localhost --port=28960 --password=rconpassword
|
|||||||
Additional flags:
|
Additional flags:
|
||||||
|
|
||||||
- `--raw`: Boolean flag, if set the RichLog will print raw responses without rendering tables.
|
- `--raw`: Boolean flag, if set the RichLog will print raw responses without rendering tables.
|
||||||
|
- `--min-status`: Boolean flag, if set the status command will print a minified table.
|
||||||
|
- note, this will have no effect if in *raw* mode.
|
||||||
- `--append`: Boolean flag, if set the RichLog output will append each response continuously.
|
- `--append`: Boolean flag, if set the RichLog output will append each response continuously.
|
||||||
- `--version`: Print the version of the TUI.
|
- `--version`: Print the version of the TUI.
|
||||||
- `--help`: Print the help message.
|
- `--help`: Print the help message.
|
||||||
@ -59,6 +61,7 @@ example .env:
|
|||||||
Q3RCON_TUI_HOST=localhost
|
Q3RCON_TUI_HOST=localhost
|
||||||
Q3RCON_TUI_PORT=28960
|
Q3RCON_TUI_PORT=28960
|
||||||
Q3RCON_TUI_PASSWORD=rconpassword
|
Q3RCON_TUI_PASSWORD=rconpassword
|
||||||
|
Q3RCON_TUI_MIN_STATUS=false
|
||||||
Q3RCON_TUI_RAW=false
|
Q3RCON_TUI_RAW=false
|
||||||
Q3RCON_TUI_APPEND=false
|
Q3RCON_TUI_APPEND=false
|
||||||
```
|
```
|
||||||
|
|||||||
@ -17,6 +17,7 @@ classifiers = [
|
|||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
"Programming Language :: Python :: 3.11",
|
"Programming Language :: Python :: 3.11",
|
||||||
"Programming Language :: Python :: 3.12",
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: 3.13",
|
||||||
"Programming Language :: Python :: Implementation :: CPython",
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
"Programming Language :: Python :: Implementation :: PyPy",
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2026-present onyx-and-iris <code@onyxandiris.online>
|
# SPDX-FileCopyrightText: 2026-present onyx-and-iris <code@onyxandiris.online>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
__version__ = '0.5.0'
|
__version__ = '0.7.1'
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
from pydantic import ValidationError
|
||||||
from textual.app import ComposeResult
|
from textual.app import ComposeResult
|
||||||
from textual.containers import Horizontal, Vertical
|
from textual.containers import Horizontal, Vertical
|
||||||
from textual.screen import ModalScreen
|
from textual.screen import ModalScreen
|
||||||
from textual.widgets import Button, Input, Label, Static
|
from textual.widgets import Button, Input, Label, Static
|
||||||
|
|
||||||
from .settings import settings
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigScreen(ModalScreen[bool]):
|
class ConfigScreen(ModalScreen[bool]):
|
||||||
"""Modal dialog for configuring connection settings."""
|
"""Modal dialog for configuring connection settings."""
|
||||||
|
|
||||||
def __init__(self, current_host: str, current_port: int, current_password: str):
|
def __init__(self, tui):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.current_host = current_host
|
self._settings = tui._settings
|
||||||
self.current_port = current_port
|
self._original_settings = self._settings.model_copy()
|
||||||
self.current_password = current_password
|
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
with Vertical(id='config-dialog'):
|
with Vertical(id='config-dialog'):
|
||||||
@ -21,15 +21,19 @@ class ConfigScreen(ModalScreen[bool]):
|
|||||||
with Vertical(id='config-form'):
|
with Vertical(id='config-form'):
|
||||||
yield Label('Host:')
|
yield Label('Host:')
|
||||||
yield Input(
|
yield Input(
|
||||||
value=self.current_host, placeholder='localhost', id='host-input'
|
value=self._original_settings.host,
|
||||||
|
placeholder='localhost',
|
||||||
|
id='host-input',
|
||||||
)
|
)
|
||||||
yield Label('Port:')
|
yield Label('Port:')
|
||||||
yield Input(
|
yield Input(
|
||||||
value=str(self.current_port), placeholder='28960', id='port-input'
|
value=str(self._original_settings.port),
|
||||||
|
placeholder='28960',
|
||||||
|
id='port-input',
|
||||||
)
|
)
|
||||||
yield Label('Password:')
|
yield Label('Password:')
|
||||||
yield Input(
|
yield Input(
|
||||||
value=self.current_password,
|
value=self._original_settings.password,
|
||||||
placeholder='Enter password',
|
placeholder='Enter password',
|
||||||
password=True,
|
password=True,
|
||||||
id='password-input',
|
id='password-input',
|
||||||
@ -39,26 +43,69 @@ class ConfigScreen(ModalScreen[bool]):
|
|||||||
yield Button('Cancel', variant='error', id='config-cancel')
|
yield Button('Cancel', variant='error', id='config-cancel')
|
||||||
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
if event.button.id == 'config-save':
|
match event.button.id:
|
||||||
|
case 'config-save':
|
||||||
|
self._save_button_handler()
|
||||||
|
case 'config-cancel':
|
||||||
|
self._cancel_button_handler()
|
||||||
|
|
||||||
|
def _save_button_handler(self):
|
||||||
|
self._clear_field_errors()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
new_host = (
|
new_host: str = (
|
||||||
self.query_one('#host-input', Input).value.strip() or 'localhost'
|
self.query_one('#host-input', Input).value.strip() or 'localhost'
|
||||||
)
|
)
|
||||||
new_port = int(self.query_one('#port-input', Input).value or '28960')
|
new_port: int | Literal[28960] = (
|
||||||
new_password = self.query_one('#password-input', Input).value
|
self.query_one('#port-input', Input).value or 28960
|
||||||
|
)
|
||||||
|
new_password: str = self.query_one('#password-input', Input).value
|
||||||
|
|
||||||
if new_port < 1 or new_port > 65535:
|
self._settings.host = new_host
|
||||||
raise ValueError('Port must be between 1 and 65535')
|
self._settings.port = new_port
|
||||||
|
self._settings.password = new_password
|
||||||
if len(new_password) < 8:
|
|
||||||
raise ValueError('Password must be at least 8 characters long')
|
|
||||||
|
|
||||||
settings.host = new_host
|
|
||||||
settings.port = new_port
|
|
||||||
settings.password = new_password
|
|
||||||
|
|
||||||
self.dismiss(True)
|
self.dismiss(True)
|
||||||
except ValueError:
|
except ValidationError as e:
|
||||||
|
for error in e.errors():
|
||||||
|
field_name = error.get('loc', ())
|
||||||
|
error_msg = error.get('msg', str(error))
|
||||||
|
|
||||||
|
match field_name:
|
||||||
|
case ('host',):
|
||||||
|
self._show_field_error('host-input', error_msg)
|
||||||
|
case ('port',):
|
||||||
|
self._show_field_error('port-input', error_msg)
|
||||||
|
case ('password',):
|
||||||
|
self._show_field_error('password-input', error_msg)
|
||||||
|
break # Only show the first error
|
||||||
|
|
||||||
|
def _show_field_error(self, field_id: str, error_message: str):
|
||||||
|
"""Show error message in the specified input field."""
|
||||||
|
self._clear_field_errors()
|
||||||
|
|
||||||
|
field = self.query_one(f'#{field_id}', Input)
|
||||||
|
field.add_class('error')
|
||||||
|
field.value = ''
|
||||||
|
|
||||||
|
field.placeholder = error_message
|
||||||
|
field.focus()
|
||||||
|
|
||||||
self.app.bell()
|
self.app.bell()
|
||||||
elif event.button.id == 'config-cancel':
|
|
||||||
|
def _clear_field_errors(self):
|
||||||
|
"""Clear error styling from all input fields."""
|
||||||
|
for field_id in ['host-input', 'port-input', 'password-input']:
|
||||||
|
field = self.query_one(f'#{field_id}', Input)
|
||||||
|
field.remove_class('error')
|
||||||
|
|
||||||
|
match field_id:
|
||||||
|
case 'host-input':
|
||||||
|
field.placeholder = 'localhost'
|
||||||
|
case 'port-input':
|
||||||
|
field.placeholder = '28960'
|
||||||
|
case 'password-input':
|
||||||
|
field.placeholder = 'Enter password'
|
||||||
|
|
||||||
|
def _cancel_button_handler(self):
|
||||||
self.dismiss(False)
|
self.dismiss(False)
|
||||||
|
|||||||
@ -230,6 +230,29 @@ Button.error:focus {
|
|||||||
background: #434c5e;
|
background: #434c5e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#config-form Input.error {
|
||||||
|
border: solid #bf616a;
|
||||||
|
background: #3c2a2a;
|
||||||
|
color: #d08770;
|
||||||
|
}
|
||||||
|
|
||||||
|
#config-form Input.error:focus {
|
||||||
|
border: solid #d08770;
|
||||||
|
background: #4a2c2c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
height: 0;
|
||||||
|
color: #bf616a;
|
||||||
|
text-style: bold;
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message.visible {
|
||||||
|
height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
#config-buttons {
|
#config-buttons {
|
||||||
height: 3;
|
height: 3;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Annotated, Type
|
from typing import Annotated, Type
|
||||||
|
|
||||||
from loguru import logger
|
from pydantic import (
|
||||||
from pydantic import AfterValidator, BeforeValidator
|
AfterValidator,
|
||||||
|
AliasChoices,
|
||||||
|
BeforeValidator,
|
||||||
|
Field,
|
||||||
|
)
|
||||||
from pydantic_settings import BaseSettings, CliSettingsSource, SettingsConfigDict
|
from pydantic_settings import BaseSettings, CliSettingsSource, SettingsConfigDict
|
||||||
|
|
||||||
from .__about__ import __version__ as version
|
from .__about__ import __version__ as version
|
||||||
@ -15,6 +19,18 @@ def version_callback(value: bool) -> bool | None:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_host(host: str) -> str | None:
|
||||||
|
if not host:
|
||||||
|
raise ValueError('Host cannot be empty')
|
||||||
|
return host
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_port(port: int) -> int | None:
|
||||||
|
if port < 1 or port > 65535:
|
||||||
|
raise ValueError('Port must be between 1 and 65535')
|
||||||
|
return port
|
||||||
|
|
||||||
|
|
||||||
def is_valid_password(password: str) -> str | None:
|
def is_valid_password(password: str) -> str | None:
|
||||||
if len(password) < 8:
|
if len(password) < 8:
|
||||||
raise ValueError('Password must be at least 8 characters long')
|
raise ValueError('Password must be at least 8 characters long')
|
||||||
@ -22,10 +38,18 @@ def is_valid_password(password: str) -> str | None:
|
|||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
host: str = 'localhost'
|
host: Annotated[str, AfterValidator(is_valid_host)] = 'localhost'
|
||||||
port: int = 28960
|
port: Annotated[int, AfterValidator(is_valid_port)] = 28960
|
||||||
password: Annotated[str, AfterValidator(is_valid_password)] = ''
|
password: Annotated[str, AfterValidator(is_valid_password)] = ''
|
||||||
append: bool = False
|
append: bool = False
|
||||||
|
min_status: bool = Field(
|
||||||
|
default=False,
|
||||||
|
alias='min-status',
|
||||||
|
validation_alias=AliasChoices(
|
||||||
|
'min-status',
|
||||||
|
'Q3RCON_TUI_MIN_STATUS',
|
||||||
|
),
|
||||||
|
)
|
||||||
raw: bool = False
|
raw: bool = False
|
||||||
version: Annotated[bool, BeforeValidator(version_callback)] = False
|
version: Annotated[bool, BeforeValidator(version_callback)] = False
|
||||||
|
|
||||||
@ -39,7 +63,7 @@ class Settings(BaseSettings):
|
|||||||
cli_prefix='',
|
cli_prefix='',
|
||||||
cli_parse_args=True,
|
cli_parse_args=True,
|
||||||
cli_implicit_flags=True,
|
cli_implicit_flags=True,
|
||||||
validate_assignment=False,
|
validate_assignment=True,
|
||||||
frozen=False,
|
frozen=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,10 +82,3 @@ class Settings(BaseSettings):
|
|||||||
dotenv_settings,
|
dotenv_settings,
|
||||||
init_settings,
|
init_settings,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
settings = Settings()
|
|
||||||
except ValueError as e:
|
|
||||||
logger.error(e)
|
|
||||||
raise SystemExit(1)
|
|
||||||
|
|||||||
@ -4,16 +4,17 @@ from textual.containers import Grid
|
|||||||
from textual.widgets import Button, Input, RichLog
|
from textual.widgets import Button, Input, RichLog
|
||||||
|
|
||||||
from .configscreen import ConfigScreen
|
from .configscreen import ConfigScreen
|
||||||
from .settings import settings
|
from .settings import Settings
|
||||||
from .writable import Writable
|
from .writable import Writable
|
||||||
|
|
||||||
|
|
||||||
class RconApp(App):
|
class Q3RconTUI(App):
|
||||||
CSS_PATH = 'q3rcon_tui.tcss'
|
CSS_PATH = 'q3rcon_tui.tcss'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.writable = Writable()
|
self._settings = Settings()
|
||||||
|
self.writable = Writable(self)
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Grid(
|
yield Grid(
|
||||||
@ -37,22 +38,26 @@ class RconApp(App):
|
|||||||
self.query_one('#config', Button).press()
|
self.query_one('#config', Button).press()
|
||||||
|
|
||||||
async def on_button_pressed(self, event: Button.Pressed) -> None:
|
async def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
if event.button.id == 'quit':
|
match event.button.id:
|
||||||
|
case 'quit':
|
||||||
|
self._quit_button_handler()
|
||||||
|
case 'config':
|
||||||
|
await self._config_button_handler()
|
||||||
|
case 'send':
|
||||||
|
await self._send_button_handler()
|
||||||
|
|
||||||
|
def _quit_button_handler(self):
|
||||||
self.app.exit()
|
self.app.exit()
|
||||||
elif event.button.id == 'config':
|
|
||||||
result = await self.push_screen(
|
async def _config_button_handler(self):
|
||||||
ConfigScreen(settings.host, settings.port, settings.password)
|
result = await self.push_screen(ConfigScreen(self))
|
||||||
)
|
|
||||||
if result:
|
if result:
|
||||||
self.query_one('#response', RichLog).write(
|
self.query_one('#response', RichLog).write(
|
||||||
f'Configuration updated: {settings.host}:{settings.port}'
|
f'Configuration updated: {self._settings.host}:{self._settings.port}'
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
if event.button.id != 'send':
|
async def _send_button_handler(self):
|
||||||
return
|
if not self._settings.append:
|
||||||
|
|
||||||
if not settings.append:
|
|
||||||
self.query_one('#response', RichLog).clear()
|
self.query_one('#response', RichLog).clear()
|
||||||
|
|
||||||
cmd = self.query_one('#command', Input).value.strip()
|
cmd = self.query_one('#command', Input).value.strip()
|
||||||
@ -62,7 +67,7 @@ class RconApp(App):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
async with Client(
|
async with Client(
|
||||||
settings.host, settings.port, settings.password
|
self._settings.host, self._settings.port, self._settings.password
|
||||||
) as client:
|
) as client:
|
||||||
response = await client.send_command(cmd)
|
response = await client.send_command(cmd)
|
||||||
self.query_one('#response', RichLog).write(
|
self.query_one('#response', RichLog).write(
|
||||||
@ -70,7 +75,7 @@ class RconApp(App):
|
|||||||
)
|
)
|
||||||
except RCONError:
|
except RCONError:
|
||||||
output = (
|
output = (
|
||||||
'Unable to execute command.',
|
f'Unable to execute command {cmd}.',
|
||||||
'It may be due to a map change or a server restart.',
|
'It may be due to a map change or a server restart.',
|
||||||
'If the problem persists, please check your connection settings and ensure the server is running.',
|
'If the problem persists, please check your connection settings and ensure the server is running.',
|
||||||
)
|
)
|
||||||
@ -82,5 +87,5 @@ class RconApp(App):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = RconApp()
|
app = Q3RconTUI()
|
||||||
app.run()
|
app.run()
|
||||||
|
|||||||
@ -3,13 +3,12 @@ import re
|
|||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
from .settings import settings
|
|
||||||
|
|
||||||
Renderable = Text | Table | str
|
Renderable = Text | Table | str
|
||||||
|
|
||||||
|
|
||||||
class Writable:
|
class Writable:
|
||||||
RE_COLOR_CODES = re.compile(r'\^[0-9]')
|
RE_COLOR_CODES = re.compile(r'\^[0-9]')
|
||||||
|
RE_MAP_FROM_STATUS = re.compile(r'^map: (?P<mapname>mp_[a-z_]+)$')
|
||||||
RE_PLAYER_FROM_STATUS = re.compile(
|
RE_PLAYER_FROM_STATUS = re.compile(
|
||||||
r'^\s*(?P<slot>[0-9]+)\s+'
|
r'^\s*(?P<slot>[0-9]+)\s+'
|
||||||
r'(?P<score>[0-9-]+)\s+'
|
r'(?P<score>[0-9-]+)\s+'
|
||||||
@ -26,22 +25,28 @@ class Writable:
|
|||||||
)
|
)
|
||||||
RE_CVAR = re.compile(
|
RE_CVAR = re.compile(
|
||||||
r'^["](?P<name>[a-z_]+)["]\sis[:]\s'
|
r'^["](?P<name>[a-z_]+)["]\sis[:]\s'
|
||||||
r'["](?P<value>.*?)\^7["]\s'
|
r'["](?P<value>.*?)["]\s'
|
||||||
r'default[:]\s'
|
r'default[:]\s'
|
||||||
r'["](?P<default>.*?)\^7["]\s'
|
r'["](?P<default>.*?)["]\s'
|
||||||
r'info[:]\s'
|
r'info[:]\s'
|
||||||
r'["](?P<info>.*?)\^7["]$'
|
r'["](?P<info>.*?)["]$'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self, tui):
|
||||||
|
self._settings = tui._settings
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_color_codes(s: str) -> str:
|
def remove_color_codes(s: str) -> str:
|
||||||
return Writable.RE_COLOR_CODES.sub('', s)
|
return Writable.RE_COLOR_CODES.sub('', s)
|
||||||
|
|
||||||
def parse(self, cmd, response: str, style=None) -> Renderable:
|
def parse(self, cmd, response: str, style=None) -> Renderable:
|
||||||
response = response.removeprefix('print\n')
|
response = self.remove_color_codes(response.removeprefix('print\n'))
|
||||||
if settings.raw:
|
if self._settings.raw:
|
||||||
return Text(response, style=style)
|
return Text(response, style=style)
|
||||||
|
|
||||||
|
if response in ['Bad rcon']:
|
||||||
|
return Text('Incorrect RCON password', style='#c73d4b')
|
||||||
|
|
||||||
match cmd:
|
match cmd:
|
||||||
case 'status':
|
case 'status':
|
||||||
return self.status_table(response)
|
return self.status_table(response)
|
||||||
@ -49,58 +54,83 @@ class Writable:
|
|||||||
if m := self.RE_CVAR.match(response):
|
if m := self.RE_CVAR.match(response):
|
||||||
return self.cvar_table(m)
|
return self.cvar_table(m)
|
||||||
else:
|
else:
|
||||||
return Text(self.remove_color_codes(response), style=style)
|
return Text(response, style=style)
|
||||||
|
|
||||||
def error(self, message: str) -> Text:
|
def error(self, message: str) -> Text:
|
||||||
return Text(message, style='#c73d4b')
|
return Text(message, style='#c73d4b')
|
||||||
|
|
||||||
def status_table(self, status_response: str) -> Table | str:
|
def status_table(self, status_response: str) -> Table | str:
|
||||||
table = Table(show_header=True, header_style='bold #88c0d0')
|
table = Table(show_header=True, header_style='bold #88c0d0')
|
||||||
table.add_column('Slot', justify='center')
|
columns = [
|
||||||
table.add_column('Score', justify='center')
|
('Slot', 'center'),
|
||||||
table.add_column('Ping', justify='center')
|
('Score', 'center'),
|
||||||
table.add_column('GUID', justify='center')
|
('Ping', 'center'),
|
||||||
table.add_column('Name', justify='center')
|
('GUID', 'center'),
|
||||||
|
('Name', 'center'),
|
||||||
|
]
|
||||||
|
for column, justify in columns:
|
||||||
|
table.add_column(column, justify=justify)
|
||||||
|
if not self._settings.min_status:
|
||||||
table.add_column('Last', justify='center')
|
table.add_column('Last', justify='center')
|
||||||
|
if self._settings.min_status:
|
||||||
table.add_column('IP', justify='center')
|
table.add_column('IP', justify='center')
|
||||||
table.add_column('Port', justify='center')
|
else:
|
||||||
table.add_column('QPort', justify='center')
|
table.add_column('IP:Port', justify='center')
|
||||||
table.add_column('Rate', justify='center')
|
columns = [
|
||||||
|
('QPort', 'center'),
|
||||||
|
('Rate', 'center'),
|
||||||
|
]
|
||||||
|
if not self._settings.min_status:
|
||||||
|
for column, justify in columns:
|
||||||
|
table.add_column(column, justify=justify)
|
||||||
|
|
||||||
|
mapname = 'unable to parse map name'
|
||||||
for line in status_response.splitlines():
|
for line in status_response.splitlines():
|
||||||
match self.RE_PLAYER_FROM_STATUS.match(line):
|
if m := self.RE_PLAYER_FROM_STATUS.match(line):
|
||||||
case None:
|
name = m.group('name')
|
||||||
continue
|
if name == '':
|
||||||
case m:
|
name = '[no name]'
|
||||||
table.add_row(
|
row = [
|
||||||
m.group('slot'),
|
m.group('slot'),
|
||||||
m.group('score'),
|
m.group('score'),
|
||||||
m.group('ping'),
|
m.group('ping'),
|
||||||
m.group('guid'),
|
m.group('guid'),
|
||||||
self.remove_color_codes(m.group('name')),
|
name,
|
||||||
m.group('last'),
|
]
|
||||||
m.group('ip'),
|
if self._settings.min_status:
|
||||||
m.group('port'),
|
row.append(m.group('ip'))
|
||||||
m.group('qport'),
|
else:
|
||||||
m.group('rate'),
|
row.append(f'{m.group("ip")}:{m.group("port")}')
|
||||||
)
|
row.append(m.group('last'))
|
||||||
|
row.append(m.group('qport'))
|
||||||
|
row.append(m.group('rate'))
|
||||||
|
table.add_row(*row)
|
||||||
|
elif m := self.RE_MAP_FROM_STATUS.match(line):
|
||||||
|
mapname = m.group('mapname')
|
||||||
|
|
||||||
|
out = Text(f'Map: {mapname}\n', style='bold #88c0d0')
|
||||||
if len(table.rows) == 0:
|
if len(table.rows) == 0:
|
||||||
return 'No players connected.'
|
return out.append('No players connected', style='#c73d4b')
|
||||||
|
else:
|
||||||
|
table.title = out
|
||||||
return table
|
return table
|
||||||
|
|
||||||
def cvar_table(self, m: re.Match) -> Table:
|
def cvar_table(self, m: re.Match) -> Table:
|
||||||
table = Table(show_header=True, header_style='bold #88c0d0')
|
table = Table(show_header=True, header_style='bold #88c0d0')
|
||||||
table.add_column('Name', justify='center')
|
columns = [
|
||||||
table.add_column('Value', justify='center')
|
('Name', 'center'),
|
||||||
table.add_column('Default', justify='center')
|
('Value', 'center'),
|
||||||
table.add_column('Info', justify='center')
|
('Default', 'center'),
|
||||||
|
('Info', 'center'),
|
||||||
|
]
|
||||||
|
for column, justify in columns:
|
||||||
|
table.add_column(column, justify=justify)
|
||||||
|
|
||||||
table.add_row(
|
table.add_row(
|
||||||
m.group('name'),
|
m.group('name'),
|
||||||
self.remove_color_codes(m.group('value')),
|
m.group('value'),
|
||||||
self.remove_color_codes(m.group('default')),
|
m.group('default'),
|
||||||
self.remove_color_codes(m.group('info')),
|
m.group('info'),
|
||||||
)
|
)
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user