import lldb

INTEL_ARGS_REGISTERS = [
    "rdx", "rcx", "r8", "r9",
]


def class_from_reciever(reciever):
    return reciever.split()[0].strip("<:")


def selector_from_register(register):
    return register.split()[-1].strip('"')


def output_for_command(debugger, command):
    interpreter = debugger.GetCommandInterpreter()
    result = lldb.SBCommandReturnObject()
    interpreter.HandleCommand(command, result)

    if result.GetStatus() == 2:
        return result.GetOutput()
    else:
        return ""


def objc_context(debugger, command, result, internal_dict):
    reciever = output_for_command(debugger, "po $rdi").strip()
    selector = selector_from_register(output_for_command(debugger, "x/s $rsi"))
    number_of_arguments = selector.count(":")
    labels = selector.split(":")
    body = "Reciever: {} Selector: {}\nArgs:\n".format(reciever, selector)
    for i in range(number_of_arguments):
        register = INTEL_ARGS_REGISTERS[i]
        arg = output_for_command(debugger, "po $%s" % register).strip()
        body += "\n{}: {}\n".format(labels[i], arg)

    body += "\n" + output_for_command(debugger, "disassemble -c 5")

    print(body)


def __lldb_init_module(debugger, internal_dict):
    handle = debugger.HandleCommand
    handle('command script add -f context.objc_context objc_context')

@@ -508,16 +508,143 @@
 rn %22%22%0A%0A%0A
+def blue(string):%0A    return %22%5Cx1b%5B34m%22 + string + %22%5Cx1b%5B39m%22%0A%0A%0Adef red(string):%0A    return %22%5Cx1b%5B31m%22 + string + %22%5Cx1b%5B39m%22%0A%0A%0A
 def objc
@@ -972,24 +972,29 @@
 .format(
+blue(
 reciever
 , select
@@ -985,18 +985,78 @@
 reciever
-, 
+),%0A                                                       red(
 selector
@@ -1056,16 +1056,17 @@
 elector)
+)
 %0A    for
@@ -1250,16 +1250,20 @@
 .format(
+red(
 labels%5Bi
@@ -1263,16 +1263,17 @@
 abels%5Bi%5D
+)
 , arg)%0A%0A
@@ -1280,22 +1280,21 @@
     
-bod
+disassembl
 y 
-+
 =
- %22%5Cn%22 +
  out
@@ -1348,17 +1348,308 @@
     
-print(bod
+try:%0A        import pygments.lexers%0A        import pygments.formatters%0A        disassembly = pygments.highlight(%0A                disassembly, pygments.lexers.NasmLexer(),%0A                pygments.formatters.TerminalFormatter())%0A    except ImportError:%0A        pass%0A%0A    print(body + %22%5Cn%22 + disassembl
 y)%0A%0A

Add coloring for context