diff --git a/src/shell_history_search/models.py b/src/shell_history_search/models.py new file mode 100644 index 0000000..0a9dcac --- /dev/null +++ b/src/shell_history_search/models.py @@ -0,0 +1,42 @@ +from dataclasses import dataclass +from typing import Optional + + +@dataclass +class HistoryEntry: + id: int + timestamp: float + command: str + exit_code: int + shell: str + working_dir: str + + @classmethod + def from_parsers_entry(cls, entry) -> "HistoryEntry": + return cls( + id=0, + timestamp=entry.timestamp or 0.0, + command=entry.command, + exit_code=0, + shell=entry.shell_type, + working_dir=entry.hostname or "" + ) + + +@dataclass +class SearchResult: + command: str + shell_type: str + timestamp: Optional[int] + similarity: float + command_id: int + + @classmethod + def from_core_result(cls, result) -> "SearchResult": + return cls( + command=result.command, + timestamp=result.timestamp, + similarity=result.similarity, + shell_type=result.shell_type, + command_id=result.command_id + )