8 Commits

Author SHA1 Message Date
3a7cc3eacb patch bump 2026-03-23 13:31:09 +00:00
fce5858a93 print success messages instead boxed output on cvar change 2026-03-23 13:31:03 +00:00
a9aff25c4e include map in status output
uses rounded boxes
2026-03-23 13:21:38 +00:00
7af5caad89 fix spinner suffix 2026-03-23 13:17:45 +00:00
ac5b117e2c bump aio-q3-rcon dep version
patch bump
2026-03-23 12:16:35 +00:00
4f5272ac32 patch bump 2026-03-22 10:35:41 +00:00
04c4e40063 rescale the boxed outputs 2026-03-22 10:35:23 +00:00
2233f5eda1 use workspace to add path dep 2026-03-22 05:29:40 +00:00
9 changed files with 61 additions and 35 deletions

View File

@@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = ["aio-q3-rcon>=1.0.0", "clypi>=1.8.2"]
dependencies = ["aio-q3-rcon>=1.0.1", "clypi>=1.8.2"]
[project.scripts]
q3rcon-cli = "q3rcon_cli.cli:main"
@@ -34,7 +34,7 @@ Source = "https://github.com/onyx-and-iris/q3rcon-cli"
path = "src/q3rcon_cli/__about__.py"
[tool.hatch.envs.default]
dependencies = ["aio-q3-rcon @ {root:parent:uri}/aio-q3-rcon"]
workspace.members = [{ path = "../aio-q3-rcon" }]
[tool.hatch.envs.types]
extra-dependencies = ["mypy>=1.0.0"]

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2026-present onyx-and-iris <code@onyxandiris.online>
#
# SPDX-License-Identifier: MIT
__version__ = '0.2.1'
__version__ = '0.2.4'

View File

@@ -1,5 +1,5 @@
from aioq3rcon import Client
from clypi import Command, Positional, Spinner, arg
from clypi import Command, Positional, Spinner, arg, cprint
from typing_extensions import override
from q3rcon_cli import console
@@ -23,21 +23,17 @@ class Gametype(Command):
@override
async def run(self):
if not Gametype.new_gametype:
if not self.new_gametype:
async with Client(self.host, self.port, self.password) as client:
if response := await client.send_command('g_gametype'):
console.out.print_cvar(response)
return
async with Client(self.host, self.port, self.password) as client:
DEFAULT_FRAGMENT_READ_TIMEOUT = client.fragment_read_timeout
await client.send_command(f'g_gametype {self.new_gametype}')
if self.force:
async with Spinner('Forcing gametype change...'):
async with Spinner('Forcing gametype change', suffix='...'):
client.fragment_read_timeout = 1
await client.send_command('map_restart')
client.fragment_read_timeout = DEFAULT_FRAGMENT_READ_TIMEOUT
if response := await client.send_command('g_gametype'):
console.out.print_cvar(response)
cprint(f'Gametype changed successfully to {self.new_gametype}.', fg='green')

View File

@@ -1,5 +1,5 @@
from aioq3rcon import Client
from clypi import Command, Positional, arg
from clypi import Command, Positional, arg, cprint
from typing_extensions import override
from q3rcon_cli import console
@@ -26,5 +26,5 @@ class Hostname(Command):
async with Client(self.host, self.port, self.password) as client:
await client.send_command(f'sv_hostname {self.new_hostname}')
if response := await client.send_command('sv_hostname'):
console.out.print_cvar(response)
cprint(f'Hostname changed to: {self.new_hostname}', fg='green')

View File

@@ -1,5 +1,5 @@
from aioq3rcon import Client
from clypi import Command, Positional, Spinner, arg
from clypi import Command, Positional, Spinner, arg, cprint
from typing_extensions import override
from q3rcon_cli import console
@@ -24,10 +24,10 @@ class Map(Command):
console.out.print_cvar(response)
return
async with Spinner('Changing map...'):
async with Spinner('Changing map', suffix='...'):
async with Client(
self.host, self.port, self.password, fragment_read_timeout=1
) as client:
await client.send_command(f'map mp_{self.new_map.removeprefix("mp_")}')
if response := await client.send_command('mapname'):
console.out.print_cvar(response)
cprint(f'Map changed to {self.new_map.removeprefix("mp_")}', fg='green')

View File

@@ -14,7 +14,7 @@ class Maprestart(Command):
@override
async def run(self):
async with Spinner('Restarting map...'):
async with Spinner('Restarting map', suffix='...'):
async with Client(
self.host, self.port, self.password, fragment_read_timeout=1
) as client:

View File

@@ -14,7 +14,7 @@ class Maprotate(Command):
@override
async def run(self):
async with Spinner('Rotating map...'):
async with Spinner('Rotating map', suffix='...'):
async with Client(
self.host, self.port, self.password, fragment_read_timeout=1
) as client:

View File

@@ -14,7 +14,7 @@ class Status(Command):
@override
async def run(self):
async with Spinner('Fetching status...'):
async with Spinner('Fetching status', suffix='...'):
async with Client(
self.host, self.port, self.password, fragment_read_timeout=0.5
) as client:

View File

@@ -1,7 +1,7 @@
import re
import clypi
from clypi import cprint
from clypi import Boxes, cprint
class Console:
@@ -33,6 +33,8 @@ class OutConsole(Console):
r'(?P<rate>[0-9]+)$',
re.IGNORECASE | re.VERBOSE,
)
STATUS_MAP_REGEX = re.compile(r'^map: (?P<mapname>mp_[a-z_]+)$')
CVAR_REGEX = re.compile(
r'^["](?P<name>[a-z_]+)["]\sis[:]\s'
r'["](?P<value>.*?)["]\s'
@@ -69,40 +71,68 @@ class OutConsole(Console):
_guids.append(m.group('guid'))
_names.append(self._remove_colour_codes(m.group('name')))
_ips.append(m.group('ip'))
elif m := OutConsole.STATUS_MAP_REGEX.match(line):
cprint(f'\nCurrent map: {m.group("mapname")}', fg=self.style)
if not _slots:
cprint('\nNo players connected.\n', fg=self.style)
cprint('No players connected.', fg='red')
return
slots = clypi.boxed(_slots, title='Slot', width=15)
scores = clypi.boxed(_scores, title='Score', width=15)
pings = clypi.boxed(_pings, title='Ping', width=15)
guids = clypi.boxed(_guids, title='GUID', width=40)
names = clypi.boxed(_names, title='Name', width=30)
ips = clypi.boxed(_ips, title='IP', width=30)
print(f'\n{clypi.stack(slots, scores, pings, guids, names, ips, padding=0)}')
slots = clypi.boxed(
_slots, title='Slot', width=10, align='center', style=Boxes.ROUNDED
)
scores = clypi.boxed(
_scores, title='Score', width=10, align='center', style=Boxes.ROUNDED
)
pings = clypi.boxed(
_pings, title='Ping', width=10, align='center', style=Boxes.ROUNDED
)
guids = clypi.boxed(
_guids,
title='GUID',
width=len(max(_guids, key=len)) + 4,
style=Boxes.ROUNDED,
)
names = clypi.boxed(
_names,
title='Name',
width=len(max(_names, key=len)) + 4,
style=Boxes.ROUNDED,
)
ips = clypi.boxed(
_ips, title='IP', width=len(max(_ips, key=len)) + 4, style=Boxes.ROUNDED
)
print(f'{clypi.stack(slots, scores, pings, guids, names, ips, padding=0)}')
def print_cvar(self, response: str):
response = self._remove_colour_codes(response).removeprefix('print\n')
if m := self.CVAR_REGEX.match(response):
name = clypi.boxed(
[m.group('name')], title='Name', width=max(len(m.group('name')) + 4, 30)
[m.group('name')],
title='Name',
width=max(len(m.group('name')) + 4, 15),
style=Boxes.ROUNDED,
)
value = clypi.boxed(
[m.group('value')],
title='Value',
width=max(len(m.group('value')) + 4, 30),
width=max(len(m.group('value')) + 4, 15),
style=Boxes.ROUNDED,
)
default = clypi.boxed(
[m.group('default')],
title='Default',
width=max(len(m.group('default')) + 4, 30),
width=max(len(m.group('default')) + 4, 15),
style=Boxes.ROUNDED,
)
info = clypi.boxed(
[m.group('info')], title='Info', width=max(len(m.group('info')) + 4, 30)
[m.group('info')],
title='Info',
width=max(len(m.group('info')) + 4, 15),
style=Boxes.ROUNDED,
)
print(f'\n{clypi.stack(name, value, default, info, padding=0)}')
print(f'{clypi.stack(name, value, default, info, padding=0)}')
out = OutConsole()