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
9 changes: 1 addition & 8 deletions gambaterm/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,15 @@ def add_console_arguments(cls, parser: argparse.ArgumentParser) -> None:
action="store_true",
help="Force the emulator to treat the rom as a GB file",
)
parser.add_argument(
"--save-directory",
"--sd",
type=Path,
default=None,
help="Path to the save directory",
)

@classmethod
def pop_console_arguments(
cls, namespace: argparse.Namespace
) -> Callable[[], Console]:
romfile: Path = namespace.romfile
input_file: Path | None = namespace.input_file
save_directory: Path | None = namespace.save_directory
force_gameboy: bool = namespace.__dict__.pop("force_gameboy")
save_directory: Path | None = namespace.__dict__.pop("save_directory")
# Save directory defaults to the rom file directory (unless we read the input from a file)
if input_file is None and save_directory is None:
save_directory = romfile.parent
Expand Down
4 changes: 1 addition & 3 deletions gambaterm/keyboard_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def __init__(
self._pop_keystrokes = pop_keystrokes

def pop_keystrokes(self) -> list[Keystroke]:
if self._pop_keystrokes is not None:
return self._pop_keystrokes()
return super().pop_keystrokes()
return self._pop_keystrokes()


def is_kitty_keyboard_protocol_supported(
Expand Down
48 changes: 34 additions & 14 deletions gambaterm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,34 @@ class AppConfig:
speed: float
skip_inputs: int
cpr_sync: bool
save_directory: Path | None


@dataclass
class LocalAppConfig(AppConfig):
enable_controller: bool
write_input: Path | None


def add_base_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument("romfile", metavar="ROM", type=Path, help="Path to a rom file")


def add_input_file_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--input-file", "-i", type=Path, default=None, help="Path to a bizhawk BK2 file"
)
parser.add_argument(
"--skip-inputs",
"--si",
type=int,
default=188,
help="Number of frame inputs to skip in order to compensate "
"for the lack of BIOS (default is 188)",
)


def add_optional_arguments(parser: argparse.ArgumentParser) -> None:
def add_tuning_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--color-mode",
"-c",
Expand Down Expand Up @@ -73,20 +89,18 @@ def add_optional_arguments(parser: argparse.ArgumentParser) -> None:
default=1.0,
help="Control the execution speed (default is 1.0)",
)
parser.add_argument(
"--skip-inputs",
"--si",
type=int,
default=188,
help="Number of frame inputs to skip in order to compensate "
"for the lack of BIOS (default is 188)",
)
parser.add_argument(
"--cpr-sync",
"--cs",
action="store_true",
help="Use CPR synchronization to prevent video buffering",
)


def add_local_only_arguments(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--disable-audio", "--da", action="store_true", help="Disable audio entirely"
)
parser.add_argument(
"--enable-controller",
"--ec",
Expand All @@ -99,6 +113,13 @@ def add_optional_arguments(parser: argparse.ArgumentParser) -> None:
type=Path,
help="Record inputs into a file",
)
parser.add_argument(
"--save-directory",
"--sd",
type=Path,
default=None,
help="Path to the save directory (default to the ROM directory)",
)


def main(
Expand All @@ -110,17 +131,16 @@ def main(
prog="gambaterm", description="Gambatte terminal front-end"
)
add_base_arguments(parser)
add_optional_arguments(parser)
add_input_file_arguments(parser)
add_tuning_arguments(parser)
add_local_only_arguments(parser)
console_cls.add_console_arguments(parser)
parser.add_argument(
"--disable-audio", "--da", action="store_true", help="Disable audio entirely"
)

# Parse arguments
namespace = parser.parse_args(parser_args)
disable_audio: bool = namespace.__dict__.pop("disable_audio")
console_callback = console_cls.pop_console_arguments(namespace)
args = AppConfig(**vars(namespace))
args = LocalAppConfig(**vars(namespace))

# Check that the ROM file exists
if not args.romfile.exists():
Expand Down
12 changes: 12 additions & 0 deletions gambaterm/remote_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import codecs
import hashlib
import contextlib
from typing import IO, Generator

Expand Down Expand Up @@ -84,3 +85,14 @@ def _height_and_width(self) -> WINSZ:
def update_size(self, rows: int, columns: int) -> None:
self._rows = rows
self._columns = columns


def user_directory_name(username: str | None) -> str:
"""Hash the username into a safe directory name.

:param username: telnet/ssh-negotiated username, or ``None``
:returns: hex digest suitable for use as a directory name
"""
if username is None:
return "_anonymous"
return hashlib.sha256(username.encode("utf-8")).hexdigest()[:16]
Loading
Loading