Repository: mitmproxy/mitmproxy

Issue:
mitmproxy - custom addon options not visible 
##### Steps to reproduce the problem:

1.  Start the following addon with `mitmproxy --scripts eg.py`

```python

from mitmproxy import http, ctx

class MyAddon:
    def load(self, loader) -> None:
        loader.add_option(name='AAAAA_addon_message',
                          typespec=str,
                          default='your request is bad and you should feel bad',
                          help='Respond with this message')

        loader.add_option(name='AAAAA_addon_status_code',
                          typespec=int,
                          default=400,
                          help='Respond with this status code')

    def request(self, flow: http.HTTPFlow) -> None:
        ctx.log.info('my_addon request')

    def response(self, flow: http.HTTPFlow) -> None:
        ctx.log.info('my_addon response')
        flow.response.status_code = ctx.options.AAAAA_status_code 
        flow.response.content = ctx.options.AAAAA_addon_message.encode('utf-8')

addons = [
    MyAddon()
]

```



2. Open the options with 'O' key binding and see the options AAAA_* are not editable

<img width="418" alt="screen shot 2018-05-22 at 3 05 02 pm" src="https://user-images.githubusercontent.com/222833/40343185-f92caa5c-5dd1-11e8-9449-8facc05c16f6.png">


##### Any other comments? What have you tried so far?

mitmweb displays the options correctly:

<img width="896" alt="screen shot 2018-05-22 at 3 05 32 pm" src="https://user-images.githubusercontent.com/222833/40343148-d00229fe-5dd1-11e8-94d0-0cd352fe870c.png">

Could be related to the [deferred options](https://github.com/mitmproxy/mitmproxy/commit/f7d7e31f06dadcf0f7801ab1db055f8609c88a71)?

This affects the current version `4.0.1` as well as `master`.

##### System information

<!-- Paste the output of "mitmproxy --version" here. -->
```
(venv) ➜  mitmproxy git:(master) ✗ mitmproxy --version
Mitmproxy: 5.0.0.dev12 (commit 7aaf495) 
Python:    3.6.5
OpenSSL:   OpenSSL 1.1.0h  27 Mar 2018
Platform:  Darwin-17.5.0-x86_64-i386-64bit
```

<!-- Please use the mitmproxy forums (https://discourse.mitmproxy.org/) for support/how-to questions. Thanks! :) -->



Discussion:
Thanks for providing super easy steps to reproduce this! :smiley:

Resolving patch:
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -107,6 +107,7 @@ def add_option(
         choices: typing.Optional[typing.Sequence[str]] = None
     ) -> None:
         self._options[name] = _Option(name, typespec, default, help, choices)
+        self.changed.send(self, updated={name})
 
     @contextlib.contextmanager
     def rollback(self, updated, reraise=False):
diff --git a/mitmproxy/tools/console/options.py b/mitmproxy/tools/console/options.py
--- a/mitmproxy/tools/console/options.py
+++ b/mitmproxy/tools/console/options.py
@@ -106,6 +106,8 @@ def __init__(self, master):
         self.master.options.changed.connect(self.sig_mod)
 
     def sig_mod(self, *args, **kwargs):
+        self.opts = sorted(self.master.options.keys())
+        self.maxlen = max(len(i) for i in self.opts)
         self._modified()
         self.set_focus(self.index)
 


Test patch: