Skip to content

Commit

Permalink
objective_c_symbol: objective_c_class: Add dump_to option to show
Browse files Browse the repository at this point in the history
  • Loading branch information
Netanel Cohen committed Jun 29, 2023
1 parent 95a45ab commit 55b127d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/rpcclient/rpcclient/darwin/objective_c_class.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import namedtuple
from functools import partial
from pathlib import Path
from typing import Mapping
from typing import Mapping, Optional

from pygments import highlight
from pygments.formatters import TerminalTrueColorFormatter
Expand Down Expand Up @@ -85,11 +85,17 @@ def reload(self):
objc.Method.from_data(method, self._client) for method in class_description['methods']
]

def show(self):
def show(self, dump_to: Optional[str] = None):
"""
Print to terminal the highlighted class description.
:param dump_to: directory to dump.
"""
print(highlight(str(self), ObjectiveCLexer(), TerminalTrueColorFormatter(style='native')))
formatted = str(self)
print(highlight(formatted, ObjectiveCLexer(), TerminalTrueColorFormatter(style='native')))

if dump_to is None:
return
(Path(dump_to) / f'{self.name}.m').expanduser().write_text(formatted)

def objc_call(self, sel: str, *args, **kwargs):
"""
Expand Down
12 changes: 10 additions & 2 deletions src/rpcclient/rpcclient/darwin/objective_c_symbol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from contextlib import suppress
from dataclasses import dataclass
from functools import partial
from pathlib import Path
from typing import Optional

from pygments import highlight
from pygments.formatters import TerminalTrueColorFormatter
Expand Down Expand Up @@ -76,12 +78,18 @@ def reload(self):
self.properties = properties_list
self.class_ = class_wrapper

def show(self, recursive: bool = False):
def show(self, dump_to: Optional[str] = None, recursive: bool = False):
"""
Print to terminal the highlighted class description.
:param dump_to: directory to dump.
:param recursive: Show methods of super classes.
"""
print(highlight(self._to_str(recursive), ObjectiveCLexer(), TerminalTrueColorFormatter(style='native')))
formatted = self._to_str(recursive)
print(highlight(formatted, ObjectiveCLexer(), TerminalTrueColorFormatter(style='native')))

if dump_to is None:
return
(Path(dump_to) / f'{self.class_.name}.m').expanduser().write_text(formatted)

def objc_call(self, selector: str, *params, **kwargs):
"""
Expand Down

0 comments on commit 55b127d

Please sign in to comment.